From c1a79d1844624b030e72a34efaecee3695a999c3 Mon Sep 17 00:00:00 2001 From: Dmitriy Krivopalov Date: Fri, 6 Mar 2026 11:46:58 +0300 Subject: [PATCH 1/2] tests correction and infection fix --- .github/workflows/analysis.yml | 5 +-- .github/workflows/release.yml | 2 +- .github/workflows/tests.yml | 1 + .../202501011024_entity_correction.sql | 0 .../202501011024_entity_correction_2.sql | 0 tests/workflow/ArgumentsTest.php | 15 +++++--- tests/workflow/CommandTest.php | 12 +++++++ tests/workflow/EventTest.php | 20 +++++++++-- tests/workflow/MigrationFailTest.php | 13 +++++++ tests/workflow/MigrationTest.php | 35 +++++++------------ 10 files changed, 68 insertions(+), 35 deletions(-) rename example/migration/sqlite/{memory-repeatable => memory-repeatable2}/202501011024_entity_correction.sql (100%) rename example/migration/sqlite/{memory-repeatable => memory-repeatable2}/202501011024_entity_correction_2.sql (100%) diff --git a/.github/workflows/analysis.yml b/.github/workflows/analysis.yml index d5db411..8f636b6 100644 --- a/.github/workflows/analysis.yml +++ b/.github/workflows/analysis.yml @@ -21,9 +21,6 @@ jobs: with: php-version: ${{ matrix.php-version }} coverage: none - env: - fail-fast: true - COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Install composer dependencies uses: ramsey/composer-install@v3 @@ -35,7 +32,7 @@ jobs: run: vendor/bin/phpcs - name: Psalm - run: vendor/bin/psalm --stats --output-format=github + run: vendor/bin/psalm --stats - name: PHPStan run: vendor/bin/phpstan analyse diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dd76815..6d997ce 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,7 +12,7 @@ jobs: fail-fast: false matrix: php-version: - - "8.3" + - "8.4" steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 95a7217..703dbe5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,6 +13,7 @@ jobs: php-version: - "8.3" - "8.4" + - "8.5" steps: - name: Checkout diff --git a/example/migration/sqlite/memory-repeatable/202501011024_entity_correction.sql b/example/migration/sqlite/memory-repeatable2/202501011024_entity_correction.sql similarity index 100% rename from example/migration/sqlite/memory-repeatable/202501011024_entity_correction.sql rename to example/migration/sqlite/memory-repeatable2/202501011024_entity_correction.sql diff --git a/example/migration/sqlite/memory-repeatable/202501011024_entity_correction_2.sql b/example/migration/sqlite/memory-repeatable2/202501011024_entity_correction_2.sql similarity index 100% rename from example/migration/sqlite/memory-repeatable/202501011024_entity_correction_2.sql rename to example/migration/sqlite/memory-repeatable2/202501011024_entity_correction_2.sql diff --git a/tests/workflow/ArgumentsTest.php b/tests/workflow/ArgumentsTest.php index f27ccf3..856698b 100644 --- a/tests/workflow/ArgumentsTest.php +++ b/tests/workflow/ArgumentsTest.php @@ -5,6 +5,7 @@ namespace kuaukutsu\poc\migration\tests\workflow; use Override; +use AssertionError; use PHPUnit\Framework\TestCase; use kuaukutsu\poc\migration\driver\PdoDriver; use kuaukutsu\poc\migration\exception\ConfigurationException; @@ -49,6 +50,7 @@ public function testUpWithLimit(): void $data = $this->command->fetchApplied(); self::assertCount(3, $data); + // check order $names = array_keys($data); self::assertEquals('202501021025_account_email.sql', $names[0]); self::assertEquals('202501021024_account_create.sql', $names[1]); @@ -72,6 +74,13 @@ public function testDownWithLimit(): void self::assertEmpty($data); } + public function testLimitNegativeValue(): void + { + $this->expectException(AssertionError::class); + /** @phpstan-ignore argument.type */ + new InputArgs(limit: -1); + } + public function testWithDryRun(): void { $this->migrator->init(); @@ -105,8 +114,6 @@ public function testWithDb(): void public function testWithUnknownDb(): void { $this->migrator->init(); - $data = $this->command->fetchApplied(); - self::assertEmpty($data); $this->expectException(ConfigurationException::class); $this->migrator->up(new InputArgs(dbName: 'sqlite/unknown')); @@ -151,11 +158,11 @@ public function testDownWithLatestVersion(): void usleep(10_000); - $this->migrator->up($args); + $this->migrator->up($args); // +1 $data = $this->command->fetchApplied(); self::assertCount(2, $data); - $this->migrator->up($args); + $this->migrator->up($args); // +1 $data = $this->command->fetchApplied(); self::assertCount(3, $data); diff --git a/tests/workflow/CommandTest.php b/tests/workflow/CommandTest.php index da913bd..e1de697 100644 --- a/tests/workflow/CommandTest.php +++ b/tests/workflow/CommandTest.php @@ -8,6 +8,7 @@ use Throwable; use PDO; use PDOException; +use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\TestCase; use kuaukutsu\poc\migration\driver\DriverType; use kuaukutsu\poc\migration\internal\command\Args; @@ -44,6 +45,7 @@ public function testInit(): void /** * @throws Throwable */ + #[Depends('testInit')] public function testUp(): void { $this->execInitialization(); @@ -51,12 +53,14 @@ public function testUp(): void $this->execUp('table1'); $data = $this->command->fetchApplied(); + self::assertCount(1, $data); self::assertNotEmpty($data['test-table1']); } /** * @throws Throwable */ + #[Depends('testInit')] public function testDown(): void { $this->execInitialization(); @@ -82,6 +86,7 @@ public function testDown(): void /** * @throws Throwable */ + #[Depends('testInit')] public function testFetchLimit(): void { $this->execInitialization(); @@ -100,6 +105,8 @@ public function testFetchLimit(): void new Args(limit: 2) ); self::assertCount(2, $data); + + // sort order $names = array_keys($data); self::assertEquals('test-table3', $names[0]); self::assertEquals('test-table2', $names[1]); @@ -108,6 +115,7 @@ public function testFetchLimit(): void /** * @throws Throwable */ + #[Depends('testInit')] public function testFetchVersion(): void { $this->execInitialization(); @@ -140,6 +148,7 @@ public function testFetchVersion(): void /** * @throws Throwable */ + #[Depends('testInit')] public function testUpDryRun(): void { $this->execInitialization(); @@ -170,6 +179,7 @@ public function testUpDryRun(): void /** * @throws Throwable */ + #[Depends('testInit')] public function testDownDryRun(): void { $this->execInitialization(); @@ -200,6 +210,7 @@ public function testDownDryRun(): void /** * @throws Throwable */ + #[Depends('testInit')] public function testUpRollbackTransaction(): void { $this->execInitialization(); @@ -222,6 +233,7 @@ public function testUpRollbackTransaction(): void /** * @throws Throwable */ + #[Depends('testInit')] public function testDownRollbackTransaction(): void { $this->execInitialization(); diff --git a/tests/workflow/EventTest.php b/tests/workflow/EventTest.php index 9914bf9..e25c39b 100644 --- a/tests/workflow/EventTest.php +++ b/tests/workflow/EventTest.php @@ -169,7 +169,7 @@ public function testMigrationFilesystemNotice(): void ); } - public function testMigrationDoesNotContainFiles(): void + public function testMigrationUpDoesNotContainFiles(): void { $eventSubscriber = new TestSubscriber(); $migrator = MigratorFactory::makeFromEvent( @@ -183,18 +183,32 @@ public function testMigrationDoesNotContainFiles(): void ); $migrator->init(); - $migrator->up(); + // migration completed in the previous step $migrator->up(); self::assertStringContainsString( 'does not contain migration files', $eventSubscriber->get(Event::FilesystemNotice) ); + } - $eventSubscriber->clear(); + public function testMigrationDownDoesNotContainFiles(): void + { + $eventSubscriber = new TestSubscriber(); + $migrator = MigratorFactory::makeFromEvent( + new PdoDriver( + dsn: 'sqlite::memory:', + ), + [ + $eventSubscriber, + ], + dirname(__DIR__) . '/migration/sqlite/memory' + ); + $migrator->init(); $migrator->down(); + // migration completed in the previous step $migrator->down(); self::assertStringContainsString( diff --git a/tests/workflow/MigrationFailTest.php b/tests/workflow/MigrationFailTest.php index 967a383..a96f229 100644 --- a/tests/workflow/MigrationFailTest.php +++ b/tests/workflow/MigrationFailTest.php @@ -8,6 +8,7 @@ use PHPUnit\Framework\TestCase; use kuaukutsu\poc\migration\driver\PdoDriver; use kuaukutsu\poc\migration\exception\ActionException; +use kuaukutsu\poc\migration\exception\ConfigurationException; use kuaukutsu\poc\migration\internal\command\CommandInterface; use kuaukutsu\poc\migration\internal\command\Params; use kuaukutsu\poc\migration\tests\MigratorFactory; @@ -79,4 +80,16 @@ public function testUpExactlyAllException(): void $this->migrator->up(new InputArgs(exactlyAll: true)); } + + public function testMigrationFixtureException(): void + { + $this->migrator->init(); + + $this->expectException(ConfigurationException::class); + $this->expectExceptionMessageMatches( + '/^the directory .+ does not exist.$/i' + ); + + $this->migrator->fixture(); + } } diff --git a/tests/workflow/MigrationTest.php b/tests/workflow/MigrationTest.php index e07a116..4345957 100644 --- a/tests/workflow/MigrationTest.php +++ b/tests/workflow/MigrationTest.php @@ -48,13 +48,13 @@ public function testInit(): void public function testUp(): void { $this->migrator->init(); - $data = $this->command->fetchApplied(); - self::assertEmpty($data); $this->migrator->up(); $data = $this->command->fetchApplied(); - self::assertCount(3, $data); + $countMigration = count($data); + self::assertGreaterThanOrEqual(3, $countMigration); + // sort order $names = array_keys($data); self::assertEquals('202501021025_account_email.sql', $names[0]); self::assertEquals('202501021024_account_create.sql', $names[1]); @@ -62,19 +62,17 @@ public function testUp(): void $this->migrator->up(); $data = $this->command->fetchApplied(); - self::assertCount(3, $data); + self::assertCount($countMigration, $data); } #[Depends('testInit')] public function testDown(): void { $this->migrator->init(); - $data = $this->command->fetchApplied(); - self::assertEmpty($data); $this->migrator->up(); $data = $this->command->fetchApplied(); - self::assertCount(3, $data); + self::assertGreaterThanOrEqual(3, $data); $this->migrator->down(); $data = $this->command->fetchApplied(); @@ -85,12 +83,10 @@ public function testDown(): void public function testRedo(): void { $this->migrator->init(); - $data = $this->command->fetchApplied(); - self::assertEmpty($data); $this->migrator->up(); $data = $this->command->fetchApplied(); - self::assertCount(3, $data); + self::assertGreaterThanOrEqual(3, $data); $version = (int)current($data); self::assertGreaterThan(0, $version); @@ -99,7 +95,7 @@ public function testRedo(): void $this->migrator->redo(); $data = $this->command->fetchApplied(); - self::assertCount(3, $data); + self::assertGreaterThanOrEqual(3, $data); $versionNew = (int)current($data); self::assertGreaterThan(0, $versionNew); @@ -118,24 +114,19 @@ public function testInitializationException(): void public function testConnectionException(): void { - $driver = new PdoDriver( - dsn: 'mysql:host=mysql;dbname=main', - ); + $driver = new PdoDriver(dsn: 'mysql:host=mysql;dbname=main'); + $migrator = MigratorFactory::makeFromEvent($driver); $this->expectException(ConnectionException::class); $this->expectExceptionMessageMatches('~PDO_MYSQL:\w+~'); - $migrator = MigratorFactory::makeFromDriver($driver); $migrator->init(); } public function testActionException(): void { - $migrator = MigratorFactory::makeFromEvent( - new PdoDriver( - dsn: 'sqlite::memory:', - ) - ); + $driver = new PdoDriver(dsn: 'sqlite::memory:'); + $migrator = MigratorFactory::makeFromEvent($driver); $this->expectException(ActionException::class); $this->expectExceptionMessage( @@ -146,15 +137,13 @@ public function testActionException(): void $migrator->up(); } - public function testActionExceptionDryRun(): void + public function testActionNotExceptionDryRun(): void { $driver = new PdoDriver(dsn: 'sqlite::memory:'); $migrator = MigratorFactory::makeFromEvent($driver); $command = $driver->makeCommand(new Params(table: 'migration')); $migrator->init(); - $data = $command->fetchApplied(); - self::assertEmpty($data); $migrator->up(new InputArgs(dryRun: true)); $data = $command->fetchApplied(); From ac21f38657423157c1b0ba8b2c3bee0fd5e2bfe6 Mon Sep 17 00:00:00 2001 From: Dmitriy Krivopalov Date: Fri, 6 Mar 2026 11:51:31 +0300 Subject: [PATCH 2/2] tests correction and infection fix --- tests/workflow/ArgumentsTest.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/workflow/ArgumentsTest.php b/tests/workflow/ArgumentsTest.php index 856698b..c44c56f 100644 --- a/tests/workflow/ArgumentsTest.php +++ b/tests/workflow/ArgumentsTest.php @@ -5,7 +5,6 @@ namespace kuaukutsu\poc\migration\tests\workflow; use Override; -use AssertionError; use PHPUnit\Framework\TestCase; use kuaukutsu\poc\migration\driver\PdoDriver; use kuaukutsu\poc\migration\exception\ConfigurationException; @@ -74,13 +73,6 @@ public function testDownWithLimit(): void self::assertEmpty($data); } - public function testLimitNegativeValue(): void - { - $this->expectException(AssertionError::class); - /** @phpstan-ignore argument.type */ - new InputArgs(limit: -1); - } - public function testWithDryRun(): void { $this->migrator->init();