Skip to content

Commit d50c74d

Browse files
committed
[OptionsResolver] Ensure remove() also unsets deprecation status
1 parent 4433ffc commit d50c74d

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/Symfony/Component/OptionsResolver/OptionsResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ public function remove(string|array $optionNames): static
803803

804804
foreach ((array) $optionNames as $option) {
805805
unset($this->defined[$option], $this->defaults[$option], $this->required[$option], $this->resolved[$option]);
806-
unset($this->lazy[$option], $this->normalizers[$option], $this->allowedTypes[$option], $this->allowedValues[$option], $this->info[$option]);
806+
unset($this->lazy[$option], $this->normalizers[$option], $this->allowedTypes[$option], $this->allowedValues[$option], $this->info[$option], $this->deprecated[$option]);
807807
}
808808

809809
return $this;

src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,4 +2566,37 @@ public function testPrototypeDefinition()
25662566

25672567
$this->assertSame($expectedOptions, $actualOptions);
25682568
}
2569+
2570+
public function testRemoveAlsoRemovesDeprecation()
2571+
{
2572+
$this->resolver->setDefined('foo');
2573+
$this->resolver->setDeprecated('foo', 'vendor/package', '1.0');
2574+
2575+
$this->assertTrue($this->resolver->isDeprecated('foo'));
2576+
2577+
// Remove the option
2578+
$this->resolver->remove('foo');
2579+
2580+
// Assert the deprecation is also gone
2581+
$this->assertFalse($this->resolver->isDeprecated('foo'));
2582+
2583+
// Re-define it without deprecation (this should not fail)
2584+
$this->resolver->setDefault('foo', 'bar');
2585+
$this->assertFalse($this->resolver->isDeprecated('foo'));
2586+
2587+
// Make sure no deprecation warning is triggered
2588+
$count = 0;
2589+
set_error_handler(function (int $type) use (&$count) {
2590+
if (\E_USER_DEPRECATED === $type) {
2591+
++$count;
2592+
}
2593+
2594+
return false;
2595+
});
2596+
2597+
$this->resolver->resolve(['foo' => 'value']);
2598+
$this->assertSame(0, $count);
2599+
2600+
restore_error_handler();
2601+
}
25692602
}

0 commit comments

Comments
 (0)