From 89d15d39b432c4c7bd03452983eb061303673699 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sat, 16 Mar 2024 10:51:50 +0100 Subject: [PATCH] allow installation with symfony 7 --- .github/workflows/test-application.yaml | 5 +--- CHANGELOG.md | 7 +++++ README.md | 2 +- composer.json | 11 ++++---- tests/Functional/MigrationTest.php | 36 ++++++++++++------------- tests/Unit/MigratorFactoryTest.php | 26 ++++++++++-------- tests/Unit/MigratorUtilTest.php | 5 ++-- tests/Unit/VersionCollectionTest.php | 31 ++++++++++----------- tests/Unit/VersionFinderTest.php | 14 +++++----- 9 files changed, 72 insertions(+), 65 deletions(-) diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index 462433a..f53f1f9 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -19,11 +19,8 @@ jobs: fail-fast: false matrix: include: - - php-version: '7.2' + - php-version: '8.1' dependencies: 'lowest' - - php-version: '7.3' - - php-version: '7.4' - - php-version: '8.0' - php-version: '8.1' - php-version: '8.2' - php-version: '8.3' diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f443e3..5a56e35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ Changelog ========= +1.4.0 +----- + +* Allow installation with Symfony 7. +* Test with PHP 8.2, 8.3 +* Drop support for PHP < 8.1 + 1.3.1 ----- diff --git a/README.md b/README.md index fa44f76..afb37b0 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ use PHPCR\Migrations\VersionFinder; use PHPCR\Migrations\Migrator; $storage = new VersionStorage($phpcrSession); -$finder = new VersionFinder(array('/path/to/migrations')); +$finder = new VersionFinder(['/path/to/migrations']); $versions = $finder->getVersionCollection(); $migrator = new Migrator($session, $versionCollection, $storage); diff --git a/composer.json b/composer.json index c315882..389734c 100644 --- a/composer.json +++ b/composer.json @@ -9,16 +9,15 @@ } ], "require": { - "php": "^7.2|^8.0", + "php": "^8.1", "phpcr/phpcr": "^2.1", - "symfony/finder": "^4.4 || ^5.0 || ^6.0", - "symfony/console": "^4.4 || ^5.0 || ^6.0" + "symfony/finder": "^5.4 || ^6.0 || ^7.0", + "symfony/console": "^5.4 || ^6.0 || ^7.0" }, "require-dev": { - "jackalope/jackalope-fs": "0.0.*", + "jackalope/jackalope-fs": "^0.0.4", "handcraftedinthealps/zendsearch": "^2.0", - "phpunit/phpunit": "^8.5 || ^9.4", - "phpspec/prophecy": "^1.19" + "phpunit/phpunit": "^9.4" }, "autoload": { "psr-4": { diff --git a/tests/Functional/MigrationTest.php b/tests/Functional/MigrationTest.php index 4e52fa8..3840d5e 100644 --- a/tests/Functional/MigrationTest.php +++ b/tests/Functional/MigrationTest.php @@ -25,11 +25,11 @@ class MigrationTest extends BaseTestCase public const VERSION2 = '201501011212'; public const VERSION3 = '201501011215'; - private $output; - private $filesystem; - private $migrationDistDir; - private $migrationDir; - private $storage; + private BufferedOutput $output; + private Filesystem $filesystem; + private string $migrationDistDir; + private string $migrationDir; + private VersionStorage $storage; public function setUp(): void { @@ -49,7 +49,7 @@ public function setUp(): void /** * It should execute all the migrations and populate the versions table. */ - public function testMigration() + public function testMigration(): void { $this->addVersion(self::VERSION1); $this->addVersion(self::VERSION2); @@ -72,7 +72,7 @@ public function testMigration() /** * It should not run migrations that have already been executed. */ - public function testMigrateAgain() + public function testMigrateAgain(): void { $this->addVersion(self::VERSION1); $this->addVersion(self::VERSION2); @@ -88,7 +88,7 @@ public function testMigrateAgain() /** * It should run new migrations. */ - public function testMigrateAdd() + public function testMigrateAdd(): void { $this->addVersion(self::VERSION1); @@ -105,7 +105,7 @@ public function testMigrateAdd() /** * It should run migrations backwards. */ - public function testMigrateDown() + public function testMigrateDown(): void { $this->addVersion(self::VERSION1); $this->addVersion(self::VERSION2); @@ -136,7 +136,7 @@ public function testMigrateDown() /** * It should do nothing if target version is current version. */ - public function testMigrateToCurrentVersionFromCurrent() + public function testMigrateToCurrentVersionFromCurrent(): void { $this->addVersion(self::VERSION1); $this->addVersion(self::VERSION2); @@ -150,7 +150,7 @@ public function testMigrateToCurrentVersionFromCurrent() /** * It should add all migrations. */ - public function testInitialize() + public function testInitialize(): void { $this->addVersion(self::VERSION1); $this->addVersion(self::VERSION2); @@ -164,7 +164,7 @@ public function testInitialize() /** * It should throw an exception if trying to reiniitialize. */ - public function testReinitialize() + public function testReinitialize(): void { $this->addVersion(self::VERSION1); $this->addVersion(self::VERSION2); @@ -179,7 +179,7 @@ public function testReinitialize() /** * It should migrate to the next version. */ - public function testMigrateNext() + public function testMigrateNext(): void { $this->addVersion(self::VERSION1); $this->addVersion(self::VERSION2); @@ -196,7 +196,7 @@ public function testMigrateNext() /** * It should migrate to the previous version. */ - public function testMigratePrevious() + public function testMigratePrevious(): void { $this->addVersion(self::VERSION1); $this->addVersion(self::VERSION2); @@ -223,7 +223,7 @@ public function testMigratePrevious() /** * It should migrate to the top. */ - public function testMigrateTop() + public function testMigrateTop(): void { $this->addVersion(self::VERSION1); $this->addVersion(self::VERSION2); @@ -235,7 +235,7 @@ public function testMigrateTop() /** * It should migrate to the bottom. */ - public function testMigrateBottom() + public function testMigrateBottom(): void { $this->addVersion(self::VERSION1); $this->addVersion(self::VERSION2); @@ -245,7 +245,7 @@ public function testMigrateBottom() $this->assertCount(3, $migratedVersions); } - private function addVersion($version) + private function addVersion($version): void { $this->filesystem->copy( $this->migrationDistDir.'/Version'.$version.'.php', @@ -253,7 +253,7 @@ private function addVersion($version) ); } - private function getMigrator() + private function getMigrator(): Migrator { $this->storage = new VersionStorage($this->session); $finder = new VersionFinder([$this->migrationDir]); diff --git a/tests/Unit/MigratorFactoryTest.php b/tests/Unit/MigratorFactoryTest.php index 16727cb..db9f4b3 100644 --- a/tests/Unit/MigratorFactoryTest.php +++ b/tests/Unit/MigratorFactoryTest.php @@ -11,24 +11,28 @@ namespace PHPCR\Migrations\Tests\Unit; +use PHPCR\Migrations\Migrator; use PHPCR\Migrations\MigratorFactory; +use PHPCR\Migrations\VersionCollection; +use PHPCR\Migrations\VersionFinder; +use PHPCR\Migrations\VersionStorage; +use PHPCR\SessionInterface; use PHPUnit\Framework\TestCase; class MigratorFactoryTest extends TestCase { - public function testFactory() + public function testFactory(): void { - $storage = $this->prophesize('PHPCR\Migrations\VersionStorage'); - $finder = $this->prophesize('PHPCR\Migrations\VersionFinder'); - $session = $this->prophesize('PHPCR\SessionInterface'); - $finder->getCollection()->willReturn($this->prophesize('PHPCR\Migrations\VersionCollection')->reveal()); + $storage = $this->createMock(VersionStorage::class); + $finder = $this->createMock(VersionFinder::class); + $finder->expects($this->once()) + ->method('getCollection') + ->willReturn($this->createMock(VersionCollection::class)) + ; + $session = $this->createMock(SessionInterface::class); - $factory = new MigratorFactory( - $storage->reveal(), - $finder->reveal(), - $session->reveal() - ); + $factory = new MigratorFactory($storage, $finder, $session); $migrator = $factory->getMigrator(); - $this->assertInstanceOf('PHPCR\Migrations\Migrator', $migrator); + $this->assertInstanceOf(Migrator::class, $migrator); } } diff --git a/tests/Unit/MigratorUtilTest.php b/tests/Unit/MigratorUtilTest.php index 8415831..b31ecdb 100644 --- a/tests/Unit/MigratorUtilTest.php +++ b/tests/Unit/MigratorUtilTest.php @@ -13,15 +13,16 @@ use PHPCR\Migrations\MigratorUtil; use PHPUnit\Framework\TestCase; +use Sulu\Bundle\ContentBundle\Version201511240843; class MigratorUtilTest extends TestCase { /** * It should return the classname of a file. */ - public function testGetClassName() + public function testGetClassName(): void { $className = MigratorUtil::getClassNameFromFile(__DIR__.'/migrations/Version201511240843.php'); - $this->assertEquals('\Sulu\Bundle\ContentBundle\Version201511240843', $className); + $this->assertEquals('\\'.Version201511240843::class, $className); } } diff --git a/tests/Unit/VersionCollectionTest.php b/tests/Unit/VersionCollectionTest.php index e3a0214..dfa8f73 100644 --- a/tests/Unit/VersionCollectionTest.php +++ b/tests/Unit/VersionCollectionTest.php @@ -12,6 +12,7 @@ namespace PHPCR\Migrations\Tests\Unit; use PHPCR\Migrations\VersionCollection; +use PHPCR\Migrations\VersionInterface; use PHPUnit\Framework\TestCase; class VersionCollectionTest extends TestCase @@ -22,19 +23,19 @@ class VersionCollectionTest extends TestCase public function setUp(): void { - $this->version1 = $this->prophesize('PHPCR\Migrations\VersionInterface'); - $this->version2 = $this->prophesize('PHPCR\Migrations\VersionInterface'); - $this->version3 = $this->prophesize('PHPCR\Migrations\VersionInterface'); + $this->version1 = $this->createMock(VersionInterface::class); + $this->version2 = $this->createMock(VersionInterface::class); + $this->version3 = $this->createMock(VersionInterface::class); } /** * It knows if it contains a version. */ - public function testHas() + public function testHas(): void { $collection = $this->createCollection([ - self::VERSION1 => $this->version1->reveal(), - self::VERSION3 => $this->version3->reveal(), + self::VERSION1 => $this->version1, + self::VERSION3 => $this->version3, ]); $this->assertTrue($collection->has(self::VERSION1)); $this->assertTrue($collection->has(self::VERSION3)); @@ -44,12 +45,12 @@ public function testHas() /** * It returns the versions required to migrate from up from A to B. */ - public function testFromAToBUp() + public function testFromAToBUp(): void { $collection = $this->createCollection([ - self::VERSION1 => $this->version1->reveal(), - self::VERSION2 => $this->version2->reveal(), - self::VERSION3 => $this->version3->reveal(), + self::VERSION1 => $this->version1, + self::VERSION2 => $this->version2, + self::VERSION3 => $this->version3, ]); $versions = $collection->getVersions(self::VERSION1, self::VERSION3); @@ -62,12 +63,12 @@ public function testFromAToBUp() /** * It returns the versions required to migrate down from A to B. */ - public function testDownFromAToBUp() + public function testDownFromAToBUp(): void { $collection = $this->createCollection([ - self::VERSION1 => $this->version1->reveal(), - self::VERSION2 => $this->version2->reveal(), - self::VERSION3 => $this->version3->reveal(), + self::VERSION1 => $this->version1, + self::VERSION2 => $this->version2, + self::VERSION3 => $this->version3, ]); $versions = $collection->getVersions(self::VERSION3, self::VERSION1); @@ -77,7 +78,7 @@ public function testDownFromAToBUp() ], array_map('strval', array_keys($versions))); } - private function createCollection($versions) + private function createCollection(array $versions): VersionCollection { return new VersionCollection($versions); } diff --git a/tests/Unit/VersionFinderTest.php b/tests/Unit/VersionFinderTest.php index 87807a8..cb67449 100644 --- a/tests/Unit/VersionFinderTest.php +++ b/tests/Unit/VersionFinderTest.php @@ -11,15 +11,13 @@ namespace PHPCR\Migrations\Tests\Unit; +use PHPCR\Migrations\VersionCollection; use PHPCR\Migrations\VersionFinder; use PHPUnit\Framework\TestCase; class VersionFinderTest extends TestCase { - /** - * @var VersionFinder - */ - private $finder; + private VersionFinder $finder; public function setUp(): void { @@ -33,10 +31,10 @@ public function setUp(): void * * @runInSeparateProcess */ - public function testGetCollection() + public function testGetCollection(): void { $collection = $this->finder->getCollection(); - $this->assertInstanceOf('PHPCR\Migrations\VersionCollection', $collection); + $this->assertInstanceOf(VersionCollection::class, $collection); $versions = $collection->getAllVersions(); $this->assertCount(3, $versions); } @@ -44,10 +42,10 @@ public function testGetCollection() /** * It should do nothing if no migrations paths are given. */ - public function testNoMigrationPaths() + public function testNoMigrationPaths(): void { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('No paths were provided'); - $versionFinder = new VersionFinder([]); + new VersionFinder([]); } }