|
22 | 22 | * @internal |
23 | 23 | * @author Nicolas PHILIPPE <nikophil@gmail.com> |
24 | 24 | */ |
25 | | -final class FoundryExtension implements Runner\Extension\Extension |
26 | | -{ |
27 | | - public function bootstrap( |
28 | | - TextUI\Configuration\Configuration $configuration, |
29 | | - Runner\Extension\Facade $facade, |
30 | | - Runner\Extension\ParameterCollection $parameters, |
31 | | - ): void { |
32 | | - // shutdown Foundry if for some reason it has been booted before |
33 | | - if (Configuration::isBooted()) { |
34 | | - Configuration::shutdown(); |
| 25 | + |
| 26 | +if (interface_exists(Runner\Extension\Extension::class)) { |
| 27 | + final class FoundryExtension implements Runner\Extension\Extension |
| 28 | + { |
| 29 | + private static bool $enabled = false; |
| 30 | + |
| 31 | + public function bootstrap( |
| 32 | + TextUI\Configuration\Configuration $configuration, |
| 33 | + Runner\Extension\Facade $facade, |
| 34 | + Runner\Extension\ParameterCollection $parameters, |
| 35 | + ): void { |
| 36 | + // shutdown Foundry if for some reason it has been booted before |
| 37 | + if (Configuration::isBooted()) { |
| 38 | + Configuration::shutdown(); |
| 39 | + } |
| 40 | + |
| 41 | + $subscribers = [ |
| 42 | + new BuildStoryOnTestPrepared(), |
| 43 | + new EnableInMemoryBeforeTest(), |
| 44 | + new DisplayFakerSeedOnTestSuiteFinished(), |
| 45 | + new BootFoundryOnPreparationStarted(), |
| 46 | + new ShutdownFoundryOnTestFinished(), |
| 47 | + ]; |
| 48 | + |
| 49 | + if (ConstraintRequirement::from('>=11.4')->isSatisfiedBy(Runner\Version::id())) { |
| 50 | + // those deal with data provider events which can be useful only if PHPUnit >=11.4 is used |
| 51 | + $subscribers[] = new BootFoundryOnDataProviderMethodCalled(); |
| 52 | + $subscribers[] = new ShutdownFoundryOnDataProviderMethodFinished(); |
| 53 | + } |
| 54 | + |
| 55 | + $facade->registerSubscribers(...$subscribers); |
| 56 | + |
| 57 | + self::$enabled = true; |
35 | 58 | } |
36 | 59 |
|
37 | | - $subscribers = [ |
38 | | - new BuildStoryOnTestPrepared(), |
39 | | - new EnableInMemoryBeforeTest(), |
40 | | - new DisplayFakerSeedOnTestSuiteFinished(), |
41 | | - ]; |
| 60 | + public static function shouldBeEnabled(): bool |
| 61 | + { |
| 62 | + return !self::isEnabled() && ConstraintRequirement::from('>=10')->isSatisfiedBy(Runner\Version::id()); |
| 63 | + } |
42 | 64 |
|
43 | | - if (ConstraintRequirement::from('>=11.4')->isSatisfiedBy(Runner\Version::id())) { |
44 | | - // those deal with data provider events which can be useful only if PHPUnit >=11.4 is used |
45 | | - $subscribers[] = new BootFoundryOnDataProviderMethodCalled(); |
46 | | - $subscribers[] = new ShutdownFoundryOnDataProviderMethodFinished(); |
| 65 | + public static function isEnabled(): bool |
| 66 | + { |
| 67 | + return self::$enabled; |
| 68 | + } |
| 69 | + } |
| 70 | +} else { |
| 71 | + final class FoundryExtension |
| 72 | + { |
| 73 | + public static function shouldBeEnabled(): bool |
| 74 | + { |
| 75 | + return false; |
47 | 76 | } |
48 | 77 |
|
49 | | - $facade->registerSubscribers(...$subscribers); |
| 78 | + public static function isEnabled(): bool |
| 79 | + { |
| 80 | + return false; |
| 81 | + } |
50 | 82 | } |
51 | 83 | } |
0 commit comments