Skip to content

Commit 7302641

Browse files
committed
feature #27667 [Form][OptionsResolver] Show deprecated options definition on debug:form command (yceruto)
This PR was merged into the 4.2-dev branch. Discussion ---------- [Form][OptionsResolver] Show deprecated options definition on debug:form command | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Next move after symfony/symfony#27277. It will look like this: Use `--show-deprecated` option to show form types with deprecated options (example): ![debug_types_with_deprecated_options](https://user-images.githubusercontent.com/2028198/41823977-970c7c98-77d6-11e8-9e97-30dcedc316ac.png) Use `--show-deprecated` option to show deprecated options of the given form type (example): ![debug_deprecated_options_from_type](https://user-images.githubusercontent.com/2028198/41823980-a4d6bd8e-77d6-11e8-95ed-39926ffd6235.png) Deprecated option (example): ![debug_deprecated_option_text](https://user-images.githubusercontent.com/2028198/41689091-04e6b7dc-74bd-11e8-87d0-90729eac4bb3.png) ![debug_deprecated_option_json](https://user-images.githubusercontent.com/2028198/41689105-142b5c5c-74bd-11e8-9232-1f30237bcf69.png) Commits ------- 87c209d741 Show deprecated options definition on debug:form command
2 parents ee5b9a9 + cdd37de commit 7302641

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

Debug/OptionsResolverIntrospector.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,14 @@ public function getNormalizer(string $option): \Closure
8787
{
8888
return \call_user_func($this->get, 'normalizers', $option, sprintf('No normalizer was set for the "%s" option.', $option));
8989
}
90+
91+
/**
92+
* @return string|\Closure
93+
*
94+
* @throws NoConfigurationException on no configured deprecation
95+
*/
96+
public function getDeprecationMessage(string $option)
97+
{
98+
return \call_user_func($this->get, 'deprecated', $option, sprintf('No deprecation was set for the "%s" option.', $option));
99+
}
90100
}

Tests/Debug/OptionsResolverIntrospectorTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,49 @@ public function testGetNormalizerThrowsOnNotDefinedOption()
200200
$debug = new OptionsResolverIntrospector($resolver);
201201
$this->assertSame('bar', $debug->getNormalizer('foo'));
202202
}
203+
204+
public function testGetDeprecationMessage()
205+
{
206+
$resolver = new OptionsResolver();
207+
$resolver->setDefined('foo');
208+
$resolver->setDeprecated('foo', 'The option "foo" is deprecated.');
209+
210+
$debug = new OptionsResolverIntrospector($resolver);
211+
$this->assertSame('The option "foo" is deprecated.', $debug->getDeprecationMessage('foo'));
212+
}
213+
214+
public function testGetClosureDeprecationMessage()
215+
{
216+
$resolver = new OptionsResolver();
217+
$resolver->setDefined('foo');
218+
$resolver->setDeprecated('foo', $closure = function ($value) {});
219+
220+
$debug = new OptionsResolverIntrospector($resolver);
221+
$this->assertSame($closure, $debug->getDeprecationMessage('foo'));
222+
}
223+
224+
/**
225+
* @expectedException \Symfony\Component\OptionsResolver\Exception\NoConfigurationException
226+
* @expectedExceptionMessage No deprecation was set for the "foo" option.
227+
*/
228+
public function testGetDeprecationMessageThrowsOnNoConfiguredValue()
229+
{
230+
$resolver = new OptionsResolver();
231+
$resolver->setDefined('foo');
232+
233+
$debug = new OptionsResolverIntrospector($resolver);
234+
$this->assertSame('bar', $debug->getDeprecationMessage('foo'));
235+
}
236+
237+
/**
238+
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
239+
* @expectedExceptionMessage The option "foo" does not exist.
240+
*/
241+
public function testGetDeprecationMessageThrowsOnNotDefinedOption()
242+
{
243+
$resolver = new OptionsResolver();
244+
245+
$debug = new OptionsResolverIntrospector($resolver);
246+
$this->assertSame('bar', $debug->getDeprecationMessage('foo'));
247+
}
203248
}

0 commit comments

Comments
 (0)