8000 Fix ability to deprecate a config node by chalasr · Pull Request #24083 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fix ability to deprecate a config node #24083

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 1 commit into from
Sep 4, 2017
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
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ protected function createNode()
$node->addEquivalentValue(false, $this->falseEquivalent);
$node->setPerformDeepMerging($this->performDeepMerging);
$node->setRequired($this->required);
$node->setDeprecated($this->deprecationMessage);
$node->setIgnoreExtraKeys($this->ignoreExtraKeys, $this->removeExtraKeys);
$node->setNormalizeKeys($this->normalizeKeys);

Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Config/Definition/VariableNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ protected function validateType($value)
*/
protected function finalizeValue($value)
{
if ($this->deprecationMessage) {
@trigger_error($this->getDeprecationMessage($this->getName(), $this->getPath()), E_USER_DEPRECATED);
}

if (!$this->allowEmptyValue && $this->isValueEmpty($value)) {
$ex = new InvalidConfigurationException(sprintf(
'The path "%s" cannot contain an empty value, but got %s.',
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,13 @@ public function testGetDefaultValueWithoutDefaultValue()
$node = new ArrayNode('foo');
$node->getDefaultValue();
}

public function testSetDeprecated()
{
$node = new ArrayNode('foo');
$node->setDeprecated('"%node%" is deprecated');

$this->assertTrue($node->isDeprecated());
$this->assertSame('"foo" is deprecated', $node->getDeprecationMessage($node->getName(), $node->getPath()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,20 @@ public function testRequiresAtLeastOneElement()
$this->addToAssertionCount(1);
}

public function testSetDeprecated()
{
$node = new ArrayNodeDefinition('root');
$node
->children()
->arrayNode('foo')->setDeprecated('The "%path%" node is deprecated.')->end()
->end()
;
$deprecatedNode = $node->getNode()->getChildren()['foo'];

$this->assertTrue($deprecatedNode->isDeprecated());
$this->assertSame('The "root.foo" node is deprecated.', $deprecatedNode->getDeprecationMessage($deprecatedNode->getName(), $deprecatedNode->getPath()));
}

/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage The path "root" should have at least 1 element(s) defined.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,15 @@ public function testCannotBeEmptyThrowsAnException()
$def = new BooleanNodeDefinition('foo');
$def->cannotBeEmpty();
}

public function testSetDeprecated()
{
$def = new BooleanNodeDefinition('foo');
$def->setDeprecated('The "%path%" node is deprecated.');

$node = $def->getNode();

$this->assertTrue($node->isDeprecated());
$this->assertSame('The "foo" node is deprecated.', $node->getDeprecationMessage($node->getName(), $node->getPath()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,16 @@ public function testGetNode()
$node = $def->getNode();
$this->assertEquals(array('foo', 'bar'), $node->getValues());
}

public function testSetDeprecated()
{
$def = new EnumNodeDefinition('foo');
$def->values(array('foo', 'bar'));
$def->setDeprecated('The "%path%" node is deprecated.');

$node = $def->getNode();

$this->assertTrue($node->isDeprecated());
$this->assertSame('The "foo" node is deprecated.', $def->getNode()->getDeprecationMessage($node->getName(), $node->getPath()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ public function getValidValues()
);
}

public function testSetDeprecated()
{
$node = new ScalarNode('foo');
$node->setDeprecated('"%node%" is deprecated');

$this->assertTrue($node->isDeprecated());
$this->assertSame('"foo" is deprecated', $node->getDeprecationMessage($node->getName(), $node->getPath()));
}

/**
* @dataProvider getInvalidValues
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidTypeException
Expand Down
0