From d825c14d835066a0440edb53c6314bd7d8132f8c Mon Sep 17 00:00:00 2001 From: kfrankiewicz Date: Thu, 24 Oct 2024 09:36:39 +0200 Subject: [PATCH 1/4] TableMetadataStorage - fix isAlreadyV3Format for the same version values --- src/Metadata/Storage/TableMetadataStorage.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Metadata/Storage/TableMetadataStorage.php b/src/Metadata/Storage/TableMetadataStorage.php index 74b88e90d..f50add555 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 $availableMigration->getVersion() !== $executedMigration->getVersion() + && strpos( + (string) $availableMigration->getVersion(), + (string) $executedMigration->getVersion(), + ) !== strlen((string) $availableMigration->getVersion()) - + strlen((string) $executedMigration->getVersion()); } } From be177d2427e80e4927bd12a3f4febfffbddeb12b Mon Sep 17 00:00:00 2001 From: kfrankiewicz Date: Thu, 24 Oct 2024 09:46:21 +0200 Subject: [PATCH 2/4] spacing --- src/Metadata/Storage/TableMetadataStorage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Metadata/Storage/TableMetadataStorage.php b/src/Metadata/Storage/TableMetadataStorage.php index f50add555..b753d62a8 100644 --- a/src/Metadata/Storage/TableMetadataStorage.php +++ b/src/Metadata/Storage/TableMetadataStorage.php @@ -281,6 +281,6 @@ private function isAlreadyV3Format(AvailableMigration $availableMigration, Execu (string) $availableMigration->getVersion(), (string) $executedMigration->getVersion(), ) !== strlen((string) $availableMigration->getVersion()) - - strlen((string) $executedMigration->getVersion()); + strlen((string) $executedMigration->getVersion()); } } From 9f64ea0e6981d65de03f81a3f4672c13039e84bf Mon Sep 17 00:00:00 2001 From: kfrankiewicz Date: Wed, 6 Nov 2024 14:06:20 +0100 Subject: [PATCH 3/4] fix and test --- src/Metadata/Storage/TableMetadataStorage.php | 4 ++-- .../Storage/TableMetadataStorageTest.php | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Metadata/Storage/TableMetadataStorage.php b/src/Metadata/Storage/TableMetadataStorage.php index b753d62a8..5948d2faa 100644 --- a/src/Metadata/Storage/TableMetadataStorage.php +++ b/src/Metadata/Storage/TableMetadataStorage.php @@ -276,8 +276,8 @@ private function updateMigratedVersionsFromV1orV2toV3(): void private function isAlreadyV3Format(AvailableMigration $availableMigration, ExecutedMigration $executedMigration): bool { - return $availableMigration->getVersion() !== $executedMigration->getVersion() - && strpos( + return (string) $availableMigration->getVersion() === (string) $executedMigration->getVersion() + || strpos( (string) $availableMigration->getVersion(), (string) $executedMigration->getVersion(), ) !== strlen((string) $availableMigration->getVersion()) - diff --git a/tests/Metadata/Storage/TableMetadataStorageTest.php b/tests/Metadata/Storage/TableMetadataStorageTest.php index 4fcb0a5ae..ba9160cbb 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; @@ -400,4 +403,21 @@ public function testGetSql(): void self::assertCount(0, $this->connection->fetchAllAssociative($sql)); } + + public function testIsAlreadyV3FormatDoesntMissTheSameVersions() + { + $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])); + } } From 61f959982cdc2ed869f995463e8ded7bddd5254a Mon Sep 17 00:00:00 2001 From: kfrankiewicz Date: Thu, 7 Nov 2024 10:16:30 +0100 Subject: [PATCH 4/4] coding standards --- tests/Metadata/Storage/TableMetadataStorageTest.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/Metadata/Storage/TableMetadataStorageTest.php b/tests/Metadata/Storage/TableMetadataStorageTest.php index ba9160cbb..d24193a5f 100644 --- a/tests/Metadata/Storage/TableMetadataStorageTest.php +++ b/tests/Metadata/Storage/TableMetadataStorageTest.php @@ -30,6 +30,7 @@ use Doctrine\Migrations\Version\Version; use PHPUnit\Framework\TestCase; use Psr\Log\Test\TestLogger; +use ReflectionClass; use function sprintf; @@ -404,17 +405,17 @@ public function testGetSql(): void self::assertCount(0, $this->connection->fetchAllAssociative($sql)); } - public function testIsAlreadyV3FormatDoesntMissTheSameVersions() + public function testIsAlreadyV3FormatDoesntMissTheSameVersions(): void { - $availableMigration = new AvailableMigration( + $availableMigration = new AvailableMigration( new Version('Foo\\Version1234'), - $this->createMock(AbstractMigration::class) + $this->createMock(AbstractMigration::class), ); - $executedMigrationV3 = new ExecutedMigration(new Version('Foo\\Version1234')); + $executedMigrationV3 = new ExecutedMigration(new Version('Foo\\Version1234')); $executedMigrationOlder = new ExecutedMigration(new Version('Version1234')); - $reflection = new \ReflectionClass(TableMetadataStorage::class); - $method = $reflection->getMethod('isAlreadyV3Format'); + $reflection = new ReflectionClass(TableMetadataStorage::class); + $method = $reflection->getMethod('isAlreadyV3Format'); $method->setAccessible(true); self::assertTrue($method->invokeArgs($this->storage, [$availableMigration, $executedMigrationV3]));