Skip to content

Commit

Permalink
Merge pull request #20 from phpcr/symfony-7
Browse files Browse the repository at this point in the history
allow installation with symfony 7
  • Loading branch information
dbu authored Mar 16, 2024
2 parents edc68cf + 89d15d3 commit c7f18ca
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 65 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
-----

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
36 changes: 18 additions & 18 deletions tests/Functional/MigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -88,7 +88,7 @@ public function testMigrateAgain()
/**
* It should run new migrations.
*/
public function testMigrateAdd()
public function testMigrateAdd(): void
{
$this->addVersion(self::VERSION1);

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -245,15 +245,15 @@ public function testMigrateBottom()
$this->assertCount(3, $migratedVersions);
}

private function addVersion($version)
private function addVersion($version): void
{
$this->filesystem->copy(
$this->migrationDistDir.'/Version'.$version.'.php',
$this->migrationDir.'/Version'.$version.'.php'
);
}

private function getMigrator()
private function getMigrator(): Migrator
{
$this->storage = new VersionStorage($this->session);
$finder = new VersionFinder([$this->migrationDir]);
Expand Down
26 changes: 15 additions & 11 deletions tests/Unit/MigratorFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
5 changes: 3 additions & 2 deletions tests/Unit/MigratorUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
31 changes: 16 additions & 15 deletions tests/Unit/VersionCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down
14 changes: 6 additions & 8 deletions tests/Unit/VersionFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -33,21 +31,21 @@ 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);
}

/**
* 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([]);
}
}

0 comments on commit c7f18ca

Please sign in to comment.