diff --git a/src/CloudTasksApi.php b/src/CloudTasksApi.php index 51639fa..0b961fa 100644 --- a/src/CloudTasksApi.php +++ b/src/CloudTasksApi.php @@ -22,6 +22,6 @@ protected static function getFacadeAccessor(): string public static function fake(): void { - self::swap(new CloudTasksApiFake()); + self::swap(new CloudTasksApiFake); } } diff --git a/src/CloudTasksApiFake.php b/src/CloudTasksApiFake.php index 074eb68..56dda5e 100644 --- a/src/CloudTasksApiFake.php +++ b/src/CloudTasksApiFake.php @@ -28,7 +28,7 @@ public function deleteTask(string $taskName): void public function getTask(string $taskName): Task { - return (new Task()) + return (new Task) ->setName($taskName); } diff --git a/src/CloudTasksJob.php b/src/CloudTasksJob.php index 399a7c4..0f13751 100644 --- a/src/CloudTasksJob.php +++ b/src/CloudTasksJob.php @@ -41,7 +41,7 @@ public function __construct( public function getJobId(): string { - return $this->uuid() ?? throw new Exception(); + return $this->uuid() ?? throw new Exception; } /** diff --git a/src/CloudTasksQueue.php b/src/CloudTasksQueue.php index d27c2de..c14458e 100644 --- a/src/CloudTasksQueue.php +++ b/src/CloudTasksQueue.php @@ -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); @@ -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); diff --git a/src/TaskHandler.php b/src/TaskHandler.php index 2e31145..812c2b2 100644 --- a/src/TaskHandler.php +++ b/src/TaskHandler.php @@ -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']; diff --git a/tests/CloudTasksApiTest.php b/tests/CloudTasksApiTest.php index 00c8b8e..ebc08a1 100644 --- a/tests/CloudTasksApiTest.php +++ b/tests/CloudTasksApiTest.php @@ -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; } @@ -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 @@ -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])); diff --git a/tests/ConfigHandlerTest.php b/tests/ConfigHandlerTest.php index 437473c..33837c2 100644 --- a/tests/ConfigHandlerTest.php +++ b/tests/ConfigHandlerTest.php @@ -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; @@ -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'; @@ -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'; diff --git a/tests/IncomingTaskTest.php b/tests/IncomingTaskTest.php index 16b49b8..060a64b 100644 --- a/tests/IncomingTaskTest.php +++ b/tests/IncomingTaskTest.php @@ -16,7 +16,7 @@ class IncomingTaskTest extends TestCase { - public function setUp(): void + protected function setUp(): void { parent::setUp(); diff --git a/tests/QueueAppEngineTest.php b/tests/QueueAppEngineTest.php index 1f2e8e4..a4362b1 100644 --- a/tests/QueueAppEngineTest.php +++ b/tests/QueueAppEngineTest.php @@ -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 { @@ -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 { @@ -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 { diff --git a/tests/QueueTest.php b/tests/QueueTest.php index 2386e76..5b098c9 100644 --- a/tests/QueueTest.php +++ b/tests/QueueTest.php @@ -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 { @@ -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 { @@ -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 { @@ -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); @@ -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 { @@ -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 { @@ -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'); @@ -248,7 +248,7 @@ public function jobs_can_be_released() ]); // Act - $this->dispatch(new JobThatWillBeReleased()) + $this->dispatch(new JobThatWillBeReleased) ->runAndGetReleasedJob() ->run(); @@ -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) { @@ -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) { @@ -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(); @@ -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(); @@ -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(); @@ -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'); @@ -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); @@ -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 { @@ -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 { @@ -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 { @@ -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')); diff --git a/tests/TaskHandlerTest.php b/tests/TaskHandlerTest.php index c550d4e..d129148 100644 --- a/tests/TaskHandlerTest.php +++ b/tests/TaskHandlerTest.php @@ -48,7 +48,7 @@ public function it_can_run_a_task() Event::fake(JobOutput::class); // Act - $this->dispatch(new SimpleJob())->run(); + $this->dispatch(new SimpleJob)->run(); // Assert Event::assertDispatched(fn (JobOutput $event) => $event->output === 'SimpleJob:success'); @@ -63,7 +63,7 @@ public function it_can_run_a_task_using_the_task_connection() $this->app['config']->set('queue.default', 'non-existing-connection'); // Act - $job = new SimpleJob(); + $job = new SimpleJob; $job->connection = 'my-cloudtasks-connection'; $this->dispatch($job)->run(); @@ -75,7 +75,7 @@ public function it_can_run_a_task_using_the_task_connection() public function after_max_attempts_it_will_log_to_failed_table() { // Arrange - $job = $this->dispatch(new FailingJobWithMaxTries()); + $job = $this->dispatch(new FailingJobWithMaxTries); // Act & Assert $this->assertDatabaseCount('failed_jobs', 0); @@ -103,7 +103,7 @@ public function uses_worker_options_callback_and_after_max_attempts_it_will_log_ return new WorkerOptions(maxTries: $queueTries[$task->queue()] ?? 1); }); - $job = $this->dispatch(tap(new FailingJobWithNoMaxTries(), fn ($job) => $job->queue = 'high')); + $job = $this->dispatch(tap(new FailingJobWithNoMaxTries, fn ($job) => $job->queue = 'high')); // Act & Assert $this->assertDatabaseCount('failed_jobs', 0); @@ -127,7 +127,7 @@ public function after_max_attempts_it_will_no_longer_execute_the_task() { // Arrange Event::fake([JobOutput::class]); - $job = $this->dispatch(new FailingJob()); + $job = $this->dispatch(new FailingJob); // Act & Assert $releasedJob = $job->runAndGetReleasedJob(); @@ -152,7 +152,7 @@ public function after_max_retry_until_it_will_log_to_failed_table(array $args) // Arrange $this->travelTo($args['now']); - $job = $this->dispatch(new FailingJobWithRetryUntil()); + $job = $this->dispatch(new FailingJobWithRetryUntil); // Act $releasedJob = $job->runAndGetReleasedJob(); @@ -175,7 +175,7 @@ public function test_unlimited_max_attempts() Event::fake(JobOutput::class); // Act - $job = $this->dispatch(new FailingJobWithUnlimitedTries()); + $job = $this->dispatch(new FailingJobWithUnlimitedTries); foreach (range(0, 50) as $attempt) { usleep(1000); @@ -191,7 +191,7 @@ public function test_max_attempts_in_combination_with_retry_until() // Arrange $this->travelTo('2020-01-01 00:00:00'); - $job = $this->dispatch(new FailingJobWithMaxTriesAndRetryUntil()); + $job = $this->dispatch(new FailingJobWithMaxTriesAndRetryUntil); // When retryUntil is specified, the maxAttempts is ignored. @@ -220,7 +220,7 @@ public function it_can_handle_encrypted_jobs() Event::fake(JobOutput::class); // Act - $job = $this->dispatch(new EncryptedJob()); + $job = $this->dispatch(new EncryptedJob); $job->run(); // Assert @@ -234,7 +234,7 @@ public function failing_jobs_are_released() Event::fake(JobReleasedAfterException::class); // Act - $job = $this->dispatch(new FailingJob()); + $job = $this->dispatch(new FailingJob); CloudTasksApi::assertDeletedTaskCount(0); CloudTasksApi::assertCreatedTaskCount(1); @@ -255,7 +255,7 @@ public function attempts_are_tracked_internally() Event::fake(JobReleasedAfterException::class); // Act & Assert - $job = $this->dispatch(new FailingJob()); + $job = $this->dispatch(new FailingJob); $released = $job->runAndGetReleasedJob(); @@ -281,7 +281,7 @@ public function retried_jobs_get_a_new_name() // Act & Assert $this->assertCount(0, $this->createdTasks); - $this->dispatch(new FailingJob())->runAndGetReleasedJob(); + $this->dispatch(new FailingJob)->runAndGetReleasedJob(); $this->assertCount(2, $this->createdTasks); $this->assertNotEquals($this->createdTasks[0]->getName(), $this->createdTasks[1]->getName()); } @@ -293,7 +293,7 @@ public function test_job_timeout() Event::fake(JobOutput::class); // Act - $this->dispatch(new SimpleJobWithTimeout())->run(); + $this->dispatch(new SimpleJobWithTimeout)->run(); // Assert $events = Event::dispatched(JobOutput::class)->map(fn ($event) => $event[0]->output)->toArray();