From cdc4bc229034b901cb0a3d8833203b2748dd6473 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 28 Oct 2024 10:11:56 +0800 Subject: [PATCH 1/7] wip Signed-off-by: Mior Muhammad Zaki --- .github/workflows/tests.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 75c28a9b..9651fbd6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -56,8 +56,7 @@ jobs: - name: Install dependencies run: | - composer require "illuminate/contracts=^${{ matrix.laravel }}" --dev --no-update - composer update --prefer-dist --no-interaction --no-progress + composer update --prefer-dist --no-interaction --no-progress --with=illuminate/contracts:^${{ matrix.laravel }} - name: Execute tests run: vendor/bin/phpunit From 319dd281ff0c374dd96c7cf507b98b79e4248a30 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 28 Oct 2024 10:12:33 +0800 Subject: [PATCH 2/7] wip Signed-off-by: Mior Muhammad Zaki --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9651fbd6..1e83ac4e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,6 +4,7 @@ on: push: branches: - master + - 'test-improvements' - '*.x' pull_request: schedule: From 4c6dc040f333c589af38b2b4746689708f8f9b04 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 28 Oct 2024 10:39:27 +0800 Subject: [PATCH 3/7] wip Signed-off-by: Mior Muhammad Zaki --- .github/workflows/tests.yml | 2 +- tests/IntegrationTest.php | 28 +++++++++++----------------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1e83ac4e..872b1fed 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -57,7 +57,7 @@ jobs: - name: Install dependencies run: | - composer update --prefer-dist --no-interaction --no-progress --with=illuminate/contracts:^${{ matrix.laravel }} + composer update --prefer-dist --no-interaction --no-progress --with="illuminate/contracts:^${{ matrix.laravel }}" - name: Execute tests run: vendor/bin/phpunit diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 84a2b88f..711ff9fd 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -20,24 +20,18 @@ abstract class IntegrationTest extends TestCase */ protected function setUp(): void { - parent::setUp(); - - Redis::flushall(); - } + $this->afterApplicationCreated(function () { + Redis::flushall(); + }); - /** - * Tear down the test case. - * - * @return void - */ - protected function tearDown(): void - { - parent::tearDown(); + $this->beforeApplicationDestroyed(function () { + Redis::flushall(); + WorkerCommandString::reset(); + SupervisorCommandString::reset(); + Horizon::$authUsing = null; + }); - Redis::flushall(); - WorkerCommandString::reset(); - SupervisorCommandString::reset(); - Horizon::$authUsing = null; + parent::setUp(); } /** @@ -48,7 +42,7 @@ protected function tearDown(): void */ public function wait($callback) { - retry(10, $callback, 1000); + retry(10, $callback, 2000); } /** From 255f90e13042fc7a8d93ed81963cf05cfaf30061 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 28 Oct 2024 10:57:33 +0800 Subject: [PATCH 4/7] wip Signed-off-by: Mior Muhammad Zaki --- src/PhpBinary.php | 8 ++++++-- tests/Feature/SupervisorTest.php | 2 ++ tests/IntegrationTest.php | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/PhpBinary.php b/src/PhpBinary.php index 18c5dc91..aa8476c0 100644 --- a/src/PhpBinary.php +++ b/src/PhpBinary.php @@ -2,6 +2,8 @@ namespace Laravel\Horizon; +use Illuminate\Support\ProcessUtils; + class PhpBinary { /** @@ -11,8 +13,10 @@ class PhpBinary */ public static function path() { - $escape = '\\' === DIRECTORY_SEPARATOR ? '"' : '\''; + if (function_exists('Illuminate\Support\php_binary')) { + return ProcessUtils::escapeArgument(\Illuminate\Support\php_binary()); + } - return $escape.PHP_BINARY.$escape; + return ProcessUtils::escapeArgument(PHP_BINARY); } } diff --git a/tests/Feature/SupervisorTest.php b/tests/Feature/SupervisorTest.php index d1bffc5d..ee3b7e80 100644 --- a/tests/Feature/SupervisorTest.php +++ b/tests/Feature/SupervisorTest.php @@ -49,6 +49,7 @@ protected function tearDown(): void parent::tearDown(); } + /** @requires extension redis */ public function test_supervisor_can_start_worker_process_with_given_options() { Queue::push(new Jobs\BasicJob); @@ -260,6 +261,7 @@ public function test_supervisor_can_restart_processes() $this->assertNotEquals($pid, $supervisor->processes()[0]->getPid()); } + /** @requires extension redis */ public function test_processes_can_be_paused_and_continued() { $options = $this->supervisorOptions(); diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 711ff9fd..d5896681 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -42,7 +42,7 @@ protected function setUp(): void */ public function wait($callback) { - retry(10, $callback, 2000); + retry(10, $callback, 1000); } /** From 63ce8f01022e198ada9b35dd5a355d7f819644e1 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 28 Oct 2024 10:58:00 +0800 Subject: [PATCH 5/7] wip Signed-off-by: Mior Muhammad Zaki --- src/PhpBinary.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/PhpBinary.php b/src/PhpBinary.php index aa8476c0..18c5dc91 100644 --- a/src/PhpBinary.php +++ b/src/PhpBinary.php @@ -2,8 +2,6 @@ namespace Laravel\Horizon; -use Illuminate\Support\ProcessUtils; - class PhpBinary { /** @@ -13,10 +11,8 @@ class PhpBinary */ public static function path() { - if (function_exists('Illuminate\Support\php_binary')) { - return ProcessUtils::escapeArgument(\Illuminate\Support\php_binary()); - } + $escape = '\\' === DIRECTORY_SEPARATOR ? '"' : '\''; - return ProcessUtils::escapeArgument(PHP_BINARY); + return $escape.PHP_BINARY.$escape; } } From 23cca98dfac09b2d463286fbd560688f4251fe59 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 28 Oct 2024 14:56:43 +0800 Subject: [PATCH 6/7] wip Signed-off-by: Mior Muhammad Zaki --- .../Listeners/MarkJobAsCompleteTest.php | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/tests/Feature/Listeners/MarkJobAsCompleteTest.php b/tests/Feature/Listeners/MarkJobAsCompleteTest.php index ab64fedd..959f3f74 100644 --- a/tests/Feature/Listeners/MarkJobAsCompleteTest.php +++ b/tests/Feature/Listeners/MarkJobAsCompleteTest.php @@ -11,25 +11,11 @@ use Laravel\Horizon\Listeners\MarkJobAsComplete; use Laravel\Horizon\Tests\IntegrationTest; use Mockery as m; +use Orchestra\Testbench\Attributes\WithConfig; +#[WithConfig('horizon.silenced', ['App\\Jobs\\ConfigJob'])] class MarkJobAsCompleteTest extends IntegrationTest { - protected function tearDown(): void - { - parent::tearDown(); - - m::close(); - } - - protected function getEnvironmentSetUp($app): void - { - parent::getEnvironmentSetUp($app); - - $app['config']->set('horizon.silenced', [ - 'App\\Jobs\\ConfigJob', - ]); - } - public function test_it_can_mark_a_job_as_complete(): void { $this->runScenario('App\\Jobs\\TestJob', false); From b49d7a7f0512b56a94c73dc7ec91307dfaddeed8 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 28 Oct 2024 19:25:53 +0800 Subject: [PATCH 7/7] wip Signed-off-by: Mior Muhammad Zaki --- tests/worker.php | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/tests/worker.php b/tests/worker.php index f513e95d..b4e71c7e 100644 --- a/tests/worker.php +++ b/tests/worker.php @@ -7,26 +7,11 @@ use Illuminate\Queue\QueueManager; use Illuminate\Queue\Worker; use Illuminate\Queue\WorkerOptions; -use Orchestra\Testbench\Concerns\CreatesApplication; -$appLoader = new class -{ - use CreatesApplication; - - /** - * Define environment setup. - * - * @param \Illuminate\Foundation\Application $app - * @return void - */ - protected function getEnvironmentSetUp($app) - { - // Define your environment setup. - } -}; +use function Orchestra\Testbench\container; // Configure the application... -$app = $appLoader->createApplication(); +$app = container()->createApplication(); $app->register(Laravel\Horizon\HorizonServiceProvider::class); $app->make('config')->set('queue.default', 'redis');