Skip to content

Commit

Permalink
Merge branch '3.5.x' into 4.0.x
Browse files Browse the repository at this point in the history
* 3.5.x:
  Drop support for Symfony 3 + 4 (#403)
  Support Symfony 7 (#402)
  • Loading branch information
derrabus committed Nov 11, 2023
2 parents 26e5b40 + d858b4c commit b552b4c
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 83 deletions.
35 changes: 35 additions & 0 deletions Command/CommandCompatibility.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Doctrine\Bundle\FixturesBundle\Command;

use ReflectionMethod;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

if ((new ReflectionMethod(Command::class, 'execute'))->hasReturnType()) {
/** @internal */
trait CommandCompatibility
{
protected function execute(InputInterface $input, OutputInterface $output): int
{
return $this->doExecute($input, $output);
}
}
} else {
/** @internal */
trait CommandCompatibility
{
/**
* {@inheritDoc}
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
return $this->doExecute($input, $output);
}
}
}
22 changes: 11 additions & 11 deletions Command/LoadDataFixturesDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,31 @@
use function assert;
use function implode;
use function sprintf;
use function trigger_error;

use const E_USER_DEPRECATED;
use function trigger_deprecation;

/**
* Load data fixtures from bundles.
*/
class LoadDataFixturesDoctrineCommand extends DoctrineCommand
{
/** @var SymfonyFixturesLoader */
private $fixturesLoader;
use CommandCompatibility;

private SymfonyFixturesLoader $fixturesLoader;

/** @var PurgerFactory[] */
private $purgerFactories;
private array $purgerFactories;

/** @param PurgerFactory[] $purgerFactories */
public function __construct(SymfonyFixturesLoader $fixturesLoader, ?ManagerRegistry $doctrine = null, array $purgerFactories = [])
{
if ($doctrine === null) {
@trigger_error(sprintf(
trigger_deprecation(
'doctrine/fixtures-bundle',
'3.2',
'Argument 2 of %s() expects an instance of %s, not passing it will throw a \TypeError in DoctrineFixturesBundle 4.0.',
__METHOD__,
ManagerRegistry::class
), E_USER_DEPRECATED);
ManagerRegistry::class,
);
}

parent::__construct($doctrine);
Expand Down Expand Up @@ -91,8 +92,7 @@ protected function configure()
);
}

/** @return int */
protected function execute(InputInterface $input, OutputInterface $output)
private function doExecute(InputInterface $input, OutputInterface $output): int
{
$ui = new SymfonyStyle($input, $output);

Expand Down
4 changes: 2 additions & 2 deletions Loader/SymfonyFixturesLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
final class SymfonyFixturesLoader extends Loader
{
/** @var FixtureInterface[] */
private $loadedFixtures = [];
private array $loadedFixtures = [];

/** @var array<string, array<string, bool>> */
private $groupsFixtureMapping = [];
private array $groupsFixtureMapping = [];

/**
* @internal
Expand Down
10 changes: 6 additions & 4 deletions Tests/Command/LoadDataFixturesDoctrineCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\Bundle\FixturesBundle\Loader\SymfonyFixturesLoader;
use Doctrine\Persistence\ManagerRegistry;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use TypeError;

use function sprintf;
Expand All @@ -17,14 +18,15 @@

class LoadDataFixturesDoctrineCommandTest extends TestCase
{
/**
* @group legacy
* @expectedDeprecation Argument 2 of Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand::__construct() expects an instance of Doctrine\Persistence\ManagerRegistry, not passing it will throw a \TypeError in DoctrineFixturesBundle 4.0.
*/
use ExpectDeprecationTrait;

/** @group legacy */
public function testInstantiatingWithoutManagerRegistry(): void
{
$loader = new SymfonyFixturesLoader();

$this->expectDeprecation('Since doctrine/fixtures-bundle 3.2: Argument 2 of Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand::__construct() expects an instance of Doctrine\Persistence\ManagerRegistry, not passing it will throw a \TypeError in DoctrineFixturesBundle 4.0.');

try {
new LoadDataFixturesDoctrineCommand($loader);
} catch (TypeError $e) {
Expand Down
53 changes: 6 additions & 47 deletions Tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
use Doctrine\Bundle\FixturesBundle\Purger\PurgerFactory;
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\DependentOnRequiredConstructorArgsFixtures;
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\OtherFixtures;
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\RequiredConstructorArgsFixtures;
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\WithDependenciesFixtures;
use Doctrine\Common\DataFixtures\Loader;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Connection;
Expand All @@ -28,9 +26,7 @@
use Symfony\Component\DependencyInjection\Definition;

use function array_map;
use function assert;
use function get_class;
use function method_exists;

class IntegrationTest extends TestCase
{
Expand All @@ -50,7 +46,7 @@ public function testFixturesLoader(): void
$container = $kernel->getContainer();

$loader = $container->get('test.doctrine.fixtures.loader');
assert($loader instanceof Loader);
$this->assertInstanceOf(SymfonyFixturesLoader::class, $loader);

$actualFixtures = $loader->getFixtures();
$this->assertCount(2, $actualFixtures);
Expand Down Expand Up @@ -83,7 +79,7 @@ public function testFixturesLoaderWhenFixtureHasDepdencenyThatIsNotYetLoaded():
$container = $kernel->getContainer();

$loader = $container->get('test.doctrine.fixtures.loader');
assert($loader instanceof Loader);
$this->assertInstanceOf(SymfonyFixturesLoader::class, $loader);

$actualFixtures = $loader->getFixtures();
$this->assertCount(2, $actualFixtures);
Expand All @@ -98,45 +94,8 @@ public function testFixturesLoaderWhenFixtureHasDepdencenyThatIsNotYetLoaded():
$this->assertInstanceOf(WithDependenciesFixtures::class, $actualFixtures[1]);
}

public function testExceptionWithDependenciesWithRequiredArguments(): void
{
// see https://github.com/doctrine/data-fixtures/pull/274
// When that is merged, this test will only run when using
// an older version of that library.
if (method_exists(Loader::class, 'createFixture')) {
$this->markTestSkipped();
}

$kernel = new IntegrationTestKernel('dev', true);
$kernel->addServices(static function (ContainerBuilder $c): void {
$c->autowire(DependentOnRequiredConstructorArgsFixtures::class)
->addTag(FixturesCompilerPass::FIXTURE_TAG);

$c->autowire(RequiredConstructorArgsFixtures::class)
->setArgument(0, 'foo')
->addTag(FixturesCompilerPass::FIXTURE_TAG);

$c->setAlias('test.doctrine.fixtures.loader', new Alias('doctrine.fixtures.loader', true));
});
$kernel->boot();
$container = $kernel->getContainer();

$loader = $container->get('test.doctrine.fixtures.loader');
assert($loader instanceof Loader);

$this->expectException(LogicException::class);
$this->expectExceptionMessage('The getDependencies() method returned a class (Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\RequiredConstructorArgsFixtures) that has required constructor arguments. Upgrade to "doctrine/data-fixtures" version 1.3 or higher to support this.');

$loader->getFixtures();
}

public function testExceptionIfDependentFixtureNotWired(): void
{
// only runs on newer versions of doctrine/data-fixtures
if (! method_exists(Loader::class, 'createFixture')) {
$this->markTestSkipped();
}

$kernel = new IntegrationTestKernel('dev', true);
$kernel->addServices(static function (ContainerBuilder $c): void {
$c->autowire(DependentOnRequiredConstructorArgsFixtures::class)
Expand Down Expand Up @@ -346,7 +305,7 @@ public function testRunCommandWithDefaultPurger(): void
$container->set('test.doctrine.fixtures.purger.orm_purger_factory', $purgerFactory);

$command = $container->get('test.doctrine.fixtures_load_command');
assert($command instanceof LoadDataFixturesDoctrineCommand);
$this->assertInstanceOf(LoadDataFixturesDoctrineCommand::class, $command);
$tester = new CommandTester($command);
$tester->execute([], ['interactive' => false]);
}
Expand Down Expand Up @@ -393,7 +352,7 @@ public function testRunCommandWithPurgeExclusions(): void
$container->set('test.doctrine.fixtures.purger.orm_purger_factory', $purgerFactory);

$command = $container->get('test.doctrine.fixtures_load_command');
assert($command instanceof LoadDataFixturesDoctrineCommand);
$this->assertInstanceOf(LoadDataFixturesDoctrineCommand::class, $command);
$tester = new CommandTester($command);
$tester->execute(['--purge-exclusions' => ['excluded_table']], ['interactive' => false]);
}
Expand Down Expand Up @@ -443,7 +402,7 @@ public function testRunCommandWithCustomPurgerAndCustomEntityManager(): void
$container->set('test.doctrine.fixtures.purger.test_factory', $purgerFactory);

$command = $container->get('test.doctrine.fixtures_load_command');
assert($command instanceof LoadDataFixturesDoctrineCommand);
$this->assertInstanceOf(LoadDataFixturesDoctrineCommand::class, $command);
$tester = new CommandTester($command);
$tester->execute(['--purger' => 'test', '--em' => 'alternative'], ['interactive' => false]);
}
Expand Down Expand Up @@ -490,7 +449,7 @@ public function testRunCommandWithPurgeMode(): void
$container->set('test.doctrine.fixtures.purger.orm_purger_factory', $purgerFactory);

$command = $container->get('test.doctrine.fixtures_load_command');
assert($command instanceof LoadDataFixturesDoctrineCommand);
$this->assertInstanceOf(LoadDataFixturesDoctrineCommand::class, $command);
$tester = new CommandTester($command);
$tester->execute(['--purge-with-truncate' => true], ['interactive' => false]);
}
Expand Down
10 changes: 4 additions & 6 deletions Tests/IntegrationTestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\Bundle\FixturesBundle\Tests;

use Closure;
use Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle;
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\FooBundle;
use Doctrine\Persistence\ManagerRegistry;
Expand All @@ -17,11 +18,8 @@

class IntegrationTestKernel extends Kernel
{
/** @var callable */
private $servicesCallback;

/** @var int */
private $randomKey;
private ?Closure $servicesCallback = null;
private int $randomKey;

public function __construct(string $environment, bool $debug)
{
Expand All @@ -46,7 +44,7 @@ public function registerBundles(): array
];
}

public function addServices(callable $callback): void
public function addServices(Closure $callback): void
{
$this->servicesCallback = $callback;
}
Expand Down
7 changes: 3 additions & 4 deletions Tests/Purger/ORMPurgerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@

class ORMPurgerFactoryTest extends TestCase
{
/** @var ORMPurgerFactory */
private $factory;
private ORMPurgerFactory $factory;

/** @var EntityManagerInterface|MockObject */
private $em;
/** @var EntityManagerInterface&MockObject */
private EntityManagerInterface $em;

protected function setUp(): void
{
Expand Down
17 changes: 9 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,22 @@
"require": {
"php": "^8.1",
"doctrine/data-fixtures": "^1.3",
"doctrine/doctrine-bundle": "^2.0",
"doctrine/orm": "^2.6.0",
"doctrine/persistence": "^2.0|^3.0",
"doctrine/doctrine-bundle": "^2.2",
"doctrine/orm": "^2.14.0",
"doctrine/persistence": "^2.4|^3.0",
"symfony/config": "^5.4|^6.0|^7.0",
"symfony/console": "^5.4|^6.0|^7.0",
"symfony/dependency-injection": "^5.4|^6.0|^7.0",
"symfony/deprecation-contracts": "^2.1|^3",
"symfony/doctrine-bridge": "^5.4|^6.0|^7.0",
"symfony/http-kernel": "^5.4|^6.0|^7.0"
},
"require-dev": {
"doctrine/coding-standard": "^9 || ^12",
"phpstan/phpstan": "^1.4.10",
"phpunit/phpunit": "^9.5.20",
"symfony/phpunit-bridge": "^6.0.8",
"vimeo/psalm": "^4.22"
"doctrine/coding-standard": "^12",
"phpstan/phpstan": "^1.10.39",
"phpunit/phpunit": "^9.6.13",
"symfony/phpunit-bridge": "^6.3.6",
"vimeo/psalm": "^4.30"
},
"autoload": {
"psr-4": { "Doctrine\\Bundle\\FixturesBundle\\": "" }
Expand Down
4 changes: 3 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<config name="php_version" value="70100"/>

<!-- Ignore warnings and show progress of the run -->
<arg value="np"/>
<arg value="nps"/>

<file>.</file>
<exclude-pattern>/vendor</exclude-pattern>
Expand All @@ -25,6 +25,8 @@
<exclude-pattern>ORMFixtureInterface.php</exclude-pattern>
</rule>
<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
<exclude-pattern>Loader/SymfonyBridgeLoader.php</exclude-pattern>
<exclude-pattern>Command/CommandCompatibility.php</exclude-pattern>
<exclude-pattern>Tests/IntegrationTest.php</exclude-pattern>
</rule>
<rule ref="Squiz.Classes.ClassFileName.NoMatch">
Expand Down
8 changes: 8 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<DuplicateClass>
<errorLevel type="suppress">
<file name="Command/CommandCompatibility.php"/>
</errorLevel>
</DuplicateClass>
</issueHandlers>
</psalm>

0 comments on commit b552b4c

Please sign in to comment.