Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UPGRADE-8.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Config
* Remove support for accessing the internal scope of the loader in PHP config files, use only its public API instead
* Add argument `$singular` to `NodeBuilder::arrayNode()`
* Add argument `$info` to `ArrayNodeDefinition::canBeDisabled()` and `canBeEnabled()`
* Ensure configuration nodes do not have both `isRequired()` and `defaultValue()`

Console
-------
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Config/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CHANGELOG
* Remove support for accessing the internal scope of the loader in PHP config files, use only its public API instead
* Add argument `$singular` to `NodeBuilder::arrayNode()`
* Add argument `$info` to `ArrayNodeDefinition::canBeDisabled()` and `canBeEnabled()`
* Ensure configuration nodes do not have both `isRequired()` and `defaultValue()`

7.4
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ public function getNode(bool $forceRootNode = false): NodeInterface
public function defaultValue(mixed $value): static
{
if ($this->required) {
// throw new InvalidDefinitionException(sprintf('The node "%s" cannot be required and have a default value.', $this->name));
trigger_deprecation('symfony/config', '7.4', 'Setting a default value to a required node is deprecated. Remove the default value from the node "%s" or make it optional.', $this->name);
throw new InvalidDefinitionException(\sprintf('The node "%s" cannot be required and have a default value.', $this->name));
}

$this->default = true;
Expand All @@ -197,8 +196,7 @@ public function defaultValue(mixed $value): static
public function isRequired(): static
{
if ($this->default) {
// throw new InvalidDefinitionException(sprintf('The node "%s" cannot be required and have a default value.', $this->name));
trigger_deprecation('symfony/config', '7.4', 'Flagging a node with a default value as required is deprecated. Remove the default from node "%s" or make it optional.', $this->name);
throw new InvalidDefinitionException(\sprintf('The node "%s" cannot be required and have a default value.', $this->name));
}

$this->required = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
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;
Expand Down Expand Up @@ -76,32 +74,26 @@ public function testUnknownPackageThrowsException()
$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.');
$this->expectException(InvalidDefinitionException::class);
$this->expectExceptionMessage('The node "foo" cannot be required and have a default value.');

$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.');
$this->expectException(InvalidDefinitionException::class);
$this->expectExceptionMessage('The node "foo" cannot be required and have a default value.');

$node->isRequired()->defaultValue($defaultValue);
}
Expand Down
Loading