From 20d3669d12f4030410f2d64c3cf29a32bcd7c77e Mon Sep 17 00:00:00 2001 From: Enzo Innocenzi Date: Wed, 31 Dec 2025 01:33:44 +0100 Subject: [PATCH 1/2] feat(testing): remove deprecated testing utilities --- docs/1-essentials/07-testing.md | 131 +++++++----------- .../Framework/Testing/IntegrationTest.php | 70 +++++----- .../CurrentAuthenticatableTest.php | 2 +- .../DatabaseAuthenticatableResolverTest.php | 4 +- .../SessionAuthenticatorTest.php | 2 +- .../Builder/CountQueryBuilderTest.php | 2 +- .../Database/Builder/CustomPrimaryKeyTest.php | 6 +- .../Builder/DeleteQueryBuilderTest.php | 2 +- .../Builder/InsertQueryBuilderTest.php | 4 +- .../Database/Builder/InsertRelationsTest.php | 24 ++-- .../Database/Builder/IsDatabaseModelTest.php | 52 +++---- .../Database/Builder/QueryBuilderTest.php | 42 +++--- .../Builder/SelectQueryBuilderTest.php | 26 ++-- .../Builder/UpdateQueryBuilderTest.php | 2 +- .../Database/Builder/UpdateRelationsTest.php | 26 ++-- .../Database/CircularEagerLoadingTest.php | 2 +- .../ConvenientDateWhereMethodsTest.php | 2 +- .../Database/ConvenientWhereMethodsTest.php | 2 +- ...ustomPrimaryKeyRelationshipLoadingTest.php | 14 +- .../Database/EncryptedAttributeTest.php | 10 +- .../Database/GenericDatabaseTest.php | 6 +- .../GenericTransactionManagerTest.php | 6 +- .../Database/HashedAttributeTest.php | 8 +- .../ModelInspector/ModelWithDtoTest.php | 2 +- .../Database/ModelsWithoutIdTest.php | 14 +- .../AlterTableStatementTest.php | 4 +- .../BelongsToStatementTest.php | 4 +- .../CreateTableStatementTest.php | 24 ++-- tests/Integration/Database/QueryTest.php | 2 +- .../Integration/Database/RefreshModelTest.php | 4 +- tests/Integration/Database/ToRawSqlTest.php | 4 +- .../Commands/DatabaseSeedCommandTest.php | 8 +- .../Http/ValidationResponseTest.php | 4 +- tests/Integration/Route/RequestTest.php | 4 +- tests/Integration/Route/RouterTest.php | 2 +- .../Integration/Validator/ExistsRuleTest.php | 2 +- 36 files changed, 244 insertions(+), 279 deletions(-) diff --git a/docs/1-essentials/07-testing.md b/docs/1-essentials/07-testing.md index 16f9261994..f00c4b483c 100644 --- a/docs/1-essentials/07-testing.md +++ b/docs/1-essentials/07-testing.md @@ -6,90 +6,52 @@ keywords: ["phpunit", "pest"] ## Overview -Tempest uses [PHPUnit](https://phpunit.de) for testing and provides an integration through the [`Tempest\Framework\Testing\IntegrationTest`](https://github.com/tempestphp/tempest-framework/blob/main/src/Tempest/Framework/Testing/IntegrationTest.php) test case. This class boots the framework with configuration suitable for testing, and provides access to multiple utilities. +Tempest uses [PHPUnit](https://phpunit.de) for testing and provides an integration through the [`IntegrationTest`](https://github.com/tempestphp/tempest-framework/blob/main/src/Tempest/Framework/Testing/IntegrationTest.php) test case. This class boots the framework with configuration suitable for testing, and provides access to multiple utilities. Testing utilities specific to components are documented in their respective chapters. For instance, testing the router is described in the [routing documentation](./01-routing.md#testing). ## Running tests -Any test class that wants to interact with Tempest should extend from [`IntegrationTest`](https://github.com/tempestphp/tempest-framework/blob/main/src/Tempest/Framework/Testing/IntegrationTest.php). Next, any test class should end with the suffix `Test`. +Any test class that needs to interact with Tempest must extend [`IntegrationTest`](https://github.com/tempestphp/tempest-framework/blob/main/src/Tempest/Framework/Testing/IntegrationTest.php). -Running the test suite is done by running `composer phpunit`. +By default, Tempest ships with a `phpunit.xml` file that configures PHPUnit to find test files in the `tests` directory. You may run tests using the following command: ```sh -composer phpunit -``` - -## Test-specific discovery locations - -Tempest will only discover non-dev namespaces defined in composer.json automatically. That means that `{:hl-keyword:require-dev:}` namespaces aren't discovered automatically. Whenever you need Tempest to discover test-specific locations, you may specify them within the `discoverTestLocations()` method of the provided `IntegrationTest` class. - -On top of that, Tempest _will_ look for files in the `tests/Fixtures` directory and discover them by default. You can override this behavior by providing your own implementation of `discoverTestLocations()`, where you can return an array of `DiscoveryLocation` objects (or nothing). - -```php tests/HomeControllerTest.php -use Tempest\Core\DiscoveryLocation; -use Tempest\Framework\Testing\IntegrationTest; - -final class HomeControllerTest extends IntegrationTest -{ - protected function discoverTestLocations(): array - { - return [ - new DiscoveryLocation('Tests\\OtherFixtures', __DIR__ . '/OtherFixtures'), - ]; - } -} +./vendor/bin/phpunit ``` ## Using the database -If you want to test code that interacts with the database, your test class can call the `setupDatabase()` method. This method will create and migrate a clean database for you on the fly. +By default, tests don't interact with the database. You may manually set up the database for testing in test files by using the `setup()` method on the `database` testing utility. -```php -final class TodoControllerTest extends IntegrationTest +```php tests/ShowAircraftControllerTest.php +final class ShowAircraftControllerTest extends IntegrationTest { - protected function setUp(): void + #[PreCondition] + protected function configure(): void { - parent::setUp(); - - $this->setupDatabase(); + $this->database->setup(); } } ``` -Most likely, you'll want to use a test-specific database connection. You can create a `database.config.php` file anywhere within test-specific discovery locations, and Tempest will use that connection instead of the project's default. For example, you can create a file `tests/Fixtures/database.config.php` like so: +:::info +The [`PreCondition`](https://docs.phpunit.de/en/12.5/attributes.html#precondition) attribute instructs PHPUnit to run the associated method after the `setUp()` method. We recommend using it instead of overriding `setUp()` directly. +::: -```php tests/Fixtures/database.config.php -use Tempest\Database\Config\SQLiteConfig; +### Runnig migrations -return new SQLiteConfig( - path: __DIR__ . '/database-testing.sqlite' -); -``` - -By default, no tables will be migrated. You can choose to provide a list of migrations that will be run for every test that calls `setupDatabase()`, or you can run specific migrations on a per-test basis. - -```php -final class TodoControllerTest extends IntegrationTest -{ - protected function migrateDatabase(): void - { - $this->migrate( - CreateMigrationsTable::class, - CreateTodosTable::class, - ); - } -} -``` +By default, all migrations are run when setting up the database. However, you may choose to run only specific migrations by using the `migrate()` method instead of `setup()`. -```php -final class TodoControllerTest extends IntegrationTest +```php tests/ShowAircraftControllerTest.php +final class ShowAircraftControllerTest extends IntegrationTest { - public function test_create_todo(): void + #[Test] + public function shows_aircraft(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, - CreateTodosTable::class, + CreateAircraftTable::class, ); // … @@ -97,34 +59,20 @@ final class TodoControllerTest extends IntegrationTest } ``` -## Tester utilities - -The `IntegrationTest` provides several utilities to make testing easier. You can read the details about each tester utility on the documentation page of its respective component. For example, there's the [http tester](../1-essentials/01-routing.md#testing) that helps you test HTTP requests: +### Using a dedicated testing database -```php -$this->http - ->get('/account/profile') - ->assertOk() - ->assertSee('My Profile'); -``` +To ensure your tests run in isolation and do not affect your main database, you may configure a dedicated test database connection. -There's the [console tester](../1-essentials/04-console-commands.md#testing): +To do so, create a `database.testing.config.php` file anywhere—Tempest will [use it](./06-configuration.md#per-environment-configuration) to override the default database settings. -```php tests/ExportUsersCommandTest.php -$this->console - ->call(ExportUsersCommand::class) - ->assertSuccess() - ->assertSee('12 users exported'); +```php tests/database.testing.config.php +use Tempest\Database\Config\SQLiteConfig; -$this->console - ->call(WipeDatabaseCommand::class) - ->assertSee('caution') - ->submit() - ->assertSuccess(); +return new SQLiteConfig( + path: __DIR__ . '/testing.sqlite' +); ``` -And many, many more. - ## Spoofing the environment By default, Tempest provides a `phpunit.xml` that sets the `ENVIRONMENT` variable to `testing`. This is needed so that Tempest can adapt its boot process and load the proper configuration files for the testing environment. @@ -152,6 +100,27 @@ For instance, you may colocate test files and their corresponding class by chang ``` +## Discovering test-specific fixtures + +Non-test files created in the `tests` directory are automatically discovered by Tempest when running the test suite. + +You can override this behavior by providing your own implementation of `discoverTestLocations()`: + +```php tests/Aircraft/ShowAircraftControllerTest.php +use Tempest\Core\DiscoveryLocation; +use Tempest\Framework\Testing\IntegrationTest; + +final class ShowAircraftControllerTest extends IntegrationTest +{ + protected function discoverTestLocations(): array + { + return [ + new DiscoveryLocation('Tests\\Aircraft', __DIR__ . '/Aircraft'), + ]; + } +} +``` + ## Using Pest as a test runner [Pest](https://pestphp.com/) is a test runner built on top of PHPUnit. It provides a functional way of writing tests similar to JavaScript testing frameworks like [Vitest](https://vitest.dev/), and features an elegant console reporter. diff --git a/src/Tempest/Framework/Testing/IntegrationTest.php b/src/Tempest/Framework/Testing/IntegrationTest.php index fb085ac682..03b90e8ca0 100644 --- a/src/Tempest/Framework/Testing/IntegrationTest.php +++ b/src/Tempest/Framework/Testing/IntegrationTest.php @@ -19,8 +19,6 @@ use Tempest\Core\ExceptionTester; use Tempest\Core\FrameworkKernel; use Tempest\Core\Kernel; -use Tempest\Database\Migrations\CreateMigrationsTable; -use Tempest\Database\Migrations\MigrationManager; use Tempest\Database\Testing\DatabaseTester; use Tempest\DateTime\DateTimeInterface; use Tempest\Discovery\DiscoveryLocation; @@ -57,26 +55,59 @@ abstract class IntegrationTest extends TestCase protected ConsoleTester $console; + /** + * Provides utilities for testing HTTP routes. + */ protected HttpRouterTester $http; + /** + * Provides utilities for testing installers. + */ protected InstallerTester $installer; + /** + * Provides utilities for testing the Vite integration. + */ protected ViteTester $vite; + /** + * Provides utilities for testing the event bus. + */ protected EventBusTester $eventBus; + /** + * Provides utilities for testing storage management. + */ protected StorageTester $storage; + /** + * Provides utilities for testing emails. + */ protected MailTester $mailer; + /** + * Provides utilities for testing the cache. + */ protected CacheTester $cache; + /** + * Provides utilities for testing exception reporting. + */ protected ExceptionTester $exceptions; + /** + * Provides utilities for testing process execution. + */ protected ProcessTester $process; + /** + * Provides utilities for testing OAuth flows. + */ protected OAuthTester $oauth; + /** + * Provides utilities for testing the database. + */ protected DatabaseTester $database; protected function setUp(): void @@ -170,41 +201,6 @@ protected function setupBaseRequest(): self return $this; } - /** - * Cleans up the database and migrates the migrations using `migrateDatabase`. - * - * @deprecated Use `$this->database->setup()` instead. - */ - protected function setupDatabase(): self - { - $migrationManager = $this->container->get(MigrationManager::class); - $migrationManager->dropAll(); - - $this->migrateDatabase(); - - return $this; - } - - /** - * Creates the migration table. You may override this method to provide more migrations to run for every tests in this file. - * - * @deprecated Use `$this->database->migrate()` instead. - */ - protected function migrateDatabase(): void - { - $this->migrate(CreateMigrationsTable::class); - } - - /** - * Migrates the specified migration classes. - * - * @deprecated Use `$this->database->migrate()` instead. - */ - protected function migrate(string|object ...$migrationClasses): void - { - $this->database->migrate(...$migrationClasses); - } - protected function clock(DateTimeInterface|string $now = 'now'): MockClock { $clock = new MockClock($now); diff --git a/tests/Integration/Auth/Authentication/CurrentAuthenticatableTest.php b/tests/Integration/Auth/Authentication/CurrentAuthenticatableTest.php index e3c4f6663b..4a97b6bf78 100644 --- a/tests/Integration/Auth/Authentication/CurrentAuthenticatableTest.php +++ b/tests/Integration/Auth/Authentication/CurrentAuthenticatableTest.php @@ -22,7 +22,7 @@ final class CurrentAuthenticatableTest extends FrameworkIntegrationTestCase #[PreCondition] protected function configure(): void { - $this->migrate(CreateMigrationsTable::class, CreateServiceAccountTableMigration::class); + $this->database->migrate(CreateMigrationsTable::class, CreateServiceAccountTableMigration::class); $this->container->config(new AuthConfig(authenticatables: [ServiceAccount::class])); } diff --git a/tests/Integration/Auth/Authentication/DatabaseAuthenticatableResolverTest.php b/tests/Integration/Auth/Authentication/DatabaseAuthenticatableResolverTest.php index 6cbe4d880e..f11ecea7c5 100644 --- a/tests/Integration/Auth/Authentication/DatabaseAuthenticatableResolverTest.php +++ b/tests/Integration/Auth/Authentication/DatabaseAuthenticatableResolverTest.php @@ -21,7 +21,7 @@ final class DatabaseAuthenticatableResolverTest extends FrameworkIntegrationTest #[Test] public function can_resolve_custom_authenticatable_class(): void { - $this->migrate(CreateMigrationsTable::class, CreateApiTokensTableMigration::class); + $this->database->migrate(CreateMigrationsTable::class, CreateApiTokensTableMigration::class); $this->container->config(new AuthConfig(authenticatables: [ApiToken::class])); @@ -37,7 +37,7 @@ public function can_resolve_custom_authenticatable_class(): void #[Test] public function can_resolve_id_from_custom_authenticatable_class(): void { - $this->migrate(CreateMigrationsTable::class, CreateApiTokensTableMigration::class); + $this->database->migrate(CreateMigrationsTable::class, CreateApiTokensTableMigration::class); $this->container->config(new AuthConfig(authenticatables: [ApiToken::class])); diff --git a/tests/Integration/Auth/Authentication/SessionAuthenticatorTest.php b/tests/Integration/Auth/Authentication/SessionAuthenticatorTest.php index eaae6fc5f3..e20251574e 100644 --- a/tests/Integration/Auth/Authentication/SessionAuthenticatorTest.php +++ b/tests/Integration/Auth/Authentication/SessionAuthenticatorTest.php @@ -50,7 +50,7 @@ protected function configure(): void $this->container->get(SessionConfig::class), )); - $this->migrate(CreateMigrationsTable::class, CreateUsersTableMigration::class, CreateApiKeysTableMigration::class); + $this->database->migrate(CreateMigrationsTable::class, CreateUsersTableMigration::class, CreateApiKeysTableMigration::class); } #[PostCondition] diff --git a/tests/Integration/Database/Builder/CountQueryBuilderTest.php b/tests/Integration/Database/Builder/CountQueryBuilderTest.php index d9179bfd36..f580585ef6 100644 --- a/tests/Integration/Database/Builder/CountQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/CountQueryBuilderTest.php @@ -138,7 +138,7 @@ public function test_count_query_with_conditions(): void public function test_count(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); query('authors') ->insert( diff --git a/tests/Integration/Database/Builder/CustomPrimaryKeyTest.php b/tests/Integration/Database/Builder/CustomPrimaryKeyTest.php index 8433d3aedb..bcee1f9161 100644 --- a/tests/Integration/Database/Builder/CustomPrimaryKeyTest.php +++ b/tests/Integration/Database/Builder/CustomPrimaryKeyTest.php @@ -15,7 +15,7 @@ final class CustomPrimaryKeyTest extends FrameworkIntegrationTestCase { public function test_model_with_custom_primary_key_name(): void { - $this->migrate(CreateMigrationsTable::class, CreateCustomPrimaryKeyUserModelTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreateCustomPrimaryKeyUserModelTable::class); $frieren = query(CustomPrimaryKeyUserModel::class)->create(name: 'Frieren', magic: 'Time Magic'); @@ -32,7 +32,7 @@ public function test_model_with_custom_primary_key_name(): void public function test_update_or_create_with_custom_primary_key(): void { - $this->migrate(CreateMigrationsTable::class, CreateCustomPrimaryKeyUserModelTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreateCustomPrimaryKeyUserModelTable::class); $frieren = query(CustomPrimaryKeyUserModel::class)->create(name: 'Frieren', magic: 'Time Magic'); @@ -47,7 +47,7 @@ public function test_update_or_create_with_custom_primary_key(): void public function test_model_without_id_property_still_works(): void { - $this->migrate(CreateMigrationsTable::class, CreateModelWithoutIdMigration::class); + $this->database->migrate(CreateMigrationsTable::class, CreateModelWithoutIdMigration::class); $model = query(ModelWithoutId::class)->new(name: 'Test'); $this->assertInstanceOf(ModelWithoutId::class, $model); diff --git a/tests/Integration/Database/Builder/DeleteQueryBuilderTest.php b/tests/Integration/Database/Builder/DeleteQueryBuilderTest.php index 0c6e32631f..74fb24eb45 100644 --- a/tests/Integration/Database/Builder/DeleteQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/DeleteQueryBuilderTest.php @@ -93,7 +93,7 @@ public function test_delete_on_plain_table_with_conditions(): void public function test_delete_with_non_object_model(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); query('authors') ->insert( diff --git a/tests/Integration/Database/Builder/InsertQueryBuilderTest.php b/tests/Integration/Database/Builder/InsertQueryBuilderTest.php index 8de47409e5..0fe939733a 100644 --- a/tests/Integration/Database/Builder/InsertQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/InsertQueryBuilderTest.php @@ -129,7 +129,7 @@ public function test_insert_on_model_table_with_existing_relation(): void public function test_then_method(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); $id = query(Book::class) ->insert(title: 'Timeline Taxi') @@ -154,7 +154,7 @@ public function test_then_method(): void public function test_insert_with_non_object_model(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); query('authors') ->insert( diff --git a/tests/Integration/Database/Builder/InsertRelationsTest.php b/tests/Integration/Database/Builder/InsertRelationsTest.php index 97d4012f61..0f6c6c0920 100644 --- a/tests/Integration/Database/Builder/InsertRelationsTest.php +++ b/tests/Integration/Database/Builder/InsertRelationsTest.php @@ -28,7 +28,7 @@ final class InsertRelationsTest extends FrameworkIntegrationTestCase { public function test_inserting_has_many_with_arrays(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); $id = query(Book::class) ->insert( @@ -50,7 +50,7 @@ public function test_inserting_has_many_with_arrays(): void public function test_inserting_has_one_with_array(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -75,7 +75,7 @@ public function test_inserting_has_one_with_array(): void public function test_inserting_has_many_with_objects(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); $id = query(Book::class) ->insert( @@ -97,7 +97,7 @@ public function test_inserting_has_many_with_objects(): void public function test_inserting_has_one_with_object(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -122,7 +122,7 @@ public function test_inserting_has_one_with_object(): void public function test_inserting_mixed_relations(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -154,7 +154,7 @@ public function test_inserting_mixed_relations(): void public function test_inserting_empty_has_many_relation(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); $id = query(Book::class) ->insert(title: 'Empty Book', chapters: []) @@ -170,7 +170,7 @@ public function test_inserting_empty_has_many_relation(): void public function test_inserting_large_batch_has_many(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); $chapters = []; for ($i = 1; $i <= 10; $i++) { @@ -191,7 +191,7 @@ public function test_inserting_large_batch_has_many(): void public function test_inserting_has_many_preserves_additional_data(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); $id = query(Book::class) ->insert( @@ -233,7 +233,7 @@ public function test_inserting_has_one_with_invalid_type_throws_exception(): voi public function test_relation_insertion_with_mixed_types(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); $id = query(Book::class) ->insert( @@ -257,7 +257,7 @@ public function test_relation_insertion_with_mixed_types(): void public function test_insertion_with_custom_primary_key_names(): void { - $this->migrate(CreateMigrationsTable::class, CreateMageTable::class, CreateSpellTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreateMageTable::class, CreateSpellTable::class); $id = query(Mage::class) ->insert( @@ -285,7 +285,7 @@ public function test_insertion_with_custom_primary_key_names(): void public function test_insertion_with_non_standard_relation_names(): void { - $this->migrate(CreateMigrationsTable::class, CreatePartyTable::class, CreateAdventurerTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePartyTable::class, CreateAdventurerTable::class); $id = query(Party::class) ->insert( @@ -319,7 +319,7 @@ public function test_insertion_with_non_standard_relation_names(): void public function test_insertion_with_custom_foreign_key_names(): void { - $this->migrate(CreateMigrationsTable::class, CreateMageTable::class, CreateSpellTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreateMageTable::class, CreateSpellTable::class); $spellId = query(Spell::class) ->insert( diff --git a/tests/Integration/Database/Builder/IsDatabaseModelTest.php b/tests/Integration/Database/Builder/IsDatabaseModelTest.php index d2c4cc4c98..8086c3364d 100644 --- a/tests/Integration/Database/Builder/IsDatabaseModelTest.php +++ b/tests/Integration/Database/Builder/IsDatabaseModelTest.php @@ -60,7 +60,7 @@ final class IsDatabaseModelTest extends FrameworkIntegrationTestCase { public function test_create_and_update_model(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, FooDatabaseMigration::class, ); @@ -88,7 +88,7 @@ public function test_create_and_update_model(): void public function test_get_with_non_id_object(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, FooDatabaseMigration::class, ); @@ -104,7 +104,7 @@ public function test_get_with_non_id_object(): void public function test_creating_many_and_saving_preserves_model_id(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, FooDatabaseMigration::class, ); @@ -123,7 +123,7 @@ public function test_creating_many_and_saving_preserves_model_id(): void public function test_complex_query(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -152,7 +152,7 @@ public function test_complex_query(): void public function test_all_with_relations(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -185,7 +185,7 @@ public function test_all_with_relations(): void public function test_missing_relation_exception(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreateATable::class, CreateBTable::class, @@ -216,7 +216,7 @@ public function test_missing_value_exception(): void public function test_nested_relations(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreateATable::class, CreateBTable::class, @@ -238,7 +238,7 @@ public function test_nested_relations(): void public function test_load_belongs_to(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreateATable::class, CreateBTable::class, @@ -261,7 +261,7 @@ public function test_load_belongs_to(): void public function test_has_many_relations(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -290,7 +290,7 @@ public function test_has_many_relations(): void public function test_has_many_through_relation(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreateHasManyParentTable::class, CreateHasManyChildTable::class, @@ -313,7 +313,7 @@ public function test_has_many_through_relation(): void public function test_empty_has_many_relation(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -329,7 +329,7 @@ public function test_empty_has_many_relation(): void public function test_has_one_relation(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -349,7 +349,7 @@ public function test_has_one_relation(): void public function test_invalid_has_one_relation(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreateHasManyParentTable::class, CreateHasManyChildTable::class, @@ -372,7 +372,7 @@ public function test_invalid_has_one_relation(): void public function test_lazy_load(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreateATable::class, CreateBTable::class, @@ -397,7 +397,7 @@ public function test_lazy_load(): void public function test_eager_load(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreateATable::class, CreateBTable::class, @@ -417,7 +417,7 @@ public function test_eager_load(): void public function test_no_result(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreateATable::class, CreateBTable::class, @@ -468,7 +468,7 @@ public function test_virtual_hooked_property(): void public function test_select_virtual_property(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreateATable::class, CreateBTable::class, @@ -488,7 +488,7 @@ public function test_select_virtual_property(): void public function test_update_with_virtual_property(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreateATable::class, CreateBTable::class, @@ -518,7 +518,7 @@ public function test_update_with_virtual_property(): void public function test_update_or_create(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -565,7 +565,7 @@ public function test_update_or_create_uses_initial_data_to_create(): void public function test_delete(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, FooDatabaseMigration::class, ); @@ -586,7 +586,7 @@ public function test_delete(): void public function test_delete_via_model_class_with_where_conditions(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, FooDatabaseMigration::class, ); @@ -607,7 +607,7 @@ public function test_delete_via_model_class_with_where_conditions(): void public function test_delete_via_model_instance_with_primary_key(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, FooDatabaseMigration::class, ); @@ -623,7 +623,7 @@ public function test_delete_via_model_instance_with_primary_key(): void public function test_delete_with_uninitialized_primary_key(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, FooDatabaseMigration::class, ); @@ -637,7 +637,7 @@ public function test_delete_with_uninitialized_primary_key(): void public function test_delete_nonexistent_record(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, FooDatabaseMigration::class, ); @@ -656,7 +656,7 @@ public function test_delete_nonexistent_record(): void public function test_nullable_relations(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreateBNullableTable::class, CreateANullableTable::class, @@ -673,7 +673,7 @@ public function test_nullable_relations(): void public function test_nullable_relation_save(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreateBNullableTable::class, CreateANullableTable::class, diff --git a/tests/Integration/Database/Builder/QueryBuilderTest.php b/tests/Integration/Database/Builder/QueryBuilderTest.php index 3be600ed12..dc47f6818d 100644 --- a/tests/Integration/Database/Builder/QueryBuilderTest.php +++ b/tests/Integration/Database/Builder/QueryBuilderTest.php @@ -18,7 +18,7 @@ final class QueryBuilderTest extends FrameworkIntegrationTestCase { public function test_select(): void { - $this->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class, TestModelWithoutIdMigration::class); + $this->database->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class, TestModelWithoutIdMigration::class); query(TestUserModel::class)->create(name: 'Frieren'); query(TestUserModel::class)->create(name: 'Fern'); @@ -53,7 +53,7 @@ public function test_select(): void public function test_insert(): void { - $this->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class, TestModelWithoutIdMigration::class); + $this->database->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class, TestModelWithoutIdMigration::class); $builderWithId = query(TestUserModel::class)->insert(name: 'Frieren'); $builderWithoutId = query(TestUserModelWithoutId::class)->insert(name: 'Stark'); @@ -77,7 +77,7 @@ public function test_insert(): void public function test_update(): void { - $this->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class, TestModelWithoutIdMigration::class); + $this->database->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class, TestModelWithoutIdMigration::class); $createdWithId = query(TestUserModel::class)->create(name: 'Frieren'); query(TestUserModelWithoutId::class)->create(name: 'Stark'); @@ -102,7 +102,7 @@ public function test_update(): void public function test_delete(): void { - $this->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class, TestModelWithoutIdMigration::class); + $this->database->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class, TestModelWithoutIdMigration::class); $createdWithId = query(TestUserModel::class)->create(name: 'Frieren'); query(TestUserModel::class)->create(name: 'Fern'); @@ -129,7 +129,7 @@ public function test_delete(): void public function test_count(): void { - $this->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class, TestModelWithoutIdMigration::class); + $this->database->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class, TestModelWithoutIdMigration::class); query(TestUserModel::class)->create(name: 'Frieren'); query(TestUserModel::class)->create(name: 'Fern'); @@ -170,7 +170,7 @@ public function test_new(): void public function test_get_with_id_query(): void { - $this->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class); + $this->database->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class); $created = query(TestUserModel::class)->create(name: 'Himmel'); $retrieved = query(TestUserModel::class)->get($created->id); @@ -182,7 +182,7 @@ public function test_get_with_id_query(): void public function test_get_throws_for_model_without_id(): void { - $this->migrate(CreateMigrationsTable::class, TestModelWithoutIdMigration::class); + $this->database->migrate(CreateMigrationsTable::class, TestModelWithoutIdMigration::class); $this->expectException(ModelDidNotHavePrimaryColumn::class); $this->expectExceptionMessage( @@ -194,7 +194,7 @@ public function test_get_throws_for_model_without_id(): void public function test_all(): void { - $this->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class, TestModelWithoutIdMigration::class); + $this->database->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class, TestModelWithoutIdMigration::class); query(TestUserModel::class)->create(name: 'Fern'); query(TestUserModel::class)->create(name: 'Stark'); @@ -216,7 +216,7 @@ public function test_all(): void public function test_find(): void { - $this->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class, TestModelWithoutIdMigration::class); + $this->database->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class, TestModelWithoutIdMigration::class); query(TestUserModel::class)->create(name: 'Frieren'); query(TestUserModel::class)->create(name: 'Fern'); @@ -242,7 +242,7 @@ public function test_find(): void public function test_create(): void { - $this->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class, TestModelWithoutIdMigration::class); + $this->database->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class, TestModelWithoutIdMigration::class); $createdWithId = query(TestUserModel::class)->create(name: 'Ubel'); $createdWithoutId = query(TestUserModelWithoutId::class)->create(name: 'Serie'); @@ -257,7 +257,7 @@ public function test_create(): void public function test_find_or_new_finds_existing(): void { - $this->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class, TestModelWithoutIdMigration::class); + $this->database->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class, TestModelWithoutIdMigration::class); $existingWithId = query(TestUserModel::class)->create(name: 'Serie'); $existingWithoutId = query(TestUserModelWithoutId::class)->create(name: 'Macht'); @@ -282,7 +282,7 @@ public function test_find_or_new_finds_existing(): void public function test_find_or_new_creates_new(): void { - $this->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class, TestModelWithoutIdMigration::class); + $this->database->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class, TestModelWithoutIdMigration::class); $resultWithId = query(TestUserModel::class)->findOrNew( find: ['name' => 'NonExistent'], @@ -304,7 +304,7 @@ public function test_find_or_new_creates_new(): void public function test_update_or_create_updates_existing(): void { - $this->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class); + $this->database->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class); $existingWithId = query(TestUserModel::class)->create(name: 'Qual'); @@ -320,7 +320,7 @@ public function test_update_or_create_updates_existing(): void public function test_update_or_create_creates_new(): void { - $this->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class); + $this->database->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class); $resultWithId = query(TestUserModel::class)->updateOrCreate( find: ['name' => 'NonExistent'], @@ -334,7 +334,7 @@ public function test_update_or_create_creates_new(): void public function test_get_with_string_id(): void { - $this->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class); + $this->database->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class); $created = query(TestUserModel::class)->create(name: 'Heiter'); $retrieved = query(TestUserModel::class)->get((string) $created->id->value); @@ -346,7 +346,7 @@ public function test_get_with_string_id(): void public function test_get_with_int_id(): void { - $this->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class); + $this->database->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class); $created = query(TestUserModel::class)->create(name: 'Eisen'); $retrieved = query(TestUserModel::class)->get($created->id->value); @@ -358,7 +358,7 @@ public function test_get_with_int_id(): void public function test_get_returns_null_for_non_existent_id(): void { - $this->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class); + $this->database->migrate(CreateMigrationsTable::class, TestModelWrapperMigration::class); $result = query(TestUserModel::class)->get(new PrimaryKey(999)); @@ -367,7 +367,7 @@ public function test_get_returns_null_for_non_existent_id(): void public function test_find_by_id_throws_for_model_without_id(): void { - $this->migrate(CreateMigrationsTable::class, TestModelWithoutIdMigration::class); + $this->database->migrate(CreateMigrationsTable::class, TestModelWithoutIdMigration::class); $this->expectException(ModelDidNotHavePrimaryColumn::class); $this->expectExceptionMessage( @@ -379,7 +379,7 @@ public function test_find_by_id_throws_for_model_without_id(): void public function test_update_or_create_throws_for_model_without_id(): void { - $this->migrate(CreateMigrationsTable::class, TestModelWithoutIdMigration::class); + $this->database->migrate(CreateMigrationsTable::class, TestModelWithoutIdMigration::class); $this->expectException(ModelDidNotHavePrimaryColumn::class); $this->expectExceptionMessage( @@ -394,7 +394,7 @@ public function test_update_or_create_throws_for_model_without_id(): void public function test_custom_primary_key_name(): void { - $this->migrate(CreateMigrationsTable::class, TestModelWithCustomPrimaryKeyMigration::class); + $this->database->migrate(CreateMigrationsTable::class, TestModelWithCustomPrimaryKeyMigration::class); $created = query(TestUserModelWithCustomPrimaryKey::class)->create(name: 'Fern'); @@ -410,7 +410,7 @@ public function test_custom_primary_key_name(): void public function test_custom_primary_key_update_or_create(): void { - $this->migrate(CreateMigrationsTable::class, TestModelWithCustomPrimaryKeyMigration::class); + $this->database->migrate(CreateMigrationsTable::class, TestModelWithCustomPrimaryKeyMigration::class); $original = query(TestUserModelWithCustomPrimaryKey::class)->create(name: 'Stark'); diff --git a/tests/Integration/Database/Builder/SelectQueryBuilderTest.php b/tests/Integration/Database/Builder/SelectQueryBuilderTest.php index 98f80fbc63..c4d257591d 100644 --- a/tests/Integration/Database/Builder/SelectQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/SelectQueryBuilderTest.php @@ -116,7 +116,7 @@ public function test_multiple_where_field(): void public function test_where_statement(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -135,7 +135,7 @@ public function test_where_statement(): void public function test_join(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -158,7 +158,7 @@ public function test_join(): void public function test_order_by(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -177,7 +177,7 @@ public function test_order_by(): void public function test_order_by_with_field_and_direction(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -198,7 +198,7 @@ public function test_order_by_with_field_and_direction(): void public function test_order_by_with_field_defaults_to_asc(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -216,7 +216,7 @@ public function test_order_by_with_field_defaults_to_asc(): void public function test_order_by_raw_shorthand(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -252,7 +252,7 @@ public function test_order_by_sql_generation(): void public function test_limit(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -273,7 +273,7 @@ public function test_limit(): void public function test_offset(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -297,7 +297,7 @@ public function test_offset(): void public function test_chunk(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -324,7 +324,7 @@ public function test_chunk(): void public function test_chunk_with_relation(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -345,7 +345,7 @@ public function test_chunk_with_relation(): void public function test_raw(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -392,7 +392,7 @@ public function test_select_query_with_conditions(): void public function test_select_first_with_non_object_model(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); query('authors') ->insert( @@ -411,7 +411,7 @@ public function test_select_first_with_non_object_model(): void public function test_select_all_with_non_object_model(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); query('authors') ->insert( diff --git a/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php b/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php index a036473379..0fd8271dbe 100644 --- a/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php @@ -227,7 +227,7 @@ public function test_update_on_plain_table_with_conditions(): void public function test_update_with_non_object_model(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); query('authors') ->insert( diff --git a/tests/Integration/Database/Builder/UpdateRelationsTest.php b/tests/Integration/Database/Builder/UpdateRelationsTest.php index 14ffdd9ec4..8763cba18a 100644 --- a/tests/Integration/Database/Builder/UpdateRelationsTest.php +++ b/tests/Integration/Database/Builder/UpdateRelationsTest.php @@ -28,7 +28,7 @@ final class UpdateRelationsTest extends FrameworkIntegrationTestCase { public function test_updating_has_many_with_arrays(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); $bookId = query(Book::class) ->insert( @@ -63,7 +63,7 @@ public function test_updating_has_many_with_arrays(): void public function test_updating_has_one_with_array(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -96,7 +96,7 @@ public function test_updating_has_one_with_array(): void public function test_updating_has_many_with_objects(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); $bookId = query(Book::class) ->insert( @@ -129,7 +129,7 @@ public function test_updating_has_many_with_objects(): void public function test_updating_has_one_with_object(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -160,7 +160,7 @@ public function test_updating_has_one_with_object(): void public function test_updating_mixed_relations(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -204,7 +204,7 @@ public function test_updating_mixed_relations(): void public function test_updating_empty_has_many_relation(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); $bookId = query(Book::class) ->insert( @@ -234,7 +234,7 @@ public function test_updating_empty_has_many_relation(): void public function test_updating_large_batch_has_many(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); $bookId = query(Book::class) ->insert( @@ -268,7 +268,7 @@ public function test_updating_large_batch_has_many(): void public function test_updating_has_many_preserves_additional_data(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); $bookId = query(Book::class) ->insert( @@ -302,7 +302,7 @@ public function test_updating_has_many_preserves_additional_data(): void public function test_updating_relation_with_mixed_types(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, CreateBookTable::class, CreateChapterTable::class); $bookId = query(Book::class) ->insert( @@ -336,7 +336,7 @@ public function test_updating_relation_with_mixed_types(): void public function test_updating_with_custom_primary_key_names(): void { - $this->migrate(CreateMigrationsTable::class, CreateUpdateMageTable::class, CreateUpdateSpellTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreateUpdateMageTable::class, CreateUpdateSpellTable::class); $mageId = query(UpdateMage::class) ->insert( @@ -375,7 +375,7 @@ public function test_updating_with_custom_primary_key_names(): void public function test_updating_with_non_standard_relation_names(): void { - $this->migrate(CreateMigrationsTable::class, CreateUpdatePartyTable::class, CreateUpdateAdventurerTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreateUpdatePartyTable::class, CreateUpdateAdventurerTable::class); $partyId = query(UpdateParty::class) ->insert( @@ -421,7 +421,7 @@ public function test_updating_with_non_standard_relation_names(): void public function test_updating_with_custom_foreign_key_names(): void { - $this->migrate(CreateMigrationsTable::class, CreateUpdateMageTable::class, CreateUpdateSpellTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreateUpdateMageTable::class, CreateUpdateSpellTable::class); $spellId = query(UpdateSpell::class) ->insert( @@ -457,7 +457,7 @@ public function test_updating_with_custom_foreign_key_names(): void public function test_update_throws_exception_when_model_has_no_primary_key(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, diff --git a/tests/Integration/Database/CircularEagerLoadingTest.php b/tests/Integration/Database/CircularEagerLoadingTest.php index 5f1e0a0cdc..2dfaa3e407 100644 --- a/tests/Integration/Database/CircularEagerLoadingTest.php +++ b/tests/Integration/Database/CircularEagerLoadingTest.php @@ -41,7 +41,7 @@ public function test_circular_with_relations_does_not_cause_infinite_loop(): voi public function test_it_saves_and_loads_relations_without_causing_infinite_loop(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreateUserWithEagerTable::class, CreateProfileWithEagerTable::class, diff --git a/tests/Integration/Database/ConvenientDateWhereMethodsTest.php b/tests/Integration/Database/ConvenientDateWhereMethodsTest.php index 49b4ae1036..1f646c6d06 100644 --- a/tests/Integration/Database/ConvenientDateWhereMethodsTest.php +++ b/tests/Integration/Database/ConvenientDateWhereMethodsTest.php @@ -28,7 +28,7 @@ protected function setUp(): void $this->clock = $this->clock('2025-08-02 12:00:00'); - $this->migrate(CreateMigrationsTable::class, CreateEventTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreateEventTable::class); $this->seedTestData(); } diff --git a/tests/Integration/Database/ConvenientWhereMethodsTest.php b/tests/Integration/Database/ConvenientWhereMethodsTest.php index cd248a9d52..c64f156bb7 100644 --- a/tests/Integration/Database/ConvenientWhereMethodsTest.php +++ b/tests/Integration/Database/ConvenientWhereMethodsTest.php @@ -24,7 +24,7 @@ protected function setUp(): void { parent::setUp(); - $this->migrate(CreateMigrationsTable::class, CreateUserTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreateUserTable::class); $this->seedTestData(); } diff --git a/tests/Integration/Database/CustomPrimaryKeyRelationshipLoadingTest.php b/tests/Integration/Database/CustomPrimaryKeyRelationshipLoadingTest.php index 80d13db31d..4e9cc58ccf 100644 --- a/tests/Integration/Database/CustomPrimaryKeyRelationshipLoadingTest.php +++ b/tests/Integration/Database/CustomPrimaryKeyRelationshipLoadingTest.php @@ -25,7 +25,7 @@ final class CustomPrimaryKeyRelationshipLoadingTest extends FrameworkIntegration { public function test_has_one_relationship_with_uuid_primary_keys(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreateMageWithUuidMigration::class, CreateGrimoireWithUuidMigration::class, @@ -57,7 +57,7 @@ public function test_has_one_relationship_with_uuid_primary_keys(): void public function test_has_many_relationship_with_uuid_primary_keys(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreateMageWithUuidMigration::class, CreateSpellWithUuidMigration::class, @@ -100,7 +100,7 @@ public function test_has_many_relationship_with_uuid_primary_keys(): void public function test_belongs_to_relationship_with_uuid_primary_keys(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreateMageWithUuidMigration::class, CreateSpellWithUuidMigration::class, @@ -129,7 +129,7 @@ public function test_belongs_to_relationship_with_uuid_primary_keys(): void public function test_nested_relationship_loading_with_uuid_primary_keys(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreateMageWithUuidMigration::class, CreateGrimoireWithUuidMigration::class, @@ -174,7 +174,7 @@ public function test_nested_relationship_loading_with_uuid_primary_keys(): void public function test_relationship_with_custom_foreign_key_naming(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreateMageWithUuidMigration::class, CreateArtifactWithUuidMigration::class, @@ -209,7 +209,7 @@ public function test_relationship_with_custom_foreign_key_naming(): void public function test_relationship_loading_preserves_uuid_integrity(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreateMageWithUuidMigration::class, CreateSpellWithUuidMigration::class, @@ -253,7 +253,7 @@ public function test_relationship_loading_preserves_uuid_integrity(): void public function test_automatic_uuid_primary_key_detection(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreateMageSimpleMigration::class, CreateSpellSimpleMigration::class, diff --git a/tests/Integration/Database/EncryptedAttributeTest.php b/tests/Integration/Database/EncryptedAttributeTest.php index 07df48e120..68e17694d1 100644 --- a/tests/Integration/Database/EncryptedAttributeTest.php +++ b/tests/Integration/Database/EncryptedAttributeTest.php @@ -25,7 +25,7 @@ final class EncryptedAttributeTest extends FrameworkIntegrationTestCase #[Test] public function encrypts_value_on_insert(): void { - $this->migrate(CreateMigrationsTable::class, CreateUserWithEncryptedDataTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreateUserWithEncryptedDataTable::class); $user = query(UserWithEncryptedData::class)->create( email: 'test@example.com', @@ -42,7 +42,7 @@ public function encrypts_value_on_insert(): void #[Test] public function encrypts_value_on_update(): void { - $this->migrate(CreateMigrationsTable::class, CreateUserWithEncryptedDataTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreateUserWithEncryptedDataTable::class); $user = query(UserWithEncryptedData::class)->create( email: 'test@example.com', @@ -62,7 +62,7 @@ public function encrypts_value_on_update(): void #[Test] public function does_not_re_encrypt_already_encrypted_values(): void { - $this->migrate(CreateMigrationsTable::class, CreateUserWithEncryptedDataTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreateUserWithEncryptedDataTable::class); $user = query(UserWithEncryptedData::class)->create( email: 'test@example.com', @@ -75,7 +75,7 @@ public function does_not_re_encrypt_already_encrypted_values(): void #[Test] public function handles_null_values(): void { - $this->migrate(CreateMigrationsTable::class, CreateUserWithNullableEncryptedDataTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreateUserWithNullableEncryptedDataTable::class); $user = query(UserWithNullableEncryptedData::class)->create( email: 'test@example.com', @@ -88,7 +88,7 @@ public function handles_null_values(): void #[Test] public function handles_empty_strings(): void { - $this->migrate(CreateMigrationsTable::class, CreateUserWithEncryptedDataTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreateUserWithEncryptedDataTable::class); $user = query(UserWithEncryptedData::class)->create( email: 'test@example.com', diff --git a/tests/Integration/Database/GenericDatabaseTest.php b/tests/Integration/Database/GenericDatabaseTest.php index 3d27b9f839..a8a2571018 100644 --- a/tests/Integration/Database/GenericDatabaseTest.php +++ b/tests/Integration/Database/GenericDatabaseTest.php @@ -24,7 +24,7 @@ final class GenericDatabaseTest extends FrameworkIntegrationTestCase { public function test_transaction_manager_execute(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); $db = $this->container->get(Database::class); @@ -41,7 +41,7 @@ public function test_transaction_manager_execute(): void public function test_transaction_manager_fails(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); $db = $this->container->get(Database::class); @@ -60,7 +60,7 @@ public function test_transaction_manager_fails(): void public function test_query_with_semicolons(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class); $db = $this->container->get(Database::class); $db->execute( diff --git a/tests/Integration/Database/GenericTransactionManagerTest.php b/tests/Integration/Database/GenericTransactionManagerTest.php index d2d6ad71ad..21022ab439 100644 --- a/tests/Integration/Database/GenericTransactionManagerTest.php +++ b/tests/Integration/Database/GenericTransactionManagerTest.php @@ -19,7 +19,7 @@ final class GenericTransactionManagerTest extends FrameworkIntegrationTestCase { public function test_transaction_manager(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); $manager = $this->container->get(TransactionManager::class); @@ -35,7 +35,7 @@ public function test_transaction_manager(): void public function test_transaction_manager_commit(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); $manager = $this->container->get(TransactionManager::class); @@ -51,7 +51,7 @@ public function test_transaction_manager_commit(): void public function test_transaction_manager_commit_rollback(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); $manager = $this->container->get(TransactionManager::class); diff --git a/tests/Integration/Database/HashedAttributeTest.php b/tests/Integration/Database/HashedAttributeTest.php index d0c37a4821..c0e76986d0 100644 --- a/tests/Integration/Database/HashedAttributeTest.php +++ b/tests/Integration/Database/HashedAttributeTest.php @@ -23,7 +23,7 @@ final class HashedAttributeTest extends FrameworkIntegrationTestCase #[Test] public function hashes_value_on_insert(): void { - $this->migrate(CreateMigrationsTable::class, CreateUserWithHashTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreateUserWithHashTable::class); $user = query(UserWithHash::class)->create( email: 'test@example.com', @@ -43,7 +43,7 @@ public function hashes_value_on_insert(): void #[Test] public function hashes_value_on_update(): void { - $this->migrate(CreateMigrationsTable::class, CreateUserWithHashTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreateUserWithHashTable::class); $user = query(UserWithHash::class) ->create( @@ -66,7 +66,7 @@ public function hashes_value_on_update(): void #[Test] public function does_not_rehash_already_hashed_values(): void { - $this->migrate(CreateMigrationsTable::class, CreateUserWithHashTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreateUserWithHashTable::class); $user = query(UserWithHash::class) ->create( @@ -82,7 +82,7 @@ public function does_not_rehash_already_hashed_values(): void #[Test] public function handles_null_values(): void { - $this->migrate(CreateMigrationsTable::class, CreateUserWithNullablePasswordTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreateUserWithNullablePasswordTable::class); $user = query(UserWithNullablePassword::class) ->create( diff --git a/tests/Integration/Database/ModelInspector/ModelWithDtoTest.php b/tests/Integration/Database/ModelInspector/ModelWithDtoTest.php index 62413a97bc..7e0dc9a2c9 100644 --- a/tests/Integration/Database/ModelInspector/ModelWithDtoTest.php +++ b/tests/Integration/Database/ModelInspector/ModelWithDtoTest.php @@ -36,7 +36,7 @@ public function up(): QueryStatement } }; - $this->migrate(CreateMigrationsTable::class, $migration); + $this->database->migrate(CreateMigrationsTable::class, $migration); ModelWithDtoTestModelWithSerializedDto::new(dto: new ModelWithDtoTestDtoForModelWithSerializer('test'))->save(); diff --git a/tests/Integration/Database/ModelsWithoutIdTest.php b/tests/Integration/Database/ModelsWithoutIdTest.php index 0e9b3426e1..91eccbc7ea 100644 --- a/tests/Integration/Database/ModelsWithoutIdTest.php +++ b/tests/Integration/Database/ModelsWithoutIdTest.php @@ -24,7 +24,7 @@ final class ModelsWithoutIdTest extends FrameworkIntegrationTestCase { public function test_update_model_without_id_with_specific_conditions(): void { - $this->migrate(CreateMigrationsTable::class, CreateLogEntryMigration::class); + $this->database->migrate(CreateMigrationsTable::class, CreateLogEntryMigration::class); query(LogEntry::class)->create( level: 'INFO', @@ -47,7 +47,7 @@ public function test_update_model_without_id_with_specific_conditions(): void public function test_delete_operations_on_models_without_id(): void { - $this->migrate(CreateMigrationsTable::class, CreateLogEntryMigration::class); + $this->database->migrate(CreateMigrationsTable::class, CreateLogEntryMigration::class); query(LogEntry::class)->create( level: 'TEMP', @@ -75,7 +75,7 @@ public function test_delete_operations_on_models_without_id(): void public function test_model_without_id_with_unique_constraints(): void { - $this->migrate(CreateMigrationsTable::class, CreateCacheEntryMigration::class); + $this->database->migrate(CreateMigrationsTable::class, CreateCacheEntryMigration::class); query(CacheEntry::class)->create( cache_key: 'spell_fire', @@ -97,7 +97,7 @@ public function test_model_without_id_with_unique_constraints(): void public function test_relationship_methods_throw_for_models_without_id(): void { - $this->migrate(CreateMigrationsTable::class, CreateLogEntryMigration::class); + $this->database->migrate(CreateMigrationsTable::class, CreateLogEntryMigration::class); $this->expectException(ModelDidNotHavePrimaryColumn::class); $this->expectExceptionMessage('does not have a primary column defined, which is required for the `findById` method'); @@ -107,7 +107,7 @@ public function test_relationship_methods_throw_for_models_without_id(): void public function test_get_method_throws_for_models_without_id(): void { - $this->migrate(CreateMigrationsTable::class, CreateLogEntryMigration::class); + $this->database->migrate(CreateMigrationsTable::class, CreateLogEntryMigration::class); $this->expectException(ModelDidNotHavePrimaryColumn::class); $this->expectExceptionMessage('does not have a primary column defined, which is required for the `get` method'); @@ -117,7 +117,7 @@ public function test_get_method_throws_for_models_without_id(): void public function test_update_or_create_throws_for_models_without_id(): void { - $this->migrate(CreateMigrationsTable::class, CreateLogEntryMigration::class); + $this->database->migrate(CreateMigrationsTable::class, CreateLogEntryMigration::class); $this->expectException(ModelDidNotHavePrimaryColumn::class); $this->expectExceptionMessage('does not have a primary column defined, which is required for the `updateOrCreate` method'); @@ -130,7 +130,7 @@ public function test_update_or_create_throws_for_models_without_id(): void public function test_model_with_mixed_id_and_non_id_properties(): void { - $this->migrate(CreateMigrationsTable::class, CreateMixedModelMigration::class); + $this->database->migrate(CreateMigrationsTable::class, CreateMixedModelMigration::class); $mixed = query(MixedModel::class)->create( regular_field: 'test', diff --git a/tests/Integration/Database/QueryStatements/AlterTableStatementTest.php b/tests/Integration/Database/QueryStatements/AlterTableStatementTest.php index 4babb621a3..4bf52ccad9 100644 --- a/tests/Integration/Database/QueryStatements/AlterTableStatementTest.php +++ b/tests/Integration/Database/QueryStatements/AlterTableStatementTest.php @@ -27,7 +27,7 @@ public function test_it_can_alter_a_table_definition(): void { $migration = $this->getAlterTableMigration(); - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreateUserDatabaseMigration::class, ); @@ -53,7 +53,7 @@ public function test_it_can_alter_a_table_definition(): void $this->assertStringContainsString($message, $queryWasInvalid->getMessage()); } - $this->migrate($migration::class); + $this->database->migrate($migration::class); $this->assertCount(3, MigrationModel::all()); $this->assertSame( diff --git a/tests/Integration/Database/QueryStatements/BelongsToStatementTest.php b/tests/Integration/Database/QueryStatements/BelongsToStatementTest.php index 632454aa6f..07bd924612 100644 --- a/tests/Integration/Database/QueryStatements/BelongsToStatementTest.php +++ b/tests/Integration/Database/QueryStatements/BelongsToStatementTest.php @@ -54,7 +54,7 @@ public function up(): QueryStatement } }; - $this->migrate(CreateMigrationsTable::class, $customersMigration, $belongsToMigration, $foreignKeyMigration); + $this->database->migrate(CreateMigrationsTable::class, $customersMigration, $belongsToMigration, $foreignKeyMigration); $this->expectNotToPerformAssertions(); } @@ -85,7 +85,7 @@ public function up(): QueryStatement } }; - $this->migrate(CreateMigrationsTable::class, $categoriesMigration, $productsMigration); + $this->database->migrate(CreateMigrationsTable::class, $categoriesMigration, $productsMigration); $this->expectNotToPerformAssertions(); } diff --git a/tests/Integration/Database/QueryStatements/CreateTableStatementTest.php b/tests/Integration/Database/QueryStatements/CreateTableStatementTest.php index 8031ae0515..cefccf14af 100644 --- a/tests/Integration/Database/QueryStatements/CreateTableStatementTest.php +++ b/tests/Integration/Database/QueryStatements/CreateTableStatementTest.php @@ -46,7 +46,7 @@ public function up(): QueryStatement } }; - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, $migration, ); @@ -74,7 +74,7 @@ public function up(): QueryStatement DatabaseDialect::POSTGRESQL => $this->expectException(DialectWasNotSupported::class), }; - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, $migration, ); @@ -92,7 +92,7 @@ public function up(): QueryStatement } }; - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, $migration, ); @@ -102,7 +102,7 @@ public function up(): QueryStatement public function test_enum_statement(): void { - $this->migrate(CreateMigrationsTable::class); + $this->database->migrate(CreateMigrationsTable::class); if ($this->container->get(Database::class)->dialect === DatabaseDialect::POSTGRESQL) { $enumTypeMigration = new class() implements MigratesUp { @@ -117,7 +117,7 @@ public function up(): QueryStatement } }; - $this->migrate($enumTypeMigration); + $this->database->migrate($enumTypeMigration); } $tableMigration = new class() implements MigratesUp { @@ -134,7 +134,7 @@ enumClass: CreateTableStatementTestEnumForCreateTable::class, } }; - $this->migrate($tableMigration); + $this->database->migrate($tableMigration); $this->expectNotToPerformAssertions(); } @@ -154,7 +154,7 @@ public function up(): QueryStatement $this->expectException(DefaultValueWasInvalid::class); $this->expectExceptionMessage("Default value '{default: \"invalid json\"}' provided for json is not valid"); - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, $migration, ); @@ -172,7 +172,7 @@ public function up(): QueryStatement } }; - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, $migration, ); @@ -195,7 +195,7 @@ public function up(): QueryStatement $this->expectException(ValueWasInvalid::class); $this->expectExceptionMessage("Value '[]' provided for set is not valid"); - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, $migration, ); @@ -215,7 +215,7 @@ public function up(): QueryStatement } }; - $this->migrate(CreateMigrationsTable::class, $migration); + $this->database->migrate(CreateMigrationsTable::class, $migration); $this->expectNotToPerformAssertions(); } @@ -247,7 +247,7 @@ public function up(): QueryStatement } }; - $this->migrate(CreateMigrationsTable::class, $migration); + $this->database->migrate(CreateMigrationsTable::class, $migration); $this->expectNotToPerformAssertions(); } @@ -264,7 +264,7 @@ public function up(): QueryStatement } }; - $this->migrate(CreateMigrationsTable::class, $migration); + $this->database->migrate(CreateMigrationsTable::class, $migration); $this->expectNotToPerformAssertions(); } diff --git a/tests/Integration/Database/QueryTest.php b/tests/Integration/Database/QueryTest.php index 835c53e078..9bd3b658e5 100644 --- a/tests/Integration/Database/QueryTest.php +++ b/tests/Integration/Database/QueryTest.php @@ -20,7 +20,7 @@ final class QueryTest extends FrameworkIntegrationTestCase { public function test_with_bindings(): void { - $this->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); + $this->database->migrate(CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class); new Author(name: 'A')->save(); new Author(name: 'B')->save(); diff --git a/tests/Integration/Database/RefreshModelTest.php b/tests/Integration/Database/RefreshModelTest.php index 3552c15643..7cae055fc2 100644 --- a/tests/Integration/Database/RefreshModelTest.php +++ b/tests/Integration/Database/RefreshModelTest.php @@ -17,7 +17,7 @@ final class RefreshModelTest extends FrameworkIntegrationTestCase { public function test_refresh_works_for_models_with_unloaded_relation(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -65,7 +65,7 @@ public function test_refresh_works_for_models_with_unloaded_relation(): void public function test_load_method_only_refreshes_relations_and_nothing_else(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, diff --git a/tests/Integration/Database/ToRawSqlTest.php b/tests/Integration/Database/ToRawSqlTest.php index f54cdb9c6b..2b1df09c47 100644 --- a/tests/Integration/Database/ToRawSqlTest.php +++ b/tests/Integration/Database/ToRawSqlTest.php @@ -263,7 +263,7 @@ public function test_raw_sql_with_string_escaping(): void public function test_raw_sql_with_model_queries(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -355,7 +355,7 @@ public function test_raw_sql_handles_array_values_properly(): void public function test_raw_sql_with_enum_values(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, diff --git a/tests/Integration/Framework/Commands/DatabaseSeedCommandTest.php b/tests/Integration/Framework/Commands/DatabaseSeedCommandTest.php index 7e3146c570..cbca648b15 100644 --- a/tests/Integration/Framework/Commands/DatabaseSeedCommandTest.php +++ b/tests/Integration/Framework/Commands/DatabaseSeedCommandTest.php @@ -19,7 +19,7 @@ final class DatabaseSeedCommandTest extends FrameworkIntegrationTestCase { public function test_seed_with_selected_seeder(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -39,7 +39,7 @@ public function test_seed_with_selected_seeder(): void public function test_seed_with_manually_selected_seeder(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -68,7 +68,7 @@ public function test_migrate_fresh_seed_with_manually_selected_seeder(): void public function test_seed_all(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -95,7 +95,7 @@ public function test_seed_when_only_one_seeder_is_available(): void TestDatabaseSeeder::class, ]; - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, diff --git a/tests/Integration/Http/ValidationResponseTest.php b/tests/Integration/Http/ValidationResponseTest.php index 70db37844e..49319a77a3 100644 --- a/tests/Integration/Http/ValidationResponseTest.php +++ b/tests/Integration/Http/ValidationResponseTest.php @@ -53,7 +53,7 @@ public function test_original_values(): void public function test_update_book(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -81,7 +81,7 @@ public function test_update_book(): void public function test_failing_post_request(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, diff --git a/tests/Integration/Route/RequestTest.php b/tests/Integration/Route/RequestTest.php index ea7c0e5085..4c198d670f 100644 --- a/tests/Integration/Route/RequestTest.php +++ b/tests/Integration/Route/RequestTest.php @@ -123,7 +123,7 @@ public function test_generic_request_can_map_to_custom_request(): void public function test_custom_request_test_with_validation(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, @@ -151,7 +151,7 @@ public function test_custom_request_test_with_validation(): void public function test_custom_request_test_with_nested_validation(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, diff --git a/tests/Integration/Route/RouterTest.php b/tests/Integration/Route/RouterTest.php index a4478c43aa..cad82ccffa 100644 --- a/tests/Integration/Route/RouterTest.php +++ b/tests/Integration/Route/RouterTest.php @@ -83,7 +83,7 @@ public function test_with_view(): void public function test_route_binding(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, diff --git a/tests/Integration/Validator/ExistsRuleTest.php b/tests/Integration/Validator/ExistsRuleTest.php index cca2db2a39..c4f328521f 100644 --- a/tests/Integration/Validator/ExistsRuleTest.php +++ b/tests/Integration/Validator/ExistsRuleTest.php @@ -22,7 +22,7 @@ final class ExistsRuleTest extends FrameworkIntegrationTestCase #[PreCondition] protected function configure(): void { - $this->migrate( + $this->database->migrate( CreateMigrationsTable::class, CreatePublishersTable::class, CreateAuthorTable::class, From 06944e4b89be5e38d18ee61e1c98218bb6895042 Mon Sep 17 00:00:00 2001 From: Enzo Innocenzi Date: Wed, 31 Dec 2025 01:53:03 +0100 Subject: [PATCH 2/2] refactor: clean up testing database initialization --- .../FrameworkIntegrationTestCase.php | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/tests/Integration/FrameworkIntegrationTestCase.php b/tests/Integration/FrameworkIntegrationTestCase.php index ee8dfd45fd..61ba1657fb 100644 --- a/tests/Integration/FrameworkIntegrationTestCase.php +++ b/tests/Integration/FrameworkIntegrationTestCase.php @@ -7,7 +7,6 @@ use InvalidArgumentException; use Stringable; use Tempest\Database\DatabaseInitializer; -use Tempest\Database\Migrations\MigrationManager; use Tempest\Discovery\DiscoveryLocation; use Tempest\Framework\Testing\IntegrationTest; use Tempest\Reflection\MethodReflector; @@ -18,6 +17,8 @@ use Tempest\Router\Routing\Construction\RouteConfigurator; use Tempest\Router\Static\StaticPageConfig; use Tempest\Router\StaticPage; +use Tempest\Support\Filesystem; +use Tempest\Support\Path; use Tempest\View\GenericView; use Tempest\View\View; use Tempest\View\ViewComponent; @@ -40,20 +41,19 @@ protected function setUp(): void { parent::setUp(); - // Database $this->container ->removeInitializer(DatabaseInitializer::class) ->addInitializer(TestingDatabaseInitializer::class); - $databaseConfigPath = __DIR__ . '/../Fixtures/Config/database.config.php'; + $defaultDatabaseConfigPath = Path\normalize(__DIR__, '..', 'Fixtures/Config/database.sqlite.php'); + $databaseConfigPath = Path\normalize(__DIR__, '..', 'Fixtures/Config/database.config.php'); - if (! file_exists($databaseConfigPath)) { - copy(__DIR__ . '/../Fixtures/Config/database.sqlite.php', $databaseConfigPath); + if (! Filesystem\exists($databaseConfigPath)) { + Filesystem\copy_file($defaultDatabaseConfigPath, $databaseConfigPath); } $this->container->config(require $databaseConfigPath); - - $this->rollbackDatabase(); + $this->database->reset(migrate: false); } protected function render(string|View $view, mixed ...$params): string @@ -79,13 +79,6 @@ protected function registerViewComponent(string $name, string $html, string $fil $this->container->get(ViewConfig::class)->addViewComponent($viewComponent); } - protected function rollbackDatabase(): void - { - $migrationManager = $this->container->get(MigrationManager::class); - - $migrationManager->dropAll(); - } - protected function assertStringCount(string $subject, string $search, int $count): void { $this->assertSame($count, substr_count($subject, $search));