From eaa1d4445870ebf4258be97ece5c4c45a3733030 Mon Sep 17 00:00:00 2001 From: Richard McDaniel Date: Wed, 19 Mar 2025 12:21:46 +0000 Subject: [PATCH 01/18] Better exceptions --- .gitignore | 1 + src/Traits/Timers.php | 3 +- src/WorkflowStub.php | 5 ++- tests/Unit/Traits/TimersTest.php | 56 ++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 50e6f7f4..271eb9a2 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ composer.lock vendor coverage .env +.phpunit.cache .phpunit.result.cache .php_cs.cache .php-cs-fixer.cache diff --git a/src/Traits/Timers.php b/src/Traits/Timers.php index 88fa010a..2b2a324e 100644 --- a/src/Traits/Timers.php +++ b/src/Traits/Timers.php @@ -5,7 +5,6 @@ namespace Workflow\Traits; use Carbon\CarbonInterval; -use Illuminate\Database\QueryException; use React\Promise\Deferred; use React\Promise\PromiseInterface; use function React\Promise\resolve; @@ -64,7 +63,7 @@ public static function timer($seconds): PromiseInterface 'class' => Signal::class, 'result' => Serializer::serialize(true), ]); - } catch (QueryException $exception) { + } catch (\Illuminate\Database\UniqueConstraintViolationException $exception) { // already logged } } diff --git a/src/WorkflowStub.php b/src/WorkflowStub.php index 54e7b095..651e756e 100644 --- a/src/WorkflowStub.php +++ b/src/WorkflowStub.php @@ -4,7 +4,6 @@ namespace Workflow; -use Illuminate\Database\QueryException; use Illuminate\Support\Arr; use Illuminate\Support\Carbon; use Illuminate\Support\Traits\Macroable; @@ -226,7 +225,7 @@ public function fail($exception): void 'class' => $this->storedWorkflow->class, 'exception' => Serializer::serialize($exception), ]); - } catch (QueryException) { + } catch (\Illuminate\Database\UniqueConstraintViolationException $exception) { // already logged } @@ -267,7 +266,7 @@ public function next($index, $now, $class, $result): void 'class' => $class, 'result' => Serializer::serialize($result), ]); - } catch (QueryException) { + } catch (\Illuminate\Database\UniqueConstraintViolationException $exception) { // already logged } diff --git a/tests/Unit/Traits/TimersTest.php b/tests/Unit/Traits/TimersTest.php index cc038930..cb92d778 100644 --- a/tests/Unit/Traits/TimersTest.php +++ b/tests/Unit/Traits/TimersTest.php @@ -4,6 +4,10 @@ namespace Tests\Unit\Traits; +use Exception; +use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\UniqueConstraintViolationException; +use Mockery; use Tests\Fixtures\TestWorkflow; use Tests\TestCase; use Workflow\Models\StoredWorkflow; @@ -138,4 +142,56 @@ public function testLoadsStoredResult(): void ]); $this->assertSame(true, Serializer::unserialize($workflow->logs()->firstWhere('index', 0)->result)); } + + public function testHandlesDuplicateLogInsertionProperly(): void + { + $workflow = WorkflowStub::load(WorkflowStub::make(TestWorkflow::class)->id()); + $storedWorkflow = StoredWorkflow::findOrFail($workflow->id()); + $storedWorkflow->timers() + ->create([ + 'index' => 0, + 'stop_at' => now(), + ]); + $storedWorkflow->logs() + ->create([ + 'index' => 0, + 'now' => now(), + 'class' => Signal::class, + 'result' => Serializer::serialize(true), + ]); + + $mockLogs = Mockery::mock(HasMany::class) + ->shouldReceive('whereIndex') + ->once() + ->andReturnSelf() + ->shouldReceive('first') + ->once() + ->andReturn(null) + ->shouldReceive('create') + ->andThrow(new UniqueConstraintViolationException('', '', [], new Exception())) + ->getMock(); + + $mockStoredWorkflow = Mockery::spy($storedWorkflow); + + $mockStoredWorkflow->shouldReceive('logs') + ->andReturnUsing(static function () use ($mockLogs) { + return $mockLogs; + }); + + WorkflowStub::setContext([ + 'storedWorkflow' => $mockStoredWorkflow, + 'index' => 0, + 'now' => now(), + 'replaying' => false, + ]); + + WorkflowStub::timer('1 minute') + ->then(static function ($value) use (&$result) { + $result = $value; + }); + + Mockery::close(); + + $this->assertSame(true, $result); + } } From c638f0c8bf009657f673e053422ee347e3c0ccdd Mon Sep 17 00:00:00 2001 From: Richard McDaniel Date: Wed, 19 Mar 2025 13:18:01 +0000 Subject: [PATCH 02/18] Better exceptions --- tests/Unit/Traits/TimersTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/Traits/TimersTest.php b/tests/Unit/Traits/TimersTest.php index cb92d778..05f7d33b 100644 --- a/tests/Unit/Traits/TimersTest.php +++ b/tests/Unit/Traits/TimersTest.php @@ -194,4 +194,4 @@ public function testHandlesDuplicateLogInsertionProperly(): void $this->assertSame(true, $result); } -} +} \ No newline at end of file From 56881846433672639874455bc28c640e6904968f Mon Sep 17 00:00:00 2001 From: Richard McDaniel Date: Wed, 19 Mar 2025 13:18:05 +0000 Subject: [PATCH 03/18] Better exceptions --- tests/Unit/Traits/TimersTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/Traits/TimersTest.php b/tests/Unit/Traits/TimersTest.php index 05f7d33b..cb92d778 100644 --- a/tests/Unit/Traits/TimersTest.php +++ b/tests/Unit/Traits/TimersTest.php @@ -194,4 +194,4 @@ public function testHandlesDuplicateLogInsertionProperly(): void $this->assertSame(true, $result); } -} \ No newline at end of file +} From acc27b85b0e2eacd5df658cedb7f7c360df6ad6b Mon Sep 17 00:00:00 2001 From: Richard McDaniel Date: Wed, 19 Mar 2025 13:59:15 +0000 Subject: [PATCH 04/18] Better exceptions --- src/WorkflowStub.php | 14 +++++-------- tests/Unit/WorkflowStubTest.php | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/WorkflowStub.php b/src/WorkflowStub.php index 651e756e..9e61c5ef 100644 --- a/src/WorkflowStub.php +++ b/src/WorkflowStub.php @@ -219,15 +219,11 @@ public function startAsChild(StoredWorkflow $parentWorkflow, int $index, $now, . public function fail($exception): void { - try { - $this->storedWorkflow->exceptions() - ->create([ - 'class' => $this->storedWorkflow->class, - 'exception' => Serializer::serialize($exception), - ]); - } catch (\Illuminate\Database\UniqueConstraintViolationException $exception) { - // already logged - } + $this->storedWorkflow->exceptions() + ->create([ + 'class' => $this->storedWorkflow->class, + 'exception' => Serializer::serialize($exception), + ]); $this->storedWorkflow->status->transitionTo(WorkflowFailedStatus::class); diff --git a/tests/Unit/WorkflowStubTest.php b/tests/Unit/WorkflowStubTest.php index 0d030984..20bd90ab 100644 --- a/tests/Unit/WorkflowStubTest.php +++ b/tests/Unit/WorkflowStubTest.php @@ -6,6 +6,7 @@ use Exception; use Illuminate\Support\Carbon; +use Illuminate\Support\Facades\Queue; use Tests\Fixtures\TestAwaitWorkflow; use Tests\Fixtures\TestBadConnectionWorkflow; use Tests\Fixtures\TestWorkflow; @@ -14,6 +15,7 @@ use Workflow\Serializers\Serializer; use Workflow\Signal; use Workflow\States\WorkflowCompletedStatus; +use Workflow\States\WorkflowCreatedStatus; use Workflow\States\WorkflowPendingStatus; use Workflow\WorkflowStub; @@ -207,4 +209,38 @@ public function testConnection(): void $this->assertSame('redis', WorkflowStub::connection()); $this->assertSame('default', WorkflowStub::queue()); } + + public function testHandlesDuplicateLogInsertionProperly(): void + { + Queue::fake(); + + $workflow = WorkflowStub::load(WorkflowStub::make(TestWorkflow::class)->id()); + $storedWorkflow = StoredWorkflow::findOrFail($workflow->id()); + $storedWorkflow->update([ + 'arguments' => Serializer::serialize([]), + 'status' => WorkflowCreatedStatus::$name, + ]); + + $storedWorkflow->timers() + ->create([ + 'index' => 0, + 'stop_at' => now(), + ]); + $storedWorkflow->logs() + ->create([ + 'index' => 0, + 'now' => now(), + 'class' => Signal::class, + 'result' => Serializer::serialize(true), + ]); + + $workflow = $storedWorkflow->toWorkflow(); + + $workflow->next(0, now(), Signal::class, true); + + $this->assertSame(WorkflowPendingStatus::class, $workflow->status()); + $this->assertSame(1, $workflow->logs()->count()); + + Queue::assertPushed(TestWorkflow::class, 1); + } } From fee52716309315d42cddef01731b20889417a839 Mon Sep 17 00:00:00 2001 From: Richard McDaniel Date: Thu, 20 Mar 2025 00:50:33 +0000 Subject: [PATCH 05/18] Better exceptions --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 578bb292..f6447e09 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -9,7 +9,7 @@ on: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 services: mysql: From 9427f5a681c2758c44c2e6d9a4f4fff2633433ee Mon Sep 17 00:00:00 2001 From: Richard McDaniel Date: Sat, 22 Mar 2025 20:39:07 +0000 Subject: [PATCH 06/18] Better exceptions --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index f6447e09..af24fff8 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -65,7 +65,7 @@ jobs: mysql -e 'CREATE DATABASE testbench' -h127.0.0.1 -uroot -ppassword -P ${{ job.services.mysql.ports[3306] }} - name: Run test suite (MySQL) - run: vendor/bin/phpunit --testdox --testsuite feature + run: vendor/bin/phpunit --testdox --testsuite feature --debug --verbose env: APP_KEY: base64:i3g6f+dV8FfsIkcxqd7gbiPn2oXk5r00sTmdD6V5utI= DB_CONNECTION: mysql From 33079b7449ec105dd018a7547705e6e1cafbe454 Mon Sep 17 00:00:00 2001 From: Richard McDaniel Date: Sat, 22 Mar 2025 20:41:52 +0000 Subject: [PATCH 07/18] Better exceptions --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index af24fff8..fff5d4b7 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -65,7 +65,7 @@ jobs: mysql -e 'CREATE DATABASE testbench' -h127.0.0.1 -uroot -ppassword -P ${{ job.services.mysql.ports[3306] }} - name: Run test suite (MySQL) - run: vendor/bin/phpunit --testdox --testsuite feature --debug --verbose + run: vendor/bin/phpunit --testdox --testsuite feature --debug env: APP_KEY: base64:i3g6f+dV8FfsIkcxqd7gbiPn2oXk5r00sTmdD6V5utI= DB_CONNECTION: mysql From 680cc0ce82774286524804f94584efab926605ec Mon Sep 17 00:00:00 2001 From: Richard McDaniel Date: Sat, 22 Mar 2025 20:51:30 +0000 Subject: [PATCH 08/18] Better exceptions --- .github/workflows/php.yml | 2 +- tests/TestCase.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index fff5d4b7..f6447e09 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -65,7 +65,7 @@ jobs: mysql -e 'CREATE DATABASE testbench' -h127.0.0.1 -uroot -ppassword -P ${{ job.services.mysql.ports[3306] }} - name: Run test suite (MySQL) - run: vendor/bin/phpunit --testdox --testsuite feature --debug + run: vendor/bin/phpunit --testdox --testsuite feature env: APP_KEY: base64:i3g6f+dV8FfsIkcxqd7gbiPn2oXk5r00sTmdD6V5utI= DB_CONNECTION: mysql diff --git a/tests/TestCase.php b/tests/TestCase.php index 901d0e9e..144836fb 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -17,6 +17,7 @@ abstract class TestCase extends BaseTestCase public static function setUpBeforeClass(): void { if (getenv('GITHUB_ACTIONS') !== 'true') { + dump('Loading environment variables'); if (TestSuiteSubscriber::getCurrentSuite() === 'feature') { Dotenv::createImmutable(__DIR__, '.env.feature')->safeLoad(); } elseif (TestSuiteSubscriber::getCurrentSuite() === 'unit') { From efac355e83db9caeb756b26780429e3e78370fbf Mon Sep 17 00:00:00 2001 From: Richard McDaniel Date: Sat, 22 Mar 2025 20:54:39 +0000 Subject: [PATCH 09/18] Better exceptions --- tests/TestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 144836fb..a3e2fee6 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -16,8 +16,8 @@ abstract class TestCase extends BaseTestCase public static function setUpBeforeClass(): void { + dump('GITHUB_ACTIONS: ' . getenv('GITHUB_ACTIONS')); if (getenv('GITHUB_ACTIONS') !== 'true') { - dump('Loading environment variables'); if (TestSuiteSubscriber::getCurrentSuite() === 'feature') { Dotenv::createImmutable(__DIR__, '.env.feature')->safeLoad(); } elseif (TestSuiteSubscriber::getCurrentSuite() === 'unit') { From 9e42621d57f565c2a5986a6f9b54fafd4a25a083 Mon Sep 17 00:00:00 2001 From: Richard McDaniel Date: Sat, 22 Mar 2025 21:01:34 +0000 Subject: [PATCH 10/18] Better exceptions --- .github/workflows/php.yml | 2 +- tests/TestCase.php | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index f6447e09..ea6e3029 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -57,7 +57,7 @@ jobs: run: vendor/bin/ecs check - name: Run static analysis via PHPStan - run: vendor/bin/phpstan --xdebug analyse src tests + run: vendor/bin/phpstan analyse src tests - name: Create databases run: | diff --git a/tests/TestCase.php b/tests/TestCase.php index a3e2fee6..2f22a9d4 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -16,7 +16,6 @@ abstract class TestCase extends BaseTestCase public static function setUpBeforeClass(): void { - dump('GITHUB_ACTIONS: ' . getenv('GITHUB_ACTIONS')); if (getenv('GITHUB_ACTIONS') !== 'true') { if (TestSuiteSubscriber::getCurrentSuite() === 'feature') { Dotenv::createImmutable(__DIR__, '.env.feature')->safeLoad(); @@ -32,6 +31,11 @@ public static function setUpBeforeClass(): void 'queue:work', ]); self::$workers[$i]->start(); + + if (!self::$workers[$i]->isRunning()) { + dump(self::$workers[$i]->getOutput()); + dump(self::$workers[$i]->getErrorOutput()); + } } } From 4fcc3f9d946108c0729b380815b057fc32a94d29 Mon Sep 17 00:00:00 2001 From: Richard McDaniel Date: Sat, 22 Mar 2025 21:02:44 +0000 Subject: [PATCH 11/18] Better exceptions --- tests/TestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 2f22a9d4..5f0cabe0 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -32,7 +32,7 @@ public static function setUpBeforeClass(): void ]); self::$workers[$i]->start(); - if (!self::$workers[$i]->isRunning()) { + if (! self::$workers[$i]->isRunning()) { dump(self::$workers[$i]->getOutput()); dump(self::$workers[$i]->getErrorOutput()); } From 584beb306c013c6fad59f1c456cfbce33b2d6cee Mon Sep 17 00:00:00 2001 From: Richard McDaniel Date: Sat, 22 Mar 2025 21:05:33 +0000 Subject: [PATCH 12/18] Better exceptions --- tests/TestCase.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/TestCase.php b/tests/TestCase.php index 5f0cabe0..fa556e48 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -22,9 +22,15 @@ public static function setUpBeforeClass(): void } elseif (TestSuiteSubscriber::getCurrentSuite() === 'unit') { Dotenv::createImmutable(__DIR__, '.env.unit')->safeLoad(); } + } else { + dump('Running in GitHub Actions, skipping dotenv loading.'); } for ($i = 0; $i < self::NUMBER_OF_WORKERS; $i++) { + dump(__DIR__ . '/../vendor/orchestra/testbench-core/laravel/artisan'); + if (! file_exists(__DIR__ . '/../vendor/orchestra/testbench-core/laravel/artisan')) { + dump('Artisan file does not exist.'); + } self::$workers[$i] = new Process([ 'php', __DIR__ . '/../vendor/orchestra/testbench-core/laravel/artisan', From cd2b026ea135190c54fa1325fdab4b3493294678 Mon Sep 17 00:00:00 2001 From: Richard McDaniel Date: Sat, 22 Mar 2025 21:13:36 +0000 Subject: [PATCH 13/18] Better exceptions --- .github/workflows/php.yml | 35 +++++++++++++++++++++++++++++++++++ tests/TestCase.php | 27 +++++++++------------------ 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index ea6e3029..103a5ca6 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -64,6 +64,23 @@ jobs: touch testbench.sqlite mysql -e 'CREATE DATABASE testbench' -h127.0.0.1 -uroot -ppassword -P ${{ job.services.mysql.ports[3306] }} + - name: Start queue workers + run: | + php artisan queue:work --daemon --quiet & + php artisan queue:work --daemon --quiet & + env: + APP_KEY: base64:i3g6f+dV8FfsIkcxqd7gbiPn2oXk5r00sTmdD6V5utI= + DB_CONNECTION: mysql + DB_DATABASE: testbench + DB_HOST: 127.0.0.1 + DB_PORT: 3306 + DB_USERNAME: root + DB_PASSWORD: password + QUEUE_CONNECTION: redis + REDIS_HOST: 127.0.0.1 + REDIS_PASSWORD: + REDIS_PORT: 6379 + - name: Run test suite (MySQL) run: vendor/bin/phpunit --testdox --testsuite feature env: @@ -79,6 +96,24 @@ jobs: REDIS_PASSWORD: REDIS_PORT: 6379 + - name: Restart queue workers for PostgreSQL + run: | + pkill -f 'php artisan queue:work' || true + php artisan queue:work --daemon --quiet & + php artisan queue:work --daemon --quiet & + env: + APP_KEY: base64:i3g6f+dV8FfsIkcxqd7gbiPn2oXk5r00sTmdD6V5utI= + DB_CONNECTION: pgsql + DB_DATABASE: testbench + DB_HOST: 127.0.0.1 + DB_PORT: 5432 + DB_USERNAME: root + DB_PASSWORD: password + QUEUE_CONNECTION: redis + REDIS_HOST: 127.0.0.1 + REDIS_PASSWORD: + REDIS_PORT: 6379 + - name: Run test suite (PostgreSQL) run: vendor/bin/phpunit --testdox --testsuite feature env: diff --git a/tests/TestCase.php b/tests/TestCase.php index fa556e48..5fa846d8 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -22,26 +22,17 @@ public static function setUpBeforeClass(): void } elseif (TestSuiteSubscriber::getCurrentSuite() === 'unit') { Dotenv::createImmutable(__DIR__, '.env.unit')->safeLoad(); } - } else { - dump('Running in GitHub Actions, skipping dotenv loading.'); - } - for ($i = 0; $i < self::NUMBER_OF_WORKERS; $i++) { - dump(__DIR__ . '/../vendor/orchestra/testbench-core/laravel/artisan'); - if (! file_exists(__DIR__ . '/../vendor/orchestra/testbench-core/laravel/artisan')) { - dump('Artisan file does not exist.'); - } - self::$workers[$i] = new Process([ - 'php', - __DIR__ . '/../vendor/orchestra/testbench-core/laravel/artisan', - 'queue:work', - ]); - self::$workers[$i]->start(); - - if (! self::$workers[$i]->isRunning()) { - dump(self::$workers[$i]->getOutput()); - dump(self::$workers[$i]->getErrorOutput()); + for ($i = 0; $i < self::NUMBER_OF_WORKERS; $i++) { + self::$workers[$i] = new Process([ + 'php', + __DIR__ . '/../vendor/orchestra/testbench-core/laravel/artisan', + 'queue:work', + ]); + self::$workers[$i]->start(); } + } else { + dump('Running in GitHub Actions.'); } } From 105aaf63cdb9e8a709a2b37b4a2d3dce6d6f75e4 Mon Sep 17 00:00:00 2001 From: Richard McDaniel Date: Sat, 22 Mar 2025 21:15:49 +0000 Subject: [PATCH 14/18] Better exceptions --- .github/workflows/php.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 103a5ca6..8b300620 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -66,8 +66,8 @@ jobs: - name: Start queue workers run: | - php artisan queue:work --daemon --quiet & - php artisan queue:work --daemon --quiet & + php vendor/orchestra/testbench-core/laravel/artisan queue:work --daemon --quiet & + php vendor/orchestra/testbench-core/laravel/artisan queue:work --daemon --quiet & env: APP_KEY: base64:i3g6f+dV8FfsIkcxqd7gbiPn2oXk5r00sTmdD6V5utI= DB_CONNECTION: mysql @@ -99,8 +99,8 @@ jobs: - name: Restart queue workers for PostgreSQL run: | pkill -f 'php artisan queue:work' || true - php artisan queue:work --daemon --quiet & - php artisan queue:work --daemon --quiet & + php vendor/orchestra/testbench-core/laravel/artisan queue:work --daemon --quiet & + php vendor/orchestra/testbench-core/laravel/artisan queue:work --daemon --quiet & env: APP_KEY: base64:i3g6f+dV8FfsIkcxqd7gbiPn2oXk5r00sTmdD6V5utI= DB_CONNECTION: pgsql From 526e4baba34e4afb562d53e3d0f45895ba3ede08 Mon Sep 17 00:00:00 2001 From: Richard McDaniel Date: Sat, 22 Mar 2025 21:19:29 +0000 Subject: [PATCH 15/18] Better exceptions --- .github/workflows/php.yml | 35 ----------------------------------- tests/TestCase.php | 18 ++++++++---------- 2 files changed, 8 insertions(+), 45 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 8b300620..ea6e3029 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -64,23 +64,6 @@ jobs: touch testbench.sqlite mysql -e 'CREATE DATABASE testbench' -h127.0.0.1 -uroot -ppassword -P ${{ job.services.mysql.ports[3306] }} - - name: Start queue workers - run: | - php vendor/orchestra/testbench-core/laravel/artisan queue:work --daemon --quiet & - php vendor/orchestra/testbench-core/laravel/artisan queue:work --daemon --quiet & - env: - APP_KEY: base64:i3g6f+dV8FfsIkcxqd7gbiPn2oXk5r00sTmdD6V5utI= - DB_CONNECTION: mysql - DB_DATABASE: testbench - DB_HOST: 127.0.0.1 - DB_PORT: 3306 - DB_USERNAME: root - DB_PASSWORD: password - QUEUE_CONNECTION: redis - REDIS_HOST: 127.0.0.1 - REDIS_PASSWORD: - REDIS_PORT: 6379 - - name: Run test suite (MySQL) run: vendor/bin/phpunit --testdox --testsuite feature env: @@ -96,24 +79,6 @@ jobs: REDIS_PASSWORD: REDIS_PORT: 6379 - - name: Restart queue workers for PostgreSQL - run: | - pkill -f 'php artisan queue:work' || true - php vendor/orchestra/testbench-core/laravel/artisan queue:work --daemon --quiet & - php vendor/orchestra/testbench-core/laravel/artisan queue:work --daemon --quiet & - env: - APP_KEY: base64:i3g6f+dV8FfsIkcxqd7gbiPn2oXk5r00sTmdD6V5utI= - DB_CONNECTION: pgsql - DB_DATABASE: testbench - DB_HOST: 127.0.0.1 - DB_PORT: 5432 - DB_USERNAME: root - DB_PASSWORD: password - QUEUE_CONNECTION: redis - REDIS_HOST: 127.0.0.1 - REDIS_PASSWORD: - REDIS_PORT: 6379 - - name: Run test suite (PostgreSQL) run: vendor/bin/phpunit --testdox --testsuite feature env: diff --git a/tests/TestCase.php b/tests/TestCase.php index 5fa846d8..7c82c3da 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -22,17 +22,15 @@ public static function setUpBeforeClass(): void } elseif (TestSuiteSubscriber::getCurrentSuite() === 'unit') { Dotenv::createImmutable(__DIR__, '.env.unit')->safeLoad(); } + } - for ($i = 0; $i < self::NUMBER_OF_WORKERS; $i++) { - self::$workers[$i] = new Process([ - 'php', - __DIR__ . '/../vendor/orchestra/testbench-core/laravel/artisan', - 'queue:work', - ]); - self::$workers[$i]->start(); - } - } else { - dump('Running in GitHub Actions.'); + for ($i = 0; $i < self::NUMBER_OF_WORKERS; $i++) { + self::$workers[$i] = new Process([ + 'php', + __DIR__ . '/../vendor/bin/testbench', + 'queue:work', + ]); + self::$workers[$i]->start(); } } From 7ee0ad963592584b3e56d256cb615d943ab86da9 Mon Sep 17 00:00:00 2001 From: Richard McDaniel Date: Sat, 22 Mar 2025 21:21:38 +0000 Subject: [PATCH 16/18] Better exceptions --- tests/TestCase.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 7c82c3da..804f923f 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -25,11 +25,7 @@ public static function setUpBeforeClass(): void } for ($i = 0; $i < self::NUMBER_OF_WORKERS; $i++) { - self::$workers[$i] = new Process([ - 'php', - __DIR__ . '/../vendor/bin/testbench', - 'queue:work', - ]); + self::$workers[$i] = new Process(['php', __DIR__ . '/../vendor/bin/testbench', 'queue:work']); self::$workers[$i]->start(); } } From 472cad450ca9b1d2f4006a77abcd02c4dbd4823c Mon Sep 17 00:00:00 2001 From: Richard McDaniel Date: Sat, 22 Mar 2025 21:28:05 +0000 Subject: [PATCH 17/18] Better exceptions --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index ea6e3029..68747902 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -9,7 +9,7 @@ on: jobs: build: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest services: mysql: From d41a830309cb13c240bf61d177d815b43f8cd5ff Mon Sep 17 00:00:00 2001 From: Richard McDaniel Date: Sat, 22 Mar 2025 21:48:48 +0000 Subject: [PATCH 18/18] Better exceptions --- .../Unit/Listeners/MonitorActivityCompletedTest.php | 4 ++++ tests/Unit/Listeners/MonitorActivityFailedTest.php | 4 ++++ tests/Unit/Listeners/MonitorActivityStartedTest.php | 4 ++++ .../Unit/Listeners/MonitorWorkflowCompletedTest.php | 4 ++++ tests/Unit/Listeners/MonitorWorkflowFailedTest.php | 4 ++++ tests/Unit/Listeners/MonitorWorkflowStartedTest.php | 4 ++++ .../Middleware/WithoutOverlappingMiddlewareTest.php | 12 ++++++++++++ 7 files changed, 36 insertions(+) diff --git a/tests/Unit/Listeners/MonitorActivityCompletedTest.php b/tests/Unit/Listeners/MonitorActivityCompletedTest.php index ee2a4b6a..0e09da20 100644 --- a/tests/Unit/Listeners/MonitorActivityCompletedTest.php +++ b/tests/Unit/Listeners/MonitorActivityCompletedTest.php @@ -15,6 +15,10 @@ final class MonitorActivityCompletedTest extends TestCase { public function testHandle(): void { + $this->app->make('cache') + ->store() + ->clear(); + config([ 'workflows.monitor_url' => 'http://test', ]); diff --git a/tests/Unit/Listeners/MonitorActivityFailedTest.php b/tests/Unit/Listeners/MonitorActivityFailedTest.php index 78b1dd92..994ad6dd 100644 --- a/tests/Unit/Listeners/MonitorActivityFailedTest.php +++ b/tests/Unit/Listeners/MonitorActivityFailedTest.php @@ -15,6 +15,10 @@ final class MonitorActivityFailedTest extends TestCase { public function testHandle(): void { + $this->app->make('cache') + ->store() + ->clear(); + config([ 'workflows.monitor_url' => 'http://test', ]); diff --git a/tests/Unit/Listeners/MonitorActivityStartedTest.php b/tests/Unit/Listeners/MonitorActivityStartedTest.php index f11213f6..6c443076 100644 --- a/tests/Unit/Listeners/MonitorActivityStartedTest.php +++ b/tests/Unit/Listeners/MonitorActivityStartedTest.php @@ -15,6 +15,10 @@ final class MonitorActivityStartedTest extends TestCase { public function testHandle(): void { + $this->app->make('cache') + ->store() + ->clear(); + config([ 'workflows.monitor_url' => 'http://test', ]); diff --git a/tests/Unit/Listeners/MonitorWorkflowCompletedTest.php b/tests/Unit/Listeners/MonitorWorkflowCompletedTest.php index c17baee7..3e1159d2 100644 --- a/tests/Unit/Listeners/MonitorWorkflowCompletedTest.php +++ b/tests/Unit/Listeners/MonitorWorkflowCompletedTest.php @@ -14,6 +14,10 @@ final class MonitorWorkflowCompletedTest extends TestCase { public function testHandle(): void { + $this->app->make('cache') + ->store() + ->clear(); + config([ 'workflows.monitor_url' => 'http://test', ]); diff --git a/tests/Unit/Listeners/MonitorWorkflowFailedTest.php b/tests/Unit/Listeners/MonitorWorkflowFailedTest.php index ff076088..ffd5e5a8 100644 --- a/tests/Unit/Listeners/MonitorWorkflowFailedTest.php +++ b/tests/Unit/Listeners/MonitorWorkflowFailedTest.php @@ -14,6 +14,10 @@ final class MonitorWorkflowFailedTest extends TestCase { public function testHandle(): void { + $this->app->make('cache') + ->store() + ->clear(); + config([ 'workflows.monitor_url' => 'http://test', ]); diff --git a/tests/Unit/Listeners/MonitorWorkflowStartedTest.php b/tests/Unit/Listeners/MonitorWorkflowStartedTest.php index f57f1e3c..6c2a24ed 100644 --- a/tests/Unit/Listeners/MonitorWorkflowStartedTest.php +++ b/tests/Unit/Listeners/MonitorWorkflowStartedTest.php @@ -14,6 +14,10 @@ final class MonitorWorkflowStartedTest extends TestCase { public function testHandle(): void { + $this->app->make('cache') + ->store() + ->clear(); + config([ 'workflows.monitor_url' => 'http://test', ]); diff --git a/tests/Unit/Middleware/WithoutOverlappingMiddlewareTest.php b/tests/Unit/Middleware/WithoutOverlappingMiddlewareTest.php index 10b17541..c0502a2b 100644 --- a/tests/Unit/Middleware/WithoutOverlappingMiddlewareTest.php +++ b/tests/Unit/Middleware/WithoutOverlappingMiddlewareTest.php @@ -15,6 +15,10 @@ final class WithoutOverlappingMiddlewareTest extends TestCase { public function testMiddleware(): void { + $this->app->make('cache') + ->store() + ->clear(); + $middleware = new WithoutOverlappingMiddleware(1, WithoutOverlappingMiddleware::WORKFLOW); $this->assertSame($middleware->getLockKey(), 'laravel-workflow-overlap:1'); $this->assertSame($middleware->getWorkflowSemaphoreKey(), 'laravel-workflow-overlap:1:workflow'); @@ -28,6 +32,10 @@ public function testMiddleware(): void public function testAllowsOnlyOneWorkflowInstance(): void { + $this->app->make('cache') + ->store() + ->clear(); + $workflow1 = $this->mock(TestWorkflow::class); $middleware1 = new WithoutOverlappingMiddleware(1, WithoutOverlappingMiddleware::WORKFLOW); @@ -65,6 +73,10 @@ public function testAllowsOnlyOneWorkflowInstance(): void public function testAllowsMultipleActivityInstances(): void { + $this->app->make('cache') + ->store() + ->clear(); + $activity1 = $this->mock(TestActivity::class); $middleware1 = new WithoutOverlappingMiddleware(1, WithoutOverlappingMiddleware::ACTIVITY);