-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[Config] Deprecate setting a default value to a node that is required #62090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,9 +11,17 @@ | |
|
|
||
| namespace Symfony\Component\Config\Tests\Definition\Builder; | ||
|
|
||
| use PHPUnit\Framework\Attributes\DataProvider; | ||
| use PHPUnit\Framework\Attributes\Group; | ||
| use PHPUnit\Framework\Attributes\IgnoreDeprecations; | ||
| use PHPUnit\Framework\TestCase; | ||
| use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
| use Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition; | ||
| use Symfony\Component\Config\Definition\Builder\NodeDefinition; | ||
| use Symfony\Component\Config\Definition\Builder\ScalarNodeDefinition; | ||
| use Symfony\Component\Config\Definition\Builder\StringNodeDefinition; | ||
| use Symfony\Component\Config\Definition\Builder\VariableNodeDefinition; | ||
| use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException; | ||
|
|
||
| class NodeDefinitionTest extends TestCase | ||
| { | ||
|
|
@@ -60,10 +68,50 @@ public function testDocUrlWithoutPackage() | |
|
|
||
| public function testUnknownPackageThrowsException() | ||
| { | ||
| $node = new ArrayNodeDefinition('node'); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving |
||
|
|
||
| $this->expectException(\OutOfBoundsException::class); | ||
| $this->expectExceptionMessage('Package "phpunit/invalid" is not installed'); | ||
|
|
||
| $node = new ArrayNodeDefinition('node'); | ||
| $node->docUrl('https://example.com/doc/{package}/{version:major}.{version:minor}', 'phpunit/invalid'); | ||
| } | ||
|
|
||
| #[IgnoreDeprecations] | ||
| #[Group('legacy')] | ||
| #[DataProvider('provideDefinitionClassesAndDefaultValues')] | ||
| public function testIncoherentRequiredAndDefaultValue(string $class, mixed $defaultValue) | ||
| { | ||
| $node = new $class('foo'); | ||
| self::assertInstanceOf(NodeDefinition::class, $node); | ||
|
|
||
| // $this->expectException(InvalidDefinitionException::class); | ||
| // $this->expectExceptionMessage('The node "foo" cannot be required and have a default value.'); | ||
| $this->expectUserDeprecationMessage('Since symfony/config 7.4: Flagging a node with a default value as required is deprecated. Remove the default from node "foo" or make it optional.'); | ||
|
|
||
| $node->defaultValue($defaultValue)->isRequired(); | ||
| } | ||
|
|
||
| #[IgnoreDeprecations] | ||
| #[Group('legacy')] | ||
| #[DataProvider('provideDefinitionClassesAndDefaultValues')] | ||
| public function testIncoherentDefaultValueAndRequired(string $class, mixed $defaultValue) | ||
| { | ||
| $node = new $class('foo'); | ||
| self::assertInstanceOf(NodeDefinition::class, $node); | ||
|
|
||
| // $this->expectException(InvalidDefinitionException::class); | ||
| // $this->expectExceptionMessage('The node "foo" cannot be required and have a default value.'); | ||
| $this->expectUserDeprecationMessage('Since symfony/config 7.4: Setting a default value to a required node is deprecated. Remove the default value from the node "foo" or make it optional.'); | ||
|
|
||
| $node->isRequired()->defaultValue($defaultValue); | ||
| } | ||
|
|
||
| public static function provideDefinitionClassesAndDefaultValues() | ||
| { | ||
| yield [ArrayNodeDefinition::class, []]; | ||
| yield [ScalarNodeDefinition::class, null]; | ||
| yield [BooleanNodeDefinition::class, false]; | ||
| yield [StringNodeDefinition::class, 'default']; | ||
| yield [VariableNodeDefinition::class, 'default']; | ||
|
Comment on lines
+111
to
+115
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Testing various child classes as they could have different behaviors. |
||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's understandable like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I missed your comment and merged.
I used a different wording for the 8.0 branch: #62109