From ed850ec29ae0f383be6179f3542a2b7352d71344 Mon Sep 17 00:00:00 2001 From: Opblaasmaatje Date: Tue, 5 May 2026 22:16:34 +0200 Subject: [PATCH 1/2] fix: Move TestingDatabaseInitialzer to framework/testing, add SkipDiscovery and a method to swap database initializer --- src/Tempest/Framework/Testing/IntegrationTest.php | 9 +++++++++ .../Framework/Testing}/TestingDatabaseInitializer.php | 4 +++- tests/Integration/Database/MultiDatabaseTest.php | 3 +-- tests/Integration/FrameworkIntegrationTestCase.php | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) rename {tests/Integration => src/Tempest/Framework/Testing}/TestingDatabaseInitializer.php (95%) diff --git a/src/Tempest/Framework/Testing/IntegrationTest.php b/src/Tempest/Framework/Testing/IntegrationTest.php index 02964bcfc3..94a8d852b6 100644 --- a/src/Tempest/Framework/Testing/IntegrationTest.php +++ b/src/Tempest/Framework/Testing/IntegrationTest.php @@ -27,6 +27,7 @@ use Tempest\Http\GenericRequest; use Tempest\Http\Method; use Tempest\Http\Request; +use Tempest\Database\DatabaseInitializer; use Tempest\Mail\Testing\MailTester; use Tempest\Mail\Testing\TestingMailer; use Tempest\Process\Testing\ProcessTester; @@ -208,6 +209,14 @@ protected function setupBaseRequest(): self return $this; } + protected function useTestingDatabase(): self + { + $this->container->removeInitializer(DatabaseInitializer::class); + $this->container->addInitializer(TestingDatabaseInitializer::class); + + return $this; + } + protected function clock(DateTimeInterface|string $now = 'now'): MockClock { $clock = new MockClock($now); diff --git a/tests/Integration/TestingDatabaseInitializer.php b/src/Tempest/Framework/Testing/TestingDatabaseInitializer.php similarity index 95% rename from tests/Integration/TestingDatabaseInitializer.php rename to src/Tempest/Framework/Testing/TestingDatabaseInitializer.php index 55cfb49ef0..20f79fc14e 100644 --- a/tests/Integration/TestingDatabaseInitializer.php +++ b/src/Tempest/Framework/Testing/TestingDatabaseInitializer.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tests\Tempest\Integration; +namespace Tempest\Framework\Testing; use Tempest\Container\Container; use Tempest\Container\DynamicInitializer; @@ -13,12 +13,14 @@ use Tempest\Database\Database; use Tempest\Database\GenericDatabase; use Tempest\Database\Transactions\GenericTransactionManager; +use Tempest\Discovery\SkipDiscovery; use Tempest\EventBus\EventBus; use Tempest\Mapper\SerializerFactory; use Tempest\Reflection\ClassReflector; use Tempest\Support\Str; use UnitEnum; +#[SkipDiscovery] final class TestingDatabaseInitializer implements DynamicInitializer { /** @var Connection[] */ diff --git a/tests/Integration/Database/MultiDatabaseTest.php b/tests/Integration/Database/MultiDatabaseTest.php index 4ae4a94b33..d0fa357b99 100644 --- a/tests/Integration/Database/MultiDatabaseTest.php +++ b/tests/Integration/Database/MultiDatabaseTest.php @@ -19,13 +19,12 @@ use Tempest\Database\QueryStatements\CreateTableStatement; use Tempest\Database\QueryStatements\DropTableStatement; use Tempest\Database\ShouldMigrate; +use Tempest\Framework\Testing\TestingDatabaseInitializer; use Tests\Tempest\Fixtures\Migrations\CreateBookTable; use Tests\Tempest\Fixtures\Migrations\CreatePublishersTable; use Tests\Tempest\Fixtures\Modules\Books\Models\Book; use Tests\Tempest\Fixtures\Modules\Books\Models\Publisher; use Tests\Tempest\Integration\FrameworkIntegrationTestCase; -use Tests\Tempest\Integration\TestingDatabaseInitializer; - use function Tempest\Database\query; /** diff --git a/tests/Integration/FrameworkIntegrationTestCase.php b/tests/Integration/FrameworkIntegrationTestCase.php index 66efa7148a..5d67ab349a 100644 --- a/tests/Integration/FrameworkIntegrationTestCase.php +++ b/tests/Integration/FrameworkIntegrationTestCase.php @@ -9,9 +9,9 @@ use Tempest\Database\DatabaseInitializer; use Tempest\Discovery\DiscoveryLocation; use Tempest\Framework\Testing\IntegrationTest; +use Tempest\Framework\Testing\TestingDatabaseInitializer; use Tempest\Support\Filesystem; use Tempest\Support\Path; - use function Tempest\Support\str; abstract class FrameworkIntegrationTestCase extends IntegrationTest From cbb1bd46b761197757af98a1d9c064494286d83f Mon Sep 17 00:00:00 2001 From: Opblaasmaatje Date: Wed, 6 May 2026 10:28:41 +0200 Subject: [PATCH 2/2] fix: format files --- src/Tempest/Framework/Testing/IntegrationTest.php | 2 +- tests/Integration/Database/MultiDatabaseTest.php | 1 + tests/Integration/FrameworkIntegrationTestCase.php | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Tempest/Framework/Testing/IntegrationTest.php b/src/Tempest/Framework/Testing/IntegrationTest.php index 94a8d852b6..a51b95fb21 100644 --- a/src/Tempest/Framework/Testing/IntegrationTest.php +++ b/src/Tempest/Framework/Testing/IntegrationTest.php @@ -18,6 +18,7 @@ use Tempest\Container\GenericContainer; use Tempest\Core\Exceptions\ExceptionTester; use Tempest\Core\FrameworkKernel; +use Tempest\Database\DatabaseInitializer; use Tempest\Database\Testing\DatabaseTester; use Tempest\DateTime\DateTimeInterface; use Tempest\Discovery\DiscoveryLocation; @@ -27,7 +28,6 @@ use Tempest\Http\GenericRequest; use Tempest\Http\Method; use Tempest\Http\Request; -use Tempest\Database\DatabaseInitializer; use Tempest\Mail\Testing\MailTester; use Tempest\Mail\Testing\TestingMailer; use Tempest\Process\Testing\ProcessTester; diff --git a/tests/Integration/Database/MultiDatabaseTest.php b/tests/Integration/Database/MultiDatabaseTest.php index d0fa357b99..ed971bc816 100644 --- a/tests/Integration/Database/MultiDatabaseTest.php +++ b/tests/Integration/Database/MultiDatabaseTest.php @@ -25,6 +25,7 @@ use Tests\Tempest\Fixtures\Modules\Books\Models\Book; use Tests\Tempest\Fixtures\Modules\Books\Models\Publisher; use Tests\Tempest\Integration\FrameworkIntegrationTestCase; + use function Tempest\Database\query; /** diff --git a/tests/Integration/FrameworkIntegrationTestCase.php b/tests/Integration/FrameworkIntegrationTestCase.php index 5d67ab349a..ed697c4a26 100644 --- a/tests/Integration/FrameworkIntegrationTestCase.php +++ b/tests/Integration/FrameworkIntegrationTestCase.php @@ -12,6 +12,7 @@ use Tempest\Framework\Testing\TestingDatabaseInitializer; use Tempest\Support\Filesystem; use Tempest\Support\Path; + use function Tempest\Support\str; abstract class FrameworkIntegrationTestCase extends IntegrationTest