diff --git a/src/Metadata/Storage/TableMetadataStorage.php b/src/Metadata/Storage/TableMetadataStorage.php index 74b88e90d..5948d2faa 100644 --- a/src/Metadata/Storage/TableMetadataStorage.php +++ b/src/Metadata/Storage/TableMetadataStorage.php @@ -276,10 +276,11 @@ private function updateMigratedVersionsFromV1orV2toV3(): void private function isAlreadyV3Format(AvailableMigration $availableMigration, ExecutedMigration $executedMigration): bool { - return strpos( - (string) $availableMigration->getVersion(), - (string) $executedMigration->getVersion(), - ) !== strlen((string) $availableMigration->getVersion()) - - strlen((string) $executedMigration->getVersion()); + return (string) $availableMigration->getVersion() === (string) $executedMigration->getVersion() + || strpos( + (string) $availableMigration->getVersion(), + (string) $executedMigration->getVersion(), + ) !== strlen((string) $availableMigration->getVersion()) - + strlen((string) $executedMigration->getVersion()); } } diff --git a/tests/Metadata/Storage/TableMetadataStorageTest.php b/tests/Metadata/Storage/TableMetadataStorageTest.php index 4fcb0a5ae..d24193a5f 100644 --- a/tests/Metadata/Storage/TableMetadataStorageTest.php +++ b/tests/Metadata/Storage/TableMetadataStorageTest.php @@ -18,7 +18,10 @@ use Doctrine\DBAL\Types\IntegerType; use Doctrine\DBAL\Types\StringType; use Doctrine\DBAL\Types\Types; +use Doctrine\Migrations\AbstractMigration; use Doctrine\Migrations\Exception\MetadataStorageError; +use Doctrine\Migrations\Metadata\AvailableMigration; +use Doctrine\Migrations\Metadata\ExecutedMigration; use Doctrine\Migrations\Metadata\Storage\TableMetadataStorage; use Doctrine\Migrations\Metadata\Storage\TableMetadataStorageConfiguration; use Doctrine\Migrations\Version\AlphabeticalComparator; @@ -27,6 +30,7 @@ use Doctrine\Migrations\Version\Version; use PHPUnit\Framework\TestCase; use Psr\Log\Test\TestLogger; +use ReflectionClass; use function sprintf; @@ -400,4 +404,21 @@ public function testGetSql(): void self::assertCount(0, $this->connection->fetchAllAssociative($sql)); } + + public function testIsAlreadyV3FormatDoesntMissTheSameVersions(): void + { + $availableMigration = new AvailableMigration( + new Version('Foo\\Version1234'), + $this->createMock(AbstractMigration::class), + ); + $executedMigrationV3 = new ExecutedMigration(new Version('Foo\\Version1234')); + $executedMigrationOlder = new ExecutedMigration(new Version('Version1234')); + + $reflection = new ReflectionClass(TableMetadataStorage::class); + $method = $reflection->getMethod('isAlreadyV3Format'); + $method->setAccessible(true); + + self::assertTrue($method->invokeArgs($this->storage, [$availableMigration, $executedMigrationV3])); + self::assertFalse($method->invokeArgs($this->storage, [$availableMigration, $executedMigrationOlder])); + } }