diff --git a/src/Bundle/DependencyInjection/Configuration.php b/src/Bundle/DependencyInjection/Configuration.php index 1b4d1ca86..8350ee53f 100644 --- a/src/Bundle/DependencyInjection/Configuration.php +++ b/src/Bundle/DependencyInjection/Configuration.php @@ -29,6 +29,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->booleanNode('auto_refresh_proxies') ->info('Whether to auto-refresh proxies by default (https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#auto-refresh)') ->defaultNull() + ->setDeprecated('zenstruck/foundry', '1.37.0', 'Configuration "zenstruck_foundry.auto_refresh_proxies" is deprecated and will be automatically set to true in 2.0.') ->end() ->arrayNode('faker') ->addDefaultsIfNotSet() diff --git a/src/Bundle/DependencyInjection/ZenstruckFoundryExtension.php b/src/Bundle/DependencyInjection/ZenstruckFoundryExtension.php index 1e491b552..cce589e5a 100644 --- a/src/Bundle/DependencyInjection/ZenstruckFoundryExtension.php +++ b/src/Bundle/DependencyInjection/ZenstruckFoundryExtension.php @@ -52,7 +52,7 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container $this->configureDatabaseResetter($mergedConfig, $container); $this->configureMakeFactory($mergedConfig['make_factory'], $container, $loader); - if (true === $mergedConfig['auto_refresh_proxies']) { + if (true === ($mergedConfig['auto_refresh_proxies'] ?? true)) { $container->getDefinition('.zenstruck_foundry.configuration')->addMethodCall('enableDefaultProxyAutoRefresh'); } elseif (false === $mergedConfig['auto_refresh_proxies']) { $container->getDefinition('.zenstruck_foundry.configuration')->addMethodCall('disableDefaultProxyAutoRefresh'); diff --git a/src/Configuration.php b/src/Configuration.php index 8faf1f308..9ec1e20df 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -85,8 +85,6 @@ public function defaultProxyAutoRefresh(): bool } if (null === $this->defaultProxyAutoRefresh) { - trigger_deprecation('zenstruck\foundry', '1.9', 'Not explicitly configuring the default proxy auto-refresh is deprecated and will default to "true" in 2.0. Use "zenstruck_foundry.auto_refresh_proxies" in the bundle config or TestState::enableDefaultProxyAutoRefresh()/disableDefaultProxyAutoRefresh().'); - $this->defaultProxyAutoRefresh = false; } diff --git a/tests/Fixtures/Kernel.php b/tests/Fixtures/Kernel.php index ddaa8474f..f9b61586b 100644 --- a/tests/Fixtures/Kernel.php +++ b/tests/Fixtures/Kernel.php @@ -162,7 +162,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load } if (\getenv('USE_FOUNDRY_BUNDLE')) { - $foundryConfig = ['auto_refresh_proxies' => false]; + $foundryConfig = []; if ($this->defaultMakeFactoryNamespace) { $foundryConfig['make_factory'] = ['default_namespace' => $this->defaultMakeFactoryNamespace]; } diff --git a/tests/Functional/FactoryDoctrineCascadeTest.php b/tests/Functional/FactoryDoctrineCascadeTest.php index 551290e45..337a19abd 100644 --- a/tests/Functional/FactoryDoctrineCascadeTest.php +++ b/tests/Functional/FactoryDoctrineCascadeTest.php @@ -24,6 +24,7 @@ use Zenstruck\Foundry\Tests\Fixtures\Entity\Cascade\Variant; use function Zenstruck\Foundry\Persistence\persistent_factory; +use function Zenstruck\Foundry\Persistence\proxy_factory; /** * @author Kevin Bond diff --git a/tests/Functional/ProxyTest.php b/tests/Functional/ProxyTest.php index 2e6d18139..0c62b2f32 100644 --- a/tests/Functional/ProxyTest.php +++ b/tests/Functional/ProxyTest.php @@ -136,6 +136,7 @@ public function can_force_set_and_save(): void public function can_force_set_multiple_fields(): void { $post = $this->postFactoryClass()::createOne(['title' => 'old title', 'body' => 'old body']); + $post->_disableAutoRefresh(); $this->assertSame('old title', $post->getTitle()); $this->assertSame('old body', $post->getBody()); @@ -248,6 +249,7 @@ public function without_auto_refresh_solves_the_auto_refresh_problem(): void public function without_auto_refresh_does_not_enable_auto_refresh_if_it_was_disabled_originally(): void { $post = $this->postFactoryClass()::createOne(['title' => 'old title', 'body' => 'old body']); + $post->_disableAutoRefresh(); $this->assertSame('old title', $post->getTitle()); $this->assertSame('old body', $post->getBody()); @@ -274,6 +276,7 @@ public function without_auto_refresh_does_not_enable_auto_refresh_if_it_was_disa public function without_auto_refresh_keeps_disabled_if_originally_disabled(): void { $post = $this->postFactoryClass()::createOne(['title' => 'old title', 'body' => 'old body']); + $post->_disableAutoRefresh(); $this->assertSame('old title', $post->getTitle()); $this->assertSame('old body', $post->getBody()); diff --git a/tests/Unit/Bundle/DependencyInjection/ZenstruckFoundryExtensionTest.php b/tests/Unit/Bundle/DependencyInjection/ZenstruckFoundryExtensionTest.php index cc6706f70..cf9601174 100644 --- a/tests/Unit/Bundle/DependencyInjection/ZenstruckFoundryExtensionTest.php +++ b/tests/Unit/Bundle/DependencyInjection/ZenstruckFoundryExtensionTest.php @@ -45,7 +45,8 @@ public function default_config(): void $this->assertContainerBuilderHasServiceDefinitionWithMethodCall('.zenstruck_foundry.configuration', 'setManagerRegistry', ['.zenstruck_foundry.chain_manager_registry']); $this->assertContainerBuilderHasServiceDefinitionWithMethodCall('.zenstruck_foundry.configuration', 'setStoryManager', ['.zenstruck_foundry.story_manager']); $this->assertContainerBuilderHasServiceDefinitionWithMethodCall('.zenstruck_foundry.configuration', 'setModelFactoryManager', ['.zenstruck_foundry.model_factory_manager']); - $this->assertCount(5, $this->container->findDefinition('.zenstruck_foundry.configuration')->getMethodCalls()); + $this->assertCount(6, $this->container->findDefinition('.zenstruck_foundry.configuration')->getMethodCalls()); + $this->assertContainerBuilderHasServiceDefinitionWithMethodCall('.zenstruck_foundry.configuration', 'enableDefaultProxyAutoRefresh', []); $this->assertTrue($this->container->getDefinition('.zenstruck_foundry.configuration')->isPublic()); $this->assertContainerBuilderHasService('.zenstruck_foundry.default_instantiator', Instantiator::class); $this->assertEmpty($this->container->getDefinition('.zenstruck_foundry.default_instantiator')->getMethodCalls()); @@ -220,6 +221,7 @@ public function cannot_configure_always_force_properties_if_using_custom_instant /** * @test + * @group legacy */ public function can_enable_auto_refresh_proxies(): void { @@ -232,6 +234,7 @@ public function can_enable_auto_refresh_proxies(): void /** * @test + * @group legacy */ public function can_disable_auto_refresh_proxies(): void {