Skip to content

Commit

Permalink
Merge pull request #1466 from kfrankiewicz/fix-isAlreadyV3Format-same…
Browse files Browse the repository at this point in the history
…-versions

TableMetadataStorage - fix isAlreadyV3Format for the same version values
  • Loading branch information
greg0ire authored Nov 12, 2024
2 parents a3af231 + 61f9599 commit 13b2364
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Metadata/Storage/TableMetadataStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
21 changes: 21 additions & 0 deletions tests/Metadata/Storage/TableMetadataStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +30,7 @@
use Doctrine\Migrations\Version\Version;
use PHPUnit\Framework\TestCase;
use Psr\Log\Test\TestLogger;
use ReflectionClass;

use function sprintf;

Expand Down Expand Up @@ -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]));
}
}

0 comments on commit 13b2364

Please sign in to comment.