Skip to content

Commit b552b4c

Browse files
committed
Merge branch '3.5.x' into 4.0.x
* 3.5.x: Drop support for Symfony 3 + 4 (doctrine#403) Support Symfony 7 (doctrine#402)
2 parents 26e5b40 + d858b4c commit b552b4c

10 files changed

+87
-83
lines changed

Command/CommandCompatibility.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Bundle\FixturesBundle\Command;
6+
7+
use ReflectionMethod;
8+
use Symfony\Component\Console\Command\Command;
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
12+
if ((new ReflectionMethod(Command::class, 'execute'))->hasReturnType()) {
13+
/** @internal */
14+
trait CommandCompatibility
15+
{
16+
protected function execute(InputInterface $input, OutputInterface $output): int
17+
{
18+
return $this->doExecute($input, $output);
19+
}
20+
}
21+
} else {
22+
/** @internal */
23+
trait CommandCompatibility
24+
{
25+
/**
26+
* {@inheritDoc}
27+
*
28+
* @return int
29+
*/
30+
protected function execute(InputInterface $input, OutputInterface $output)
31+
{
32+
return $this->doExecute($input, $output);
33+
}
34+
}
35+
}

Command/LoadDataFixturesDoctrineCommand.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,31 @@
2222
use function assert;
2323
use function implode;
2424
use function sprintf;
25-
use function trigger_error;
26-
27-
use const E_USER_DEPRECATED;
25+
use function trigger_deprecation;
2826

2927
/**
3028
* Load data fixtures from bundles.
3129
*/
3230
class LoadDataFixturesDoctrineCommand extends DoctrineCommand
3331
{
34-
/** @var SymfonyFixturesLoader */
35-
private $fixturesLoader;
32+
use CommandCompatibility;
33+
34+
private SymfonyFixturesLoader $fixturesLoader;
3635

3736
/** @var PurgerFactory[] */
38-
private $purgerFactories;
37+
private array $purgerFactories;
3938

4039
/** @param PurgerFactory[] $purgerFactories */
4140
public function __construct(SymfonyFixturesLoader $fixturesLoader, ?ManagerRegistry $doctrine = null, array $purgerFactories = [])
4241
{
4342
if ($doctrine === null) {
44-
@trigger_error(sprintf(
43+
trigger_deprecation(
44+
'doctrine/fixtures-bundle',
45+
'3.2',
4546
'Argument 2 of %s() expects an instance of %s, not passing it will throw a \TypeError in DoctrineFixturesBundle 4.0.',
4647
__METHOD__,
47-
ManagerRegistry::class
48-
), E_USER_DEPRECATED);
48+
ManagerRegistry::class,
49+
);
4950
}
5051

5152
parent::__construct($doctrine);
@@ -91,8 +92,7 @@ protected function configure()
9192
);
9293
}
9394

94-
/** @return int */
95-
protected function execute(InputInterface $input, OutputInterface $output)
95+
private function doExecute(InputInterface $input, OutputInterface $output): int
9696
{
9797
$ui = new SymfonyStyle($input, $output);
9898

Loader/SymfonyFixturesLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
final class SymfonyFixturesLoader extends Loader
2222
{
2323
/** @var FixtureInterface[] */
24-
private $loadedFixtures = [];
24+
private array $loadedFixtures = [];
2525

2626
/** @var array<string, array<string, bool>> */
27-
private $groupsFixtureMapping = [];
27+
private array $groupsFixtureMapping = [];
2828

2929
/**
3030
* @internal

Tests/Command/LoadDataFixturesDoctrineCommandTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Doctrine\Bundle\FixturesBundle\Loader\SymfonyFixturesLoader;
1010
use Doctrine\Persistence\ManagerRegistry;
1111
use PHPUnit\Framework\TestCase;
12+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1213
use TypeError;
1314

1415
use function sprintf;
@@ -17,14 +18,15 @@
1718

1819
class LoadDataFixturesDoctrineCommandTest extends TestCase
1920
{
20-
/**
21-
* @group legacy
22-
* @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.
23-
*/
21+
use ExpectDeprecationTrait;
22+
23+
/** @group legacy */
2424
public function testInstantiatingWithoutManagerRegistry(): void
2525
{
2626
$loader = new SymfonyFixturesLoader();
2727

28+
$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.');
29+
2830
try {
2931
new LoadDataFixturesDoctrineCommand($loader);
3032
} catch (TypeError $e) {

Tests/IntegrationTest.php

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
use Doctrine\Bundle\FixturesBundle\Purger\PurgerFactory;
1212
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\DependentOnRequiredConstructorArgsFixtures;
1313
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\OtherFixtures;
14-
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\RequiredConstructorArgsFixtures;
1514
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\WithDependenciesFixtures;
16-
use Doctrine\Common\DataFixtures\Loader;
1715
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
1816
use Doctrine\Common\EventManager;
1917
use Doctrine\DBAL\Connection;
@@ -28,9 +26,7 @@
2826
use Symfony\Component\DependencyInjection\Definition;
2927

3028
use function array_map;
31-
use function assert;
3229
use function get_class;
33-
use function method_exists;
3430

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

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

5551
$actualFixtures = $loader->getFixtures();
5652
$this->assertCount(2, $actualFixtures);
@@ -83,7 +79,7 @@ public function testFixturesLoaderWhenFixtureHasDepdencenyThatIsNotYetLoaded():
8379
$container = $kernel->getContainer();
8480

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

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

101-
public function testExceptionWithDependenciesWithRequiredArguments(): void
102-
{
103-
// see https://github.com/doctrine/data-fixtures/pull/274
104-
// When that is merged, this test will only run when using
105-
// an older version of that library.
106-
if (method_exists(Loader::class, 'createFixture')) {
107-
$this->markTestSkipped();
108-
}
109-
110-
$kernel = new IntegrationTestKernel('dev', true);
111-
$kernel->addServices(static function (ContainerBuilder $c): void {
112-
$c->autowire(DependentOnRequiredConstructorArgsFixtures::class)
113-
->addTag(FixturesCompilerPass::FIXTURE_TAG);
114-
115-
$c->autowire(RequiredConstructorArgsFixtures::class)
116-
->setArgument(0, 'foo')
117-
->addTag(FixturesCompilerPass::FIXTURE_TAG);
118-
119-
$c->setAlias('test.doctrine.fixtures.loader', new Alias('doctrine.fixtures.loader', true));
120-
});
121-
$kernel->boot();
122-
$container = $kernel->getContainer();
123-
124-
$loader = $container->get('test.doctrine.fixtures.loader');
125-
assert($loader instanceof Loader);
126-
127-
$this->expectException(LogicException::class);
128-
$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.');
129-
130-
$loader->getFixtures();
131-
}
132-
13397
public function testExceptionIfDependentFixtureNotWired(): void
13498
{
135-
// only runs on newer versions of doctrine/data-fixtures
136-
if (! method_exists(Loader::class, 'createFixture')) {
137-
$this->markTestSkipped();
138-
}
139-
14099
$kernel = new IntegrationTestKernel('dev', true);
141100
$kernel->addServices(static function (ContainerBuilder $c): void {
142101
$c->autowire(DependentOnRequiredConstructorArgsFixtures::class)
@@ -346,7 +305,7 @@ public function testRunCommandWithDefaultPurger(): void
346305
$container->set('test.doctrine.fixtures.purger.orm_purger_factory', $purgerFactory);
347306

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

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

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

492451
$command = $container->get('test.doctrine.fixtures_load_command');
493-
assert($command instanceof LoadDataFixturesDoctrineCommand);
452+
$this->assertInstanceOf(LoadDataFixturesDoctrineCommand::class, $command);
494453
$tester = new CommandTester($command);
495454
$tester->execute(['--purge-with-truncate' => true], ['interactive' => false]);
496455
}

Tests/IntegrationTestKernel.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Doctrine\Bundle\FixturesBundle\Tests;
66

7+
use Closure;
78
use Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle;
89
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\FooBundle;
910
use Doctrine\Persistence\ManagerRegistry;
@@ -17,11 +18,8 @@
1718

1819
class IntegrationTestKernel extends Kernel
1920
{
20-
/** @var callable */
21-
private $servicesCallback;
22-
23-
/** @var int */
24-
private $randomKey;
21+
private ?Closure $servicesCallback = null;
22+
private int $randomKey;
2523

2624
public function __construct(string $environment, bool $debug)
2725
{
@@ -46,7 +44,7 @@ public function registerBundles(): array
4644
];
4745
}
4846

49-
public function addServices(callable $callback): void
47+
public function addServices(Closure $callback): void
5048
{
5149
$this->servicesCallback = $callback;
5250
}

Tests/Purger/ORMPurgerFactoryTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414

1515
class ORMPurgerFactoryTest extends TestCase
1616
{
17-
/** @var ORMPurgerFactory */
18-
private $factory;
17+
private ORMPurgerFactory $factory;
1918

20-
/** @var EntityManagerInterface|MockObject */
21-
private $em;
19+
/** @var EntityManagerInterface&MockObject */
20+
private EntityManagerInterface $em;
2221

2322
protected function setUp(): void
2423
{

composer.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,22 @@
2222
"require": {
2323
"php": "^8.1",
2424
"doctrine/data-fixtures": "^1.3",
25-
"doctrine/doctrine-bundle": "^2.0",
26-
"doctrine/orm": "^2.6.0",
27-
"doctrine/persistence": "^2.0|^3.0",
25+
"doctrine/doctrine-bundle": "^2.2",
26+
"doctrine/orm": "^2.14.0",
27+
"doctrine/persistence": "^2.4|^3.0",
2828
"symfony/config": "^5.4|^6.0|^7.0",
2929
"symfony/console": "^5.4|^6.0|^7.0",
3030
"symfony/dependency-injection": "^5.4|^6.0|^7.0",
31+
"symfony/deprecation-contracts": "^2.1|^3",
3132
"symfony/doctrine-bridge": "^5.4|^6.0|^7.0",
3233
"symfony/http-kernel": "^5.4|^6.0|^7.0"
3334
},
3435
"require-dev": {
35-
"doctrine/coding-standard": "^9 || ^12",
36-
"phpstan/phpstan": "^1.4.10",
37-
"phpunit/phpunit": "^9.5.20",
38-
"symfony/phpunit-bridge": "^6.0.8",
39-
"vimeo/psalm": "^4.22"
36+
"doctrine/coding-standard": "^12",
37+
"phpstan/phpstan": "^1.10.39",
38+
"phpunit/phpunit": "^9.6.13",
39+
"symfony/phpunit-bridge": "^6.3.6",
40+
"vimeo/psalm": "^4.30"
4041
},
4142
"autoload": {
4243
"psr-4": { "Doctrine\\Bundle\\FixturesBundle\\": "" }

phpcs.xml.dist

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<config name="php_version" value="70100"/>
1010

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

1414
<file>.</file>
1515
<exclude-pattern>/vendor</exclude-pattern>
@@ -25,6 +25,8 @@
2525
<exclude-pattern>ORMFixtureInterface.php</exclude-pattern>
2626
</rule>
2727
<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
28+
<exclude-pattern>Loader/SymfonyBridgeLoader.php</exclude-pattern>
29+
<exclude-pattern>Command/CommandCompatibility.php</exclude-pattern>
2830
<exclude-pattern>Tests/IntegrationTest.php</exclude-pattern>
2931
</rule>
3032
<rule ref="Squiz.Classes.ClassFileName.NoMatch">

psalm.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,12 @@
2222
<directory name="vendor" />
2323
</ignoreFiles>
2424
</projectFiles>
25+
26+
<issueHandlers>
27+
<DuplicateClass>
28+
<errorLevel type="suppress">
29+
<file name="Command/CommandCompatibility.php"/>
30+
</errorLevel>
31+
</DuplicateClass>
32+
</issueHandlers>
2533
</psalm>

0 commit comments

Comments
 (0)