From 1dcfd78525d456c591efa70e73d9b51cf49aaf1d Mon Sep 17 00:00:00 2001 From: barbosa89 Date: Wed, 5 Nov 2025 11:43:35 -0500 Subject: [PATCH 1/5] feat: include InteractWithDatabase trait in TestCase class --- src/Testing/TestCase.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Testing/TestCase.php b/src/Testing/TestCase.php index 547f67d0..4485968a 100644 --- a/src/Testing/TestCase.php +++ b/src/Testing/TestCase.php @@ -13,6 +13,7 @@ use Phenix\Facades\Mail; use Phenix\Facades\Queue; use Phenix\Facades\View; +use Phenix\Testing\Concerns\InteractWithDatabase; use Phenix\Testing\Concerns\InteractWithResponses; use Phenix\Testing\Concerns\RefreshDatabase; use Symfony\Component\Console\Tester\CommandTester; @@ -22,6 +23,7 @@ abstract class TestCase extends AsyncTestCase { use InteractWithResponses; + use InteractWithDatabase; protected ?AppProxy $app; protected string $appDir; From fc81e2f61d502ac3a14cd6965fa8268ccf43b957 Mon Sep 17 00:00:00 2001 From: barbosa89 Date: Wed, 5 Nov 2025 11:43:40 -0500 Subject: [PATCH 2/5] fix: correct base class reference in TestCase --- tests/TestCase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index f1d42dd5..dcace41a 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -7,9 +7,9 @@ use Amp\Cancellation; use Amp\Sync\Channel; use Closure; -use Phenix\Testing\TestCase as TestingTestCase; +use Phenix\Testing\TestCase as BaseTestCase; -class TestCase extends TestingTestCase +class TestCase extends BaseTestCase { protected function getAppDir(): string { From 796cc42fa69a1e4481970b82f140052042b6fe90 Mon Sep 17 00:00:00 2001 From: barbosa89 Date: Wed, 5 Nov 2025 12:02:59 -0500 Subject: [PATCH 3/5] refactor: move anounimous classes to internal files --- tests/Internal/FakeCancellation.php | 33 ++++++++++++++++ tests/Internal/FakeChannel.php | 44 +++++++++++++++++++++ tests/TestCase.php | 61 ++--------------------------- 3 files changed, 81 insertions(+), 57 deletions(-) create mode 100644 tests/Internal/FakeCancellation.php create mode 100644 tests/Internal/FakeChannel.php diff --git a/tests/Internal/FakeCancellation.php b/tests/Internal/FakeCancellation.php new file mode 100644 index 00000000..b21d4d58 --- /dev/null +++ b/tests/Internal/FakeCancellation.php @@ -0,0 +1,33 @@ + Date: Wed, 5 Nov 2025 12:07:10 -0500 Subject: [PATCH 4/5] feat: add support for unit tests with new stub and option in MakeTest command --- src/Console/Commands/MakeTest.php | 4 ++++ src/stubs/test.stub | 2 ++ src/stubs/test.unit.stub | 7 +++++++ 3 files changed, 13 insertions(+) create mode 100644 src/stubs/test.unit.stub diff --git a/src/Console/Commands/MakeTest.php b/src/Console/Commands/MakeTest.php index 0dc7dd53..dfafe08e 100644 --- a/src/Console/Commands/MakeTest.php +++ b/src/Console/Commands/MakeTest.php @@ -47,6 +47,10 @@ protected function outputDirectory(): string protected function stub(): string { + if ($this->input->getOption('unit')) { + return 'test.unit.stub'; + } + return 'test.stub'; } diff --git a/src/stubs/test.stub b/src/stubs/test.stub index 904678e8..a3dd14ac 100644 --- a/src/stubs/test.stub +++ b/src/stubs/test.stub @@ -2,6 +2,8 @@ declare(strict_types=1); +// uses(RefreshDatabase::class); + it('asserts truthy', function () { expect(true)->toBeTruthy(); }); diff --git a/src/stubs/test.unit.stub b/src/stubs/test.unit.stub new file mode 100644 index 00000000..904678e8 --- /dev/null +++ b/src/stubs/test.unit.stub @@ -0,0 +1,7 @@ +toBeTruthy(); +}); From ddf24896e8f096ad02faa94f97af01eabc339450 Mon Sep 17 00:00:00 2001 From: barbosa89 Date: Wed, 5 Nov 2025 13:11:29 -0500 Subject: [PATCH 5/5] style: php cs --- tests/Internal/FakeCancellation.php | 2 +- tests/Internal/FakeChannel.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Internal/FakeCancellation.php b/tests/Internal/FakeCancellation.php index b21d4d58..99d7b891 100644 --- a/tests/Internal/FakeCancellation.php +++ b/tests/Internal/FakeCancellation.php @@ -30,4 +30,4 @@ public function throwIfRequested(): void // However, in a real implementation, this would throw an exception // to indicate that the cancellation has been requested. } -} \ No newline at end of file +} diff --git a/tests/Internal/FakeChannel.php b/tests/Internal/FakeChannel.php index ea3b8570..4f62c158 100644 --- a/tests/Internal/FakeChannel.php +++ b/tests/Internal/FakeChannel.php @@ -41,4 +41,4 @@ public function onClose(Closure $onClose): void // handling of the onClose callback. If used in production, this should be implemented // to handle resource cleanup or other necessary actions when the channel is closed. } -} \ No newline at end of file +}