You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: src/Configuration.php
+21-5
Original file line number
Diff line number
Diff line change
@@ -33,8 +33,12 @@ final class Configuration
33
33
*/
34
34
public$instantiator;
35
35
36
-
/** @var \Closure():self|self|null */
37
-
privatestatic\Closure|self|null$instance = null;
36
+
/**
37
+
* This property is only filled if the PHPUnit extension is used!
38
+
*/
39
+
privatebool$bootedForDataProvider = false;
40
+
41
+
privatestatic ?self$instance = null;
38
42
39
43
/**
40
44
* @param InstantiatorCallable $instantiator
@@ -66,13 +70,18 @@ public function assertPersistanceEnabled(): void
66
70
}
67
71
}
68
72
73
+
publicfunctioninADataProvider(): bool
74
+
{
75
+
return$this->bootedForDataProvider;
76
+
}
77
+
69
78
publicstaticfunctioninstance(): self
70
79
{
71
80
if (!self::$instance) {
72
-
thrownewFoundryNotBooted('Foundry is not yet booted. Ensure ZenstruckFoundryBundle is enabled. If in a test, ensure your TestCase has the Factories trait.');
parent::__construct('Foundry is not yet booted. Ensure ZenstruckFoundryBundle is enabled. If in a test, ensure your TestCase has the Factories trait.');
* "false === $configuration->inADataProvider()" would also mean that the PHPUnit extension is NOT used
374
+
* so a `FoundryNotBooted` exception would be thrown if we actually are in a data provider.
375
+
*/
376
+
if (!$configuration->inADataProvider()) {
377
+
return;
378
+
}
379
+
380
+
if (
381
+
!$configuration->isPersistenceAvailable()
382
+
|| $thisinstanceof PersistentProxyObjectFactory
383
+
) {
384
+
return;
385
+
}
386
+
387
+
thrownew \LogicException(\sprintf('Cannot create object in a data provider for non-proxy factories. Transform your factory into a "%s", or call "create()" method in the test. See https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#phpunit-data-providers', PersistentProxyObjectFactory::class));
0 commit comments