diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 40ba518a..72d24356 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -15,3 +15,9 @@ jobs: uses: "doctrine/.github/.github/workflows/continuous-integration.yml@3.1.0" with: php-versions: '["7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3"]' + + phpunit-with-dev-deps: + name: "PHPUnit with dev dependencies" + uses: "doctrine/.github/.github/workflows/continuous-integration-symfony-unstable.yml@3.1.0" + with: + symfony-version-constraint: "^7" diff --git a/Tests/DependencyInjection/DoctrineCommandsTest.php b/Tests/DependencyInjection/DoctrineCommandsTest.php index a1113f27..e72f4086 100644 --- a/Tests/DependencyInjection/DoctrineCommandsTest.php +++ b/Tests/DependencyInjection/DoctrineCommandsTest.php @@ -24,6 +24,7 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Bundle\FrameworkBundle\Console\Application; +use Symfony\Component\Console\Command\LazyCommand; use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; @@ -40,9 +41,12 @@ class DoctrineCommandsTest extends TestCase */ public function testCommandRegistered(string $name, string $instance): void { - $application = $this->getApplication(); + $command = $this->getApplication()->find($name); + if ($command instanceof LazyCommand) { + $command = $command->getCommand(); + } - self::assertInstanceOf($instance, $application->find($name)); + self::assertInstanceOf($instance, $command); } /** @@ -68,8 +72,8 @@ public function getCommands(): array ]; } - /** @return MockObject|KernelInterface */ - private function getKernel(ContainerBuilder $container) + /** @return KernelInterface&MockObject */ + private function getKernel(ContainerBuilder $container): KernelInterface { $kernel = $this->createMock(KernelInterface::class); diff --git a/Tests/DependencyInjection/DoctrineMigrationsExtensionTest.php b/Tests/DependencyInjection/DoctrineMigrationsExtensionTest.php index 07350b68..2ac9dc27 100644 --- a/Tests/DependencyInjection/DoctrineMigrationsExtensionTest.php +++ b/Tests/DependencyInjection/DoctrineMigrationsExtensionTest.php @@ -9,7 +9,7 @@ use Doctrine\Bundle\DoctrineBundle\Registry; use Doctrine\Bundle\MigrationsBundle\DependencyInjection\DoctrineMigrationsExtension; use Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle; -use Doctrine\Bundle\MigrationsBundle\Tests\Fixtures\Migrations\Migration001; +use Doctrine\Bundle\MigrationsBundle\Tests\Fixtures\Migrations\ContainerAwareMigration; use Doctrine\Bundle\MigrationsBundle\Tests\Fixtures\TestBundle\TestBundle; use Doctrine\Migrations\Configuration\Configuration; use Doctrine\Migrations\DependencyFactory; @@ -25,6 +25,7 @@ use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Alias; +use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; @@ -32,6 +33,7 @@ use Symfony\Component\DependencyInjection\Reference; use function assert; +use function interface_exists; use function sys_get_temp_dir; class DoctrineMigrationsExtensionTest extends TestCase @@ -170,6 +172,10 @@ public function compare(Version $a, Version $b): int public function testContainerAwareMigrations(): void { + if (! interface_exists(ContainerAwareInterface::class)) { + self::markTestSkipped('This test requires Symfony < 7'); + } + $config = [ 'migrations_paths' => ['DoctrineMigrationsTest' => 'a'], ]; @@ -180,9 +186,9 @@ public function testContainerAwareMigrations(): void $di = $container->get('doctrine.migrations.dependency_factory'); self::assertInstanceOf(DependencyFactory::class, $di); - $migration = $di->getMigrationFactory()->createVersion(Migration001::class); + $migration = $di->getMigrationFactory()->createVersion(ContainerAwareMigration::class); - self::assertInstanceOf(Migration001::class, $migration); + self::assertInstanceOf(ContainerAwareMigration::class, $migration); self::assertSame($container, $migration->getContainer()); } diff --git a/Tests/Fixtures/Migrations/ContainerAwareMigration.php b/Tests/Fixtures/Migrations/ContainerAwareMigration.php new file mode 100644 index 00000000..77614ce6 --- /dev/null +++ b/Tests/Fixtures/Migrations/ContainerAwareMigration.php @@ -0,0 +1,30 @@ +container = $container; + } + + public function getContainer(): ?ContainerInterface + { + return $this->container; + } +} diff --git a/Tests/Fixtures/Migrations/Migration001.php b/Tests/Fixtures/Migrations/Migration001.php index 20906a65..8fc6480d 100644 --- a/Tests/Fixtures/Migrations/Migration001.php +++ b/Tests/Fixtures/Migrations/Migration001.php @@ -6,26 +6,11 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; -use Symfony\Component\DependencyInjection\ContainerAwareInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; -class Migration001 extends AbstractMigration implements ContainerAwareInterface +class Migration001 extends AbstractMigration { - /** @var ContainerInterface */ - private $container; - public function up(Schema $schema): void { // TODO: Implement up() method. } - - public function setContainer(?ContainerInterface $container = null): void - { - $this->container = $container; - } - - public function getContainer(): ?ContainerInterface - { - return $this->container; - } } diff --git a/composer.json b/composer.json index 3b20dbf7..031fabc1 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "phpstan/phpstan-phpunit": "^1", "phpstan/phpstan-strict-rules": "^1.1", "phpstan/phpstan-symfony": "^1.3", - "doctrine/orm": "^2.6", + "doctrine/orm": "^2.6 || ^3", "doctrine/persistence": "^2.0 || ^3 ", "psalm/plugin-phpunit": "^0.18.4", "psalm/plugin-symfony": "^3 || ^5",