Skip to content

Commit

Permalink
Pint
Browse files Browse the repository at this point in the history
  • Loading branch information
Marick van Tuil committed Nov 30, 2024
1 parent 49fceca commit 981c997
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 54 deletions.
2 changes: 1 addition & 1 deletion src/CloudTasksApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ protected static function getFacadeAccessor(): string

public static function fake(): void
{
self::swap(new CloudTasksApiFake());
self::swap(new CloudTasksApiFake);
}
}
2 changes: 1 addition & 1 deletion src/CloudTasksApiFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function deleteTask(string $taskName): void

public function getTask(string $taskName): Task
{
return (new Task())
return (new Task)
->setName($taskName);
}

Expand Down
2 changes: 1 addition & 1 deletion src/CloudTasksJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(

public function getJobId(): string
{
return $this->uuid() ?? throw new Exception();
return $this->uuid() ?? throw new Exception;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/CloudTasksQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ protected function pushToCloudTasks($queue, $payload, $delay, mixed $job)

$payload = (array) json_decode($payload, true);

$task = tap(new Task())->setName($this->taskName($queue, $payload['displayName']));
$task = tap(new Task)->setName($this->taskName($queue, $payload['displayName']));

$payload = $this->enrichPayloadWithAttempts($payload);

Expand Down Expand Up @@ -217,21 +217,21 @@ public function addPayloadToTask(array $payload, Task $task, mixed $job): Task
if (! empty($this->config['app_engine'])) {
$path = \Safe\parse_url(route('cloud-tasks.handle-task'), PHP_URL_PATH);

$appEngineRequest = new AppEngineHttpRequest();
$appEngineRequest = new AppEngineHttpRequest;
$appEngineRequest->setRelativeUri($path);
$appEngineRequest->setHttpMethod(HttpMethod::POST);
$appEngineRequest->setBody(json_encode($payload));
$appEngineRequest->setHeaders($headers);

if (! empty($service = $this->config['app_engine_service'])) {
$routing = new AppEngineRouting();
$routing = new AppEngineRouting;
$routing->setService($service);
$appEngineRequest->setAppEngineRouting($routing);
}

$task->setAppEngineHttpRequest($appEngineRequest);
} else {
$httpRequest = new HttpRequest();
$httpRequest = new HttpRequest;
$httpRequest->setUrl($this->getHandler($job));
$httpRequest->setBody(json_encode($payload));
$httpRequest->setHttpMethod(HttpMethod::POST);
Expand Down
2 changes: 1 addition & 1 deletion src/TaskHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private function run(IncomingTask $task): void

public function getWorkerOptions(): WorkerOptions
{
$options = new WorkerOptions();
$options = new WorkerOptions;

if (isset($this->config['backoff'])) {
$options->backoff = $this->config['backoff'];
Expand Down
10 changes: 5 additions & 5 deletions tests/CloudTasksApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function setUp(): void
$this->setConfigValue('location', env('CI_CLOUD_TASKS_LOCATION'));
$this->setConfigValue('service_account_email', env('CI_CLOUD_TASKS_SERVICE_ACCOUNT_EMAIL'));

$this->client = new CloudTasksClient();
$this->client = new CloudTasksClient;

}

Expand All @@ -64,11 +64,11 @@ public function custom_client_options_can_be_added()
public function test_create_task()
{
// Arrange
$httpRequest = new HttpRequest();
$httpRequest = new HttpRequest;
$httpRequest->setHttpMethod(HttpMethod::GET);
$httpRequest->setUrl('https://example.com');

$cloudTask = new Task();
$cloudTask = new Task;
$cloudTask->setHttpRequest($httpRequest);

// Act
Expand Down Expand Up @@ -112,11 +112,11 @@ public function test_delete_task_on_non_existing_task()
public function test_delete_task()
{
// Arrange
$httpRequest = new HttpRequest();
$httpRequest = new HttpRequest;
$httpRequest->setHttpMethod(HttpMethod::GET);
$httpRequest->setUrl('https://example.com');

$cloudTask = new Task();
$cloudTask = new Task;
$cloudTask->setHttpRequest($httpRequest);
$cloudTask->setScheduleTime(new Timestamp(['seconds' => time() + 10]));

Expand Down
6 changes: 3 additions & 3 deletions tests/ConfigHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function test_it_allows_a_handler_url_to_contain_path(string $handler, st

$this->setConfigValue('handler', $handler);

$this->dispatch(new SimpleJob());
$this->dispatch(new SimpleJob);

CloudTasksApi::assertTaskCreated(function (Task $task) use ($expectedHandler) {
return $task->getHttpRequest()->getUrl() === $expectedHandler;
Expand All @@ -34,7 +34,7 @@ public function the_handle_route_task_uri_can_be_configured(): void

$this->app['config']->set('cloud-tasks.uri', 'my-custom-route');

$this->dispatch(new SimpleJob());
$this->dispatch(new SimpleJob);

CloudTasksApi::assertTaskCreated(function (Task $task) {
return $task->getHttpRequest()->getUrl() === 'https://docker.for.mac.localhost:8080/my-custom-route';
Expand All @@ -49,7 +49,7 @@ public function the_handle_route_task_uri_in_combination_with_path_can_be_config
$this->setConfigValue('handler', 'https://example.com/api');
$this->app['config']->set('cloud-tasks.uri', 'my-custom-route');

$this->dispatch(new SimpleJob());
$this->dispatch(new SimpleJob);

CloudTasksApi::assertTaskCreated(function (Task $task) {
return $task->getHttpRequest()->getUrl() === 'https://example.com/api/my-custom-route';
Expand Down
2 changes: 1 addition & 1 deletion tests/IncomingTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class IncomingTaskTest extends TestCase
{
public function setUp(): void
protected function setUp(): void
{
parent::setUp();

Expand Down
6 changes: 3 additions & 3 deletions tests/QueueAppEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function an_app_engine_http_request_with_the_handler_url_is_made()
CloudTasksApi::fake();

// Act
$this->dispatch(new SimpleJob());
$this->dispatch(new SimpleJob);

// Assert
CloudTasksApi::assertTaskCreated(function (Task $task): bool {
Expand All @@ -40,7 +40,7 @@ public function it_routes_to_the_service()
CloudTasksApi::fake();

// Act
$this->dispatch(new SimpleJob());
$this->dispatch(new SimpleJob);

// Assert
CloudTasksApi::assertTaskCreated(function (Task $task): bool {
Expand All @@ -55,7 +55,7 @@ public function it_contains_the_payload()
CloudTasksApi::fake();

// Act
$this->dispatch($job = new SimpleJob());
$this->dispatch($job = new SimpleJob);

// Assert
CloudTasksApi::assertTaskCreated(function (Task $task) use ($job): bool {
Expand Down
42 changes: 21 additions & 21 deletions tests/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function a_http_request_with_the_handler_url_is_made()
CloudTasksApi::fake();

// Act
$this->dispatch(new SimpleJob());
$this->dispatch(new SimpleJob);

// Assert
CloudTasksApi::assertTaskCreated(function (Task $task): bool {
Expand All @@ -65,7 +65,7 @@ public function it_posts_to_the_handler()
CloudTasksApi::fake();

// Act
$this->dispatch(new SimpleJob());
$this->dispatch(new SimpleJob);

// Assert
CloudTasksApi::assertTaskCreated(function (Task $task): bool {
Expand All @@ -81,7 +81,7 @@ public function it_posts_to_the_configured_handler_url()
CloudTasksApi::fake();

// Act
$this->dispatch(new SimpleJob());
$this->dispatch(new SimpleJob);

// Assert
CloudTasksApi::assertTaskCreated(function (Task $task): bool {
Expand All @@ -98,7 +98,7 @@ public function it_posts_to_the_callback_handler_url()
CloudTasksQueue::configureHandlerUrlUsing(static fn (SimpleJob $job) => 'https://example.com/api/my-custom-route?job='.$job->id);

// Act
$job = new SimpleJob();
$job = new SimpleJob;
$job->id = 1;
$this->dispatch($job);

Expand All @@ -115,7 +115,7 @@ public function it_posts_the_serialized_job_payload_to_the_handler()
CloudTasksApi::fake();

// Act
$this->dispatch($job = new SimpleJob());
$this->dispatch($job = new SimpleJob);

// Assert
CloudTasksApi::assertTaskCreated(function (Task $task) use ($job): bool {
Expand All @@ -135,7 +135,7 @@ public function it_will_set_the_scheduled_time_when_dispatching_later()

// Act
$inFiveMinutes = now()->addMinutes(5);
$this->dispatch((new SimpleJob())->delay($inFiveMinutes));
$this->dispatch((new SimpleJob)->delay($inFiveMinutes));

// Assert
CloudTasksApi::assertTaskCreated(function (Task $task) use ($inFiveMinutes): bool {
Expand All @@ -153,8 +153,8 @@ public function it_posts_the_task_the_correct_queue()
$closureDisplayName = CallQueuedClosure::create($closure)->displayName();

// Act
$this->dispatch((new SimpleJob()));
$this->dispatch((new FailingJob())->onQueue('my-special-queue'));
$this->dispatch((new SimpleJob));
$this->dispatch((new FailingJob)->onQueue('my-special-queue'));
$this->dispatch($closure);
$this->dispatch($closure, 'my-special-queue');

Expand Down Expand Up @@ -248,7 +248,7 @@ public function jobs_can_be_released()
]);

// Act
$this->dispatch(new JobThatWillBeReleased())
$this->dispatch(new JobThatWillBeReleased)
->runAndGetReleasedJob()
->run();

Expand Down Expand Up @@ -305,7 +305,7 @@ public function test_default_backoff()
Event::fake(JobReleasedAfterException::class);

// Act
$this->dispatch(new FailingJob())->run();
$this->dispatch(new FailingJob)->run();

// Assert
CloudTasksApi::assertTaskCreated(function (Task $task) {
Expand All @@ -323,7 +323,7 @@ public function test_backoff_from_queue_config()
Event::fake(JobReleasedAfterException::class);

// Act
$this->dispatch(new FailingJob())->run();
$this->dispatch(new FailingJob)->run();

// Assert
CloudTasksApi::assertTaskCreated(function (Task $task) {
Expand All @@ -341,7 +341,7 @@ public function test_backoff_from_job()
Event::fake(JobReleasedAfterException::class);

// Act
$failingJob = new FailingJob();
$failingJob = new FailingJob;
$failingJob->backoff = 123;
$this->dispatch($failingJob)->run();

Expand All @@ -360,7 +360,7 @@ public function test_exponential_backoff_from_job_method()
CloudTasksApi::fake();

// Act
$releasedJob = $this->dispatch(new FailingJobWithExponentialBackoff())
$releasedJob = $this->dispatch(new FailingJobWithExponentialBackoff)
->runAndGetReleasedJob();
$releasedJob = $releasedJob->runAndGetReleasedJob();
$releasedJob->run();
Expand Down Expand Up @@ -388,7 +388,7 @@ public function test_failing_method_on_job()
Event::fake(JobOutput::class);

// Act
$this->dispatch(new FailingJob())
$this->dispatch(new FailingJob)
->runAndGetReleasedJob()
->runAndGetReleasedJob()
->runAndGetReleasedJob();
Expand All @@ -411,7 +411,7 @@ public function test_queue_before_and_after_hooks()
Queue::after(function (JobProcessed $event) {
event(new JobOutput('Queue::after:'.$event->job->payload()['data']['commandName']));
});
$this->dispatch(new SimpleJob())->run();
$this->dispatch(new SimpleJob)->run();

// Assert
Event::assertDispatched(fn (JobOutput $event) => $event->output === 'Queue::before:Tests\Support\SimpleJob');
Expand All @@ -429,7 +429,7 @@ public function test_queue_looping_hook_not_supported_with_this_package()
Queue::looping(function () {
event(new JobOutput('Queue::looping'));
});
$this->dispatch(new SimpleJob())->run();
$this->dispatch(new SimpleJob)->run();

// Assert
Event::assertDispatchedTimes(JobOutput::class, times: 1);
Expand Down Expand Up @@ -475,7 +475,7 @@ public function it_adds_a_pre_defined_task_name()
Str::createUlidsUsingSequence(['01HSR4V9QE2F4T0K8RBAYQ88KE']);

// Act
$this->dispatch((new SimpleJob()));
$this->dispatch((new SimpleJob));

// Assert
CloudTasksApi::assertTaskCreated(function (Task $task): bool {
Expand All @@ -494,7 +494,7 @@ public function headers_can_be_added_to_the_task()
'X-MyHeader' => 'MyValue',
]);

$this->dispatch((new SimpleJob()));
$this->dispatch((new SimpleJob));

// Assert
CloudTasksApi::assertTaskCreated(function (Task $task): bool {
Expand All @@ -513,7 +513,7 @@ public function headers_can_be_added_to_the_task_with_job_context()
'X-MyHeader' => $payload['displayName'],
]);

$this->dispatch((new SimpleJob()));
$this->dispatch((new SimpleJob));

// Assert
CloudTasksApi::assertTaskCreated(function (Task $task): bool {
Expand All @@ -529,10 +529,10 @@ public function batched_jobs_with_custom_queue_are_dispatched_on_the_custom_queu

// Act
$this->dispatch(Bus::batch([
tap(new SimpleJob(), function (SimpleJob $job) {
tap(new SimpleJob, function (SimpleJob $job) {
$job->queue = 'my-queue1';
}),
tap(new SimpleJobWithTimeout(), function (SimpleJob $job) {
tap(new SimpleJobWithTimeout, function (SimpleJob $job) {
$job->queue = 'my-queue2';
}),
])->onQueue('my-batch-queue'));
Expand Down
Loading

0 comments on commit 981c997

Please sign in to comment.