Skip to content

Commit 3ea0140

Browse files
authored
Merge pull request #223 from symfony-cmf/4-to-5
4 to 5
2 parents c85c4cd + d447691 commit 3ea0140

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

Diff for: CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ Changelog
2121
4.x
2222
===
2323

24+
4.5.1
25+
-----
26+
27+
* Use regular fixture loader with Symfony 7 rather than the dropped `ContainerAwareLoader`.
28+
For fixtures with services, instantiate the fixture and pass the instance to `PHPCR::loadFixture`
29+
instead of passing the class string.
30+
2431
4.5.0
2532
-----
2633

Diff for: src/Functional/DbManager/PHPCR.php

+25-14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\Bundle\PHPCRBundle\DataFixtures\PHPCRExecutor;
1515
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
16+
use Doctrine\Common\DataFixtures\FixtureInterface;
1617
use Doctrine\Common\DataFixtures\Loader;
1718
use Doctrine\Common\DataFixtures\ProxyReferenceRepository;
1819
use Doctrine\Common\DataFixtures\Purger\PHPCRPurger;
@@ -54,30 +55,40 @@ public function purgeRepository(bool $initialize = false): void
5455
}
5556

5657
/**
57-
* @param string[] $classNames Fixture classes to load
58-
* @param bool $initialize if the ODM repository initializers should be executed
58+
* @param array<class-string|object> $classes Fixture classes or class names to load
59+
* @param bool $initialize Whether the ODM repository initializers should be executed
5960
*/
60-
public function loadFixtures(array $classNames, bool $initialize = false): void
61+
public function loadFixtures(array $classes, bool $initialize = false): void
6162
{
62-
$loader = new ContainerAwareLoader($this->container);
63+
$loader = class_exists(ContainerAwareLoader::class)
64+
? new ContainerAwareLoader($this->container)
65+
: new Loader()
66+
;
6367

64-
foreach ($classNames as $className) {
68+
foreach ($classes as $className) {
6569
$this->loadFixtureClass($loader, $className);
6670
}
6771

6872
$this->getExecutor($initialize)->execute($loader->getFixtures(), false);
6973
}
7074

71-
public function loadFixtureClass(Loader $loader, string $className): void
75+
/**
76+
* @param class-string|FixtureInterface $class
77+
*/
78+
public function loadFixtureClass(Loader $loader, $class): void
7279
{
73-
if (!class_exists($className)) {
74-
throw new \InvalidArgumentException(sprintf(
75-
'Fixture class "%s" does not exist.',
76-
$className
77-
));
78-
}
80+
if (\is_object($class)) {
81+
$fixture = $class;
82+
} else {
83+
if (!class_exists($class)) {
84+
throw new \InvalidArgumentException(sprintf(
85+
'Fixture class "%s" does not exist.',
86+
$class
87+
));
88+
}
7989

80-
$fixture = new $className();
90+
$fixture = new $class();
91+
}
8192

8293
if ($loader->hasFixture($fixture)) {
8394
unset($fixture);
@@ -110,7 +121,7 @@ public function createTestNode(): void
110121
$session->save();
111122
}
112123

113-
private function getExecutor($initialize = false): PHPCRExecutor
124+
private function getExecutor(bool $initialize = false): PHPCRExecutor
114125
{
115126
static $lastInitialize = null;
116127

0 commit comments

Comments
 (0)