Skip to content

Commit

Permalink
Test against dev deps in CI (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus authored Nov 13, 2023
1 parent de8b465 commit 68643ac
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 24 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ jobs:
uses: "doctrine/.github/.github/workflows/[email protected]"
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/[email protected]"
with:
symfony-version-constraint: "^7"
12 changes: 8 additions & 4 deletions Tests/DependencyInjection/DoctrineCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

/**
Expand All @@ -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);

Expand Down
12 changes: 9 additions & 3 deletions Tests/DependencyInjection/DoctrineMigrationsExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,13 +25,15 @@
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;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\Reference;

use function assert;
use function interface_exists;
use function sys_get_temp_dir;

class DoctrineMigrationsExtensionTest extends TestCase
Expand Down Expand Up @@ -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'],
];
Expand All @@ -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());
}

Expand Down
30 changes: 30 additions & 0 deletions Tests/Fixtures/Migrations/ContainerAwareMigration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Doctrine\Bundle\MigrationsBundle\Tests\Fixtures\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class ContainerAwareMigration extends AbstractMigration implements ContainerAwareInterface
{
/** @var ContainerInterface */
private $container;

public function up(Schema $schema): void
{
}

public function setContainer(?ContainerInterface $container = null): void
{
$this->container = $container;
}

public function getContainer(): ?ContainerInterface
{
return $this->container;
}
}
17 changes: 1 addition & 16 deletions Tests/Fixtures/Migrations/Migration001.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 68643ac

Please sign in to comment.