Skip to content

Commit

Permalink
refactor: deprecate config auto_refresh_proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
nikophil committed Nov 24, 2023
1 parent 73cd6a9 commit 047d525
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 0 additions & 2 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
1 change: 1 addition & 0 deletions tests/Functional/FactoryDoctrineCascadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
Expand Down
3 changes: 3 additions & 0 deletions tests/Functional/ProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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
{
Expand All @@ -232,6 +234,7 @@ public function can_enable_auto_refresh_proxies(): void

/**
* @test
* @group legacy
*/
public function can_disable_auto_refresh_proxies(): void
{
Expand Down

0 comments on commit 047d525

Please sign in to comment.