Skip to content

Commit

Permalink
Merge branch '5.1' into 5.2
Browse files Browse the repository at this point in the history
* 5.1:
  Use createMock() and use import instead of FQCN
  • Loading branch information
nicolas-grekas committed Jan 27, 2021
2 parents deef133 + 96cc8f6 commit 50e0e13
Show file tree
Hide file tree
Showing 21 changed files with 107 additions and 74 deletions.
3 changes: 2 additions & 1 deletion Tests/Definition/ArrayNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Config\Definition\ArrayNode;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\Definition\Exception\InvalidTypeException;
use Symfony\Component\Config\Definition\ScalarNode;

class ArrayNodeTest extends TestCase
Expand All @@ -23,7 +24,7 @@ class ArrayNodeTest extends TestCase

public function testNormalizeThrowsExceptionWhenFalseIsNotAllowed()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidTypeException::class);
$this->expectException(InvalidTypeException::class);
$node = new ArrayNode('root');
$node->normalize(false);
}
Expand Down
3 changes: 2 additions & 1 deletion Tests/Definition/BooleanNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\BooleanNode;
use Symfony\Component\Config\Definition\Exception\InvalidTypeException;

class BooleanNodeTest extends TestCase
{
Expand Down Expand Up @@ -51,7 +52,7 @@ public function getValidValues()
*/
public function testNormalizeThrowsExceptionOnInvalidValues($value)
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidTypeException::class);
$this->expectException(InvalidTypeException::class);
$node = new BooleanNode('test');
$node->normalize($value);
}
Expand Down
8 changes: 5 additions & 3 deletions Tests/Definition/Builder/ArrayNodeDefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
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\Exception\InvalidConfigurationException;
use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\Definition\PrototypedArrayNode;

class ArrayNodeDefinitionTest extends TestCase
{
Expand Down Expand Up @@ -155,8 +157,8 @@ public function testNestedPrototypedArrayNodes()
;
$node = $nodeDefinition->getNode();

$this->assertInstanceOf(\Symfony\Component\Config\Definition\PrototypedArrayNode::class, $node);
$this->assertInstanceOf(\Symfony\Component\Config\Definition\PrototypedArrayNode::class, $node->getPrototype());
$this->assertInstanceOf(PrototypedArrayNode::class, $node);
$this->assertInstanceOf(PrototypedArrayNode::class, $node->getPrototype());
}

public function testEnabledNodeDefaults()
Expand Down Expand Up @@ -320,7 +322,7 @@ public function testRequiresAtLeastOneElement()

public function testCannotBeEmpty()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('The path "root" should have at least 1 element(s) defined.');
$node = new ArrayNodeDefinition('root');
$node
Expand Down
3 changes: 2 additions & 1 deletion Tests/Definition/Builder/BooleanNodeDefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition;
use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException;

class BooleanNodeDefinitionTest extends TestCase
{
public function testCannotBeEmptyThrowsAnException()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidDefinitionException::class);
$this->expectException(InvalidDefinitionException::class);
$this->expectExceptionMessage('->cannotBeEmpty() is not applicable to BooleanNodeDefinition.');
$def = new BooleanNodeDefinition('foo');
$def->cannotBeEmpty();
Expand Down
3 changes: 2 additions & 1 deletion Tests/Definition/Builder/ExprBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Builder\ExprBuilder;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;

class ExprBuilderTest extends TestCase
{
Expand Down Expand Up @@ -167,7 +168,7 @@ public function castToArrayValues()

public function testThenInvalid()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$test = $this->getTestBuilder()
->ifString()
->thenInvalid('Invalid value')
Expand Down
6 changes: 4 additions & 2 deletions Tests/Definition/Builder/NodeBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace Symfony\Component\Config\Tests\Definition\Builder;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Builder\FloatNodeDefinition;
use Symfony\Component\Config\Definition\Builder\IntegerNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeBuilder as BaseNodeBuilder;
use Symfony\Component\Config\Definition\Builder\VariableNodeDefinition as BaseVariableNodeDefinition;

Expand Down Expand Up @@ -79,10 +81,10 @@ public function testNumericNodeCreation()
$builder = new BaseNodeBuilder();

$node = $builder->integerNode('foo')->min(3)->max(5);
$this->assertInstanceOf(\Symfony\Component\Config\Definition\Builder\IntegerNodeDefinition::class, $node);
$this->assertInstanceOf(IntegerNodeDefinition::class, $node);

$node = $builder->floatNode('bar')->min(3.0)->max(5.0);
$this->assertInstanceOf(\Symfony\Component\Config\Definition\Builder\FloatNodeDefinition::class, $node);
$this->assertInstanceOf(FloatNodeDefinition::class, $node);
}
}

Expand Down
12 changes: 7 additions & 5 deletions Tests/Definition/Builder/NumericNodeDefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Builder\FloatNodeDefinition;
use Symfony\Component\Config\Definition\Builder\IntegerNodeDefinition;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException;

class NumericNodeDefinitionTest extends TestCase
{
Expand All @@ -35,15 +37,15 @@ public function testIncoherentMaxAssertion()

public function testIntegerMinAssertion()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('The value 4 is too small for path "foo". Should be greater than or equal to 5');
$def = new IntegerNodeDefinition('foo');
$def->min(5)->getNode()->finalize(4);
}

public function testIntegerMaxAssertion()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('The value 4 is too big for path "foo". Should be less than or equal to 3');
$def = new IntegerNodeDefinition('foo');
$def->max(3)->getNode()->finalize(4);
Expand All @@ -58,15 +60,15 @@ public function testIntegerValidMinMaxAssertion()

public function testFloatMinAssertion()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('The value 400 is too small for path "foo". Should be greater than or equal to 500');
$def = new FloatNodeDefinition('foo');
$def->min(5E2)->getNode()->finalize(4e2);
}

public function testFloatMaxAssertion()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('The value 4.3 is too big for path "foo". Should be less than or equal to 0.3');
$def = new FloatNodeDefinition('foo');
$def->max(0.3)->getNode()->finalize(4.3);
Expand All @@ -81,7 +83,7 @@ public function testFloatValidMinMaxAssertion()

public function testCannotBeEmptyThrowsAnException()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidDefinitionException::class);
$this->expectException(InvalidDefinitionException::class);
$this->expectExceptionMessage('->cannotBeEmpty() is not applicable to NumericNodeDefinition.');
$def = new IntegerNodeDefinition('foo');
$def->cannotBeEmpty();
Expand Down
30 changes: 18 additions & 12 deletions Tests/Definition/Builder/TreeBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@
namespace Symfony\Component\Config\Tests\Definition\Builder;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\BaseNode;
use Symfony\Component\Config\Definition\BooleanNode;
use Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Tests\Fixtures\BarNode;
use Symfony\Component\Config\Tests\Fixtures\Builder\BarNodeDefinition;
use Symfony\Component\Config\Tests\Fixtures\Builder\NodeBuilder as CustomNodeBuilder;
use Symfony\Component\Config\Tests\Fixtures\Builder\VariableNodeDefinition;

class TreeBuilderTest extends TestCase
{
Expand All @@ -23,11 +29,11 @@ public function testUsingACustomNodeBuilder()

$nodeBuilder = $builder->getRootNode()->children();

$this->assertInstanceOf(\Symfony\Component\Config\Tests\Fixtures\Builder\NodeBuilder::class, $nodeBuilder);
$this->assertInstanceOf(CustomNodeBuilder::class, $nodeBuilder);

$nodeBuilder = $nodeBuilder->arrayNode('deeper')->children();

$this->assertInstanceOf(\Symfony\Component\Config\Tests\Fixtures\Builder\NodeBuilder::class, $nodeBuilder);
$this->assertInstanceOf(CustomNodeBuilder::class, $nodeBuilder);
}

public function testOverrideABuiltInNodeType()
Expand All @@ -36,7 +42,7 @@ public function testOverrideABuiltInNodeType()

$definition = $builder->getRootNode()->children()->variableNode('variable');

$this->assertInstanceOf(\Symfony\Component\Config\Tests\Fixtures\Builder\VariableNodeDefinition::class, $definition);
$this->assertInstanceOf(VariableNodeDefinition::class, $definition);
}

public function testAddANodeType()
Expand All @@ -45,7 +51,7 @@ public function testAddANodeType()

$definition = $builder->getRootNode()->children()->barNode('variable');

$this->assertInstanceOf(\Symfony\Component\Config\Tests\Fixtures\Builder\BarNodeDefinition::class, $definition);
$this->assertInstanceOf(BarNodeDefinition::class, $definition);
}

public function testCreateABuiltInNodeTypeWithACustomNodeBuilder()
Expand All @@ -54,7 +60,7 @@ public function testCreateABuiltInNodeTypeWithACustomNodeBuilder()

$definition = $builder->getRootNode()->children()->booleanNode('boolean');

$this->assertInstanceOf(\Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition::class, $definition);
$this->assertInstanceOf(BooleanNodeDefinition::class, $definition);
}

public function testPrototypedArrayNodeUseTheCustomNodeBuilder()
Expand All @@ -64,7 +70,7 @@ public function testPrototypedArrayNodeUseTheCustomNodeBuilder()
$root = $builder->getRootNode();
$root->prototype('bar')->end();

$this->assertInstanceOf(\Symfony\Component\Config\Tests\Fixtures\BarNode::class, $root->getNode(true)->getPrototype());
$this->assertInstanceOf(BarNode::class, $root->getNode(true)->getPrototype());
}

public function testAnExtendedNodeBuilderGetsPropagatedToTheChildren()
Expand All @@ -86,11 +92,11 @@ public function testAnExtendedNodeBuilderGetsPropagatedToTheChildren()
$node = $builder->buildTree();
$children = $node->getChildren();

$this->assertInstanceOf(\Symfony\Component\Config\Definition\BooleanNode::class, $children['foo']);
$this->assertInstanceOf(BooleanNode::class, $children['foo']);

$childChildren = $children['child']->getChildren();

$this->assertInstanceOf(\Symfony\Component\Config\Definition\BooleanNode::class, $childChildren['foo']);
$this->assertInstanceOf(BooleanNode::class, $childChildren['foo']);
}

public function testDefinitionInfoGetsTransferredToNode()
Expand Down Expand Up @@ -147,14 +153,14 @@ public function testDefaultPathSeparatorIsDot()
$children = $node->getChildren();

$this->assertArrayHasKey('foo', $children);
$this->assertInstanceOf(\Symfony\Component\Config\Definition\BaseNode::class, $children['foo']);
$this->assertInstanceOf(BaseNode::class, $children['foo']);
$this->assertSame('propagation.foo', $children['foo']->getPath());

$this->assertArrayHasKey('child', $children);
$childChildren = $children['child']->getChildren();

$this->assertArrayHasKey('foo', $childChildren);
$this->assertInstanceOf(\Symfony\Component\Config\Definition\BaseNode::class, $childChildren['foo']);
$this->assertInstanceOf(BaseNode::class, $childChildren['foo']);
$this->assertSame('propagation.child.foo', $childChildren['foo']->getPath());
}

Expand All @@ -178,14 +184,14 @@ public function testPathSeparatorIsPropagatedToChildren()
$children = $node->getChildren();

$this->assertArrayHasKey('foo', $children);
$this->assertInstanceOf(\Symfony\Component\Config\Definition\BaseNode::class, $children['foo']);
$this->assertInstanceOf(BaseNode::class, $children['foo']);
$this->assertSame('propagation/foo', $children['foo']->getPath());

$this->assertArrayHasKey('child', $children);
$childChildren = $children['child']->getChildren();

$this->assertArrayHasKey('foo', $childChildren);
$this->assertInstanceOf(\Symfony\Component\Config\Definition\BaseNode::class, $childChildren['foo']);
$this->assertInstanceOf(BaseNode::class, $childChildren['foo']);
$this->assertSame('propagation/child/foo', $childChildren['foo']->getPath());
}
}
3 changes: 2 additions & 1 deletion Tests/Definition/EnumNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\EnumNode;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;

class EnumNodeTest extends TestCase
{
Expand Down Expand Up @@ -49,7 +50,7 @@ public function testConstructionWithNullName()

public function testFinalizeWithInvalidValue()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('The value "foobar" is not allowed for path "foo". Permissible values: "foo", "bar"');
$node = new EnumNode('foo', null, ['foo', 'bar']);
$node->finalize('foobar');
Expand Down
3 changes: 2 additions & 1 deletion Tests/Definition/FloatNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Config\Tests\Definition;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Exception\InvalidTypeException;
use Symfony\Component\Config\Definition\FloatNode;

class FloatNodeTest extends TestCase
Expand Down Expand Up @@ -57,7 +58,7 @@ public function getValidValues()
*/
public function testNormalizeThrowsExceptionOnInvalidValues($value)
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidTypeException::class);
$this->expectException(InvalidTypeException::class);
$node = new FloatNode('test');
$node->normalize($value);
}
Expand Down
3 changes: 2 additions & 1 deletion Tests/Definition/IntegerNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Config\Tests\Definition;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Exception\InvalidTypeException;
use Symfony\Component\Config\Definition\IntegerNode;

class IntegerNodeTest extends TestCase
Expand Down Expand Up @@ -52,7 +53,7 @@ public function getValidValues()
*/
public function testNormalizeThrowsExceptionOnInvalidValues($value)
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidTypeException::class);
$this->expectException(InvalidTypeException::class);
$node = new IntegerNode('test');
$node->normalize($value);
}
Expand Down
6 changes: 4 additions & 2 deletions Tests/Definition/MergeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\Exception\ForbiddenOverwriteException;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;

class MergeTest extends TestCase
{
public function testForbiddenOverwrite()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\ForbiddenOverwriteException::class);
$this->expectException(ForbiddenOverwriteException::class);
$tb = new TreeBuilder('root', 'array');
$tree = $tb
->getRootNode()
Expand Down Expand Up @@ -92,7 +94,7 @@ public function testUnsetKey()

public function testDoesNotAllowNewKeysInSubsequentConfigs()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$tb = new TreeBuilder('root', 'array');
$tree = $tb
->getRootNode()
Expand Down
3 changes: 2 additions & 1 deletion Tests/Definition/NormalizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\Definition\NodeInterface;

class NormalizationTest extends TestCase
Expand Down Expand Up @@ -171,7 +172,7 @@ public function getNumericKeysTests()

public function testNonAssociativeArrayThrowsExceptionIfAttributeNotSet()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('The attribute "id" must be set for path "root.thing".');
$denormalized = [
'thing' => [
Expand Down
Loading

0 comments on commit 50e0e13

Please sign in to comment.