|
13 | 13 |
|
14 | 14 | use Doctrine\Bundle\PHPCRBundle\DataFixtures\PHPCRExecutor;
|
15 | 15 | use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
| 16 | +use Doctrine\Common\DataFixtures\FixtureInterface; |
16 | 17 | use Doctrine\Common\DataFixtures\Loader;
|
17 | 18 | use Doctrine\Common\DataFixtures\ProxyReferenceRepository;
|
18 | 19 | use Doctrine\Common\DataFixtures\Purger\PHPCRPurger;
|
@@ -54,30 +55,40 @@ public function purgeRepository(bool $initialize = false): void
|
54 | 55 | }
|
55 | 56 |
|
56 | 57 | /**
|
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 |
59 | 60 | */
|
60 |
| - public function loadFixtures(array $classNames, bool $initialize = false): void |
| 61 | + public function loadFixtures(array $classes, bool $initialize = false): void |
61 | 62 | {
|
62 |
| - $loader = new ContainerAwareLoader($this->container); |
| 63 | + $loader = class_exists(ContainerAwareLoader::class) |
| 64 | + ? new ContainerAwareLoader($this->container) |
| 65 | + : new Loader() |
| 66 | + ; |
63 | 67 |
|
64 |
| - foreach ($classNames as $className) { |
| 68 | + foreach ($classes as $className) { |
65 | 69 | $this->loadFixtureClass($loader, $className);
|
66 | 70 | }
|
67 | 71 |
|
68 | 72 | $this->getExecutor($initialize)->execute($loader->getFixtures(), false);
|
69 | 73 | }
|
70 | 74 |
|
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 |
72 | 79 | {
|
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 | + } |
79 | 89 |
|
80 |
| - $fixture = new $className(); |
| 90 | + $fixture = new $class(); |
| 91 | + } |
81 | 92 |
|
82 | 93 | if ($loader->hasFixture($fixture)) {
|
83 | 94 | unset($fixture);
|
@@ -110,7 +121,7 @@ public function createTestNode(): void
|
110 | 121 | $session->save();
|
111 | 122 | }
|
112 | 123 |
|
113 |
| - private function getExecutor($initialize = false): PHPCRExecutor |
| 124 | + private function getExecutor(bool $initialize = false): PHPCRExecutor |
114 | 125 | {
|
115 | 126 | static $lastInitialize = null;
|
116 | 127 |
|
|
0 commit comments