Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
347
vendor/symfony/config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php
vendored
Normal file
347
vendor/symfony/config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php
vendored
Normal file
|
@ -0,0 +1,347 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Config\Tests\Definition\Builder;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||
use Symfony\Component\Config\Definition\Builder\ScalarNodeDefinition;
|
||||
use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException;
|
||||
use Symfony\Component\Config\Definition\Processor;
|
||||
|
||||
class ArrayNodeDefinitionTest extends TestCase
|
||||
{
|
||||
public function testAppendingSomeNode()
|
||||
{
|
||||
$parent = new ArrayNodeDefinition('root');
|
||||
$child = new ScalarNodeDefinition('child');
|
||||
|
||||
$parent
|
||||
->children()
|
||||
->scalarNode('foo')->end()
|
||||
->scalarNode('bar')->end()
|
||||
->end()
|
||||
->append($child);
|
||||
|
||||
$this->assertCount(3, $this->getField($parent, 'children'));
|
||||
$this->assertContains($child, $this->getField($parent, 'children'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidDefinitionException
|
||||
* @dataProvider providePrototypeNodeSpecificCalls
|
||||
*/
|
||||
public function testPrototypeNodeSpecificOption($method, $args)
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
|
||||
\call_user_func_array(array($node, $method), $args);
|
||||
|
||||
$node->getNode();
|
||||
}
|
||||
|
||||
public function providePrototypeNodeSpecificCalls()
|
||||
{
|
||||
return array(
|
||||
array('defaultValue', array(array())),
|
||||
array('addDefaultChildrenIfNoneSet', array()),
|
||||
array('requiresAtLeastOneElement', array()),
|
||||
array('useAttributeAsKey', array('foo')),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidDefinitionException
|
||||
*/
|
||||
public function testConcreteNodeSpecificOption()
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$node
|
||||
->addDefaultsIfNotSet()
|
||||
->prototype('array')
|
||||
;
|
||||
$node->getNode();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidDefinitionException
|
||||
*/
|
||||
public function testPrototypeNodesCantHaveADefaultValueWhenUsingDefaultChildren()
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$node
|
||||
->defaultValue(array())
|
||||
->addDefaultChildrenIfNoneSet('foo')
|
||||
->prototype('array')
|
||||
;
|
||||
$node->getNode();
|
||||
}
|
||||
|
||||
public function testPrototypedArrayNodeDefaultWhenUsingDefaultChildren()
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$node
|
||||
->addDefaultChildrenIfNoneSet()
|
||||
->prototype('array')
|
||||
;
|
||||
$tree = $node->getNode();
|
||||
$this->assertEquals(array(array()), $tree->getDefaultValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providePrototypedArrayNodeDefaults
|
||||
*/
|
||||
public function testPrototypedArrayNodeDefault($args, $shouldThrowWhenUsingAttrAsKey, $shouldThrowWhenNotUsingAttrAsKey, $defaults)
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$node
|
||||
->addDefaultChildrenIfNoneSet($args)
|
||||
->prototype('array')
|
||||
;
|
||||
|
||||
try {
|
||||
$tree = $node->getNode();
|
||||
$this->assertFalse($shouldThrowWhenNotUsingAttrAsKey);
|
||||
$this->assertEquals($defaults, $tree->getDefaultValue());
|
||||
} catch (InvalidDefinitionException $e) {
|
||||
$this->assertTrue($shouldThrowWhenNotUsingAttrAsKey);
|
||||
}
|
||||
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$node
|
||||
->useAttributeAsKey('attr')
|
||||
->addDefaultChildrenIfNoneSet($args)
|
||||
->prototype('array')
|
||||
;
|
||||
|
||||
try {
|
||||
$tree = $node->getNode();
|
||||
$this->assertFalse($shouldThrowWhenUsingAttrAsKey);
|
||||
$this->assertEquals($defaults, $tree->getDefaultValue());
|
||||
} catch (InvalidDefinitionException $e) {
|
||||
$this->assertTrue($shouldThrowWhenUsingAttrAsKey);
|
||||
}
|
||||
}
|
||||
|
||||
public function providePrototypedArrayNodeDefaults()
|
||||
{
|
||||
return array(
|
||||
array(null, true, false, array(array())),
|
||||
array(2, true, false, array(array(), array())),
|
||||
array('2', false, true, array('2' => array())),
|
||||
array('foo', false, true, array('foo' => array())),
|
||||
array(array('foo'), false, true, array('foo' => array())),
|
||||
array(array('foo', 'bar'), false, true, array('foo' => array(), 'bar' => array())),
|
||||
);
|
||||
}
|
||||
|
||||
public function testNestedPrototypedArrayNodes()
|
||||
{
|
||||
$nodeDefinition = new ArrayNodeDefinition('root');
|
||||
$nodeDefinition
|
||||
->addDefaultChildrenIfNoneSet()
|
||||
->prototype('array')
|
||||
->prototype('array')
|
||||
;
|
||||
$node = $nodeDefinition->getNode();
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Config\Definition\PrototypedArrayNode', $node);
|
||||
$this->assertInstanceOf('Symfony\Component\Config\Definition\PrototypedArrayNode', $node->getPrototype());
|
||||
}
|
||||
|
||||
public function testEnabledNodeDefaults()
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$node
|
||||
->canBeEnabled()
|
||||
->children()
|
||||
->scalarNode('foo')->defaultValue('bar')->end()
|
||||
;
|
||||
|
||||
$this->assertEquals(array('enabled' => false, 'foo' => 'bar'), $node->getNode()->getDefaultValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getEnableableNodeFixtures
|
||||
*/
|
||||
public function testTrueEnableEnabledNode($expected, $config, $message)
|
||||
{
|
||||
$processor = new Processor();
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$node
|
||||
->canBeEnabled()
|
||||
->children()
|
||||
->scalarNode('foo')->defaultValue('bar')->end()
|
||||
;
|
||||
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$processor->process($node->getNode(), $config),
|
||||
$message
|
||||
);
|
||||
}
|
||||
|
||||
public function testCanBeDisabled()
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$node->canBeDisabled();
|
||||
|
||||
$this->assertTrue($this->getField($node, 'addDefaults'));
|
||||
$this->assertEquals(array('enabled' => false), $this->getField($node, 'falseEquivalent'));
|
||||
$this->assertEquals(array('enabled' => true), $this->getField($node, 'trueEquivalent'));
|
||||
$this->assertEquals(array('enabled' => true), $this->getField($node, 'nullEquivalent'));
|
||||
|
||||
$nodeChildren = $this->getField($node, 'children');
|
||||
$this->assertArrayHasKey('enabled', $nodeChildren);
|
||||
|
||||
$enabledNode = $nodeChildren['enabled'];
|
||||
$this->assertTrue($this->getField($enabledNode, 'default'));
|
||||
$this->assertTrue($this->getField($enabledNode, 'defaultValue'));
|
||||
}
|
||||
|
||||
public function testIgnoreExtraKeys()
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
|
||||
$this->assertFalse($this->getField($node, 'ignoreExtraKeys'));
|
||||
|
||||
$result = $node->ignoreExtraKeys();
|
||||
|
||||
$this->assertEquals($node, $result);
|
||||
$this->assertTrue($this->getField($node, 'ignoreExtraKeys'));
|
||||
}
|
||||
|
||||
public function testNormalizeKeys()
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
|
||||
$this->assertTrue($this->getField($node, 'normalizeKeys'));
|
||||
|
||||
$result = $node->normalizeKeys(false);
|
||||
|
||||
$this->assertEquals($node, $result);
|
||||
$this->assertFalse($this->getField($node, 'normalizeKeys'));
|
||||
}
|
||||
|
||||
public function testPrototypeVariable()
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$this->assertEquals($node->prototype('variable'), $node->variablePrototype());
|
||||
}
|
||||
|
||||
public function testPrototypeScalar()
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$this->assertEquals($node->prototype('scalar'), $node->scalarPrototype());
|
||||
}
|
||||
|
||||
public function testPrototypeBoolean()
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$this->assertEquals($node->prototype('boolean'), $node->booleanPrototype());
|
||||
}
|
||||
|
||||
public function testPrototypeInteger()
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$this->assertEquals($node->prototype('integer'), $node->integerPrototype());
|
||||
}
|
||||
|
||||
public function testPrototypeFloat()
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$this->assertEquals($node->prototype('float'), $node->floatPrototype());
|
||||
}
|
||||
|
||||
public function testPrototypeArray()
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$this->assertEquals($node->prototype('array'), $node->arrayPrototype());
|
||||
}
|
||||
|
||||
public function testPrototypeEnum()
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$this->assertEquals($node->prototype('enum'), $node->enumPrototype());
|
||||
}
|
||||
|
||||
public function getEnableableNodeFixtures()
|
||||
{
|
||||
return array(
|
||||
array(array('enabled' => true, 'foo' => 'bar'), array(true), 'true enables an enableable node'),
|
||||
array(array('enabled' => true, 'foo' => 'bar'), array(null), 'null enables an enableable node'),
|
||||
array(array('enabled' => true, 'foo' => 'bar'), array(array('enabled' => true)), 'An enableable node can be enabled'),
|
||||
array(array('enabled' => true, 'foo' => 'baz'), array(array('foo' => 'baz')), 'any configuration enables an enableable node'),
|
||||
array(array('enabled' => false, 'foo' => 'baz'), array(array('foo' => 'baz', 'enabled' => false)), 'An enableable node can be disabled'),
|
||||
array(array('enabled' => false, 'foo' => 'bar'), array(false), 'false disables an enableable node'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testRequiresAtLeastOneElement()
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$node
|
||||
->requiresAtLeastOneElement()
|
||||
->integerPrototype();
|
||||
|
||||
$node->getNode()->finalize(array(1));
|
||||
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Using Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition::cannotBeEmpty() at path "root" has no effect, consider requiresAtLeastOneElement() instead. In 4.0 both methods will behave the same.
|
||||
*/
|
||||
public function testCannotBeEmpty()
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$node
|
||||
->cannotBeEmpty()
|
||||
->integerPrototype();
|
||||
|
||||
$node->getNode()->finalize(array());
|
||||
}
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation ->cannotBeEmpty() is not applicable to concrete nodes at path "root". In 4.0 it will throw an exception.
|
||||
*/
|
||||
public function testCannotBeEmptyOnConcreteNode()
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$node->cannotBeEmpty();
|
||||
|
||||
$node->getNode()->finalize(array());
|
||||
}
|
||||
|
||||
protected function getField($object, $field)
|
||||
{
|
||||
$reflection = new \ReflectionProperty($object, $field);
|
||||
$reflection->setAccessible(true);
|
||||
|
||||
return $reflection->getValue($object);
|
||||
}
|
||||
}
|
39
vendor/symfony/config/Tests/Definition/Builder/BooleanNodeDefinitionTest.php
vendored
Normal file
39
vendor/symfony/config/Tests/Definition/Builder/BooleanNodeDefinitionTest.php
vendored
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Config\Tests\Definition\Builder;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition;
|
||||
|
||||
class BooleanNodeDefinitionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidDefinitionException
|
||||
* @expectedExceptionMessage ->cannotBeEmpty() is not applicable to BooleanNodeDefinition.
|
||||
*/
|
||||
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()));
|
||||
}
|
||||
}
|
77
vendor/symfony/config/Tests/Definition/Builder/EnumNodeDefinitionTest.php
vendored
Normal file
77
vendor/symfony/config/Tests/Definition/Builder/EnumNodeDefinitionTest.php
vendored
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Config\Tests\Definition\Builder;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\Definition\Builder\EnumNodeDefinition;
|
||||
|
||||
class EnumNodeDefinitionTest extends TestCase
|
||||
{
|
||||
public function testWithOneValue()
|
||||
{
|
||||
$def = new EnumNodeDefinition('foo');
|
||||
$def->values(array('foo'));
|
||||
|
||||
$node = $def->getNode();
|
||||
$this->assertEquals(array('foo'), $node->getValues());
|
||||
}
|
||||
|
||||
public function testWithOneDistinctValue()
|
||||
{
|
||||
$def = new EnumNodeDefinition('foo');
|
||||
$def->values(array('foo', 'foo'));
|
||||
|
||||
$node = $def->getNode();
|
||||
$this->assertEquals(array('foo'), $node->getValues());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage You must call ->values() on enum nodes.
|
||||
*/
|
||||
public function testNoValuesPassed()
|
||||
{
|
||||
$def = new EnumNodeDefinition('foo');
|
||||
$def->getNode();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage ->values() must be called with at least one value.
|
||||
*/
|
||||
public function testWithNoValues()
|
||||
{
|
||||
$def = new EnumNodeDefinition('foo');
|
||||
$def->values(array());
|
||||
}
|
||||
|
||||
public function testGetNode()
|
||||
{
|
||||
$def = new EnumNodeDefinition('foo');
|
||||
$def->values(array('foo', 'bar'));
|
||||
|
||||
$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()));
|
||||
}
|
||||
}
|
270
vendor/symfony/config/Tests/Definition/Builder/ExprBuilderTest.php
vendored
Normal file
270
vendor/symfony/config/Tests/Definition/Builder/ExprBuilderTest.php
vendored
Normal file
|
@ -0,0 +1,270 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Config\Tests\Definition\Builder;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
|
||||
class ExprBuilderTest extends TestCase
|
||||
{
|
||||
public function testAlwaysExpression()
|
||||
{
|
||||
$test = $this->getTestBuilder()
|
||||
->always($this->returnClosure('new_value'))
|
||||
->end();
|
||||
|
||||
$this->assertFinalizedValueIs('new_value', $test);
|
||||
}
|
||||
|
||||
public function testIfTrueExpression()
|
||||
{
|
||||
$test = $this->getTestBuilder()
|
||||
->ifTrue()
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('new_value', $test, array('key' => true));
|
||||
|
||||
$test = $this->getTestBuilder()
|
||||
->ifTrue(function ($v) { return true; })
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('new_value', $test);
|
||||
|
||||
$test = $this->getTestBuilder()
|
||||
->ifTrue(function ($v) { return false; })
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('value', $test);
|
||||
}
|
||||
|
||||
public function testIfStringExpression()
|
||||
{
|
||||
$test = $this->getTestBuilder()
|
||||
->ifString()
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('new_value', $test);
|
||||
|
||||
$test = $this->getTestBuilder()
|
||||
->ifString()
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs(45, $test, array('key' => 45));
|
||||
}
|
||||
|
||||
public function testIfNullExpression()
|
||||
{
|
||||
$test = $this->getTestBuilder()
|
||||
->ifNull()
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('new_value', $test, array('key' => null));
|
||||
|
||||
$test = $this->getTestBuilder()
|
||||
->ifNull()
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('value', $test);
|
||||
}
|
||||
|
||||
public function testIfEmptyExpression()
|
||||
{
|
||||
$test = $this->getTestBuilder()
|
||||
->ifEmpty()
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('new_value', $test, array('key' => array()));
|
||||
|
||||
$test = $this->getTestBuilder()
|
||||
->ifEmpty()
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('value', $test);
|
||||
}
|
||||
|
||||
public function testIfArrayExpression()
|
||||
{
|
||||
$test = $this->getTestBuilder()
|
||||
->ifArray()
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('new_value', $test, array('key' => array()));
|
||||
|
||||
$test = $this->getTestBuilder()
|
||||
->ifArray()
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('value', $test);
|
||||
}
|
||||
|
||||
public function testIfInArrayExpression()
|
||||
{
|
||||
$test = $this->getTestBuilder()
|
||||
->ifInArray(array('foo', 'bar', 'value'))
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('new_value', $test);
|
||||
|
||||
$test = $this->getTestBuilder()
|
||||
->ifInArray(array('foo', 'bar'))
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('value', $test);
|
||||
}
|
||||
|
||||
public function testIfNotInArrayExpression()
|
||||
{
|
||||
$test = $this->getTestBuilder()
|
||||
->ifNotInArray(array('foo', 'bar'))
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('new_value', $test);
|
||||
|
||||
$test = $this->getTestBuilder()
|
||||
->ifNotInArray(array('foo', 'bar', 'value_from_config'))
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('new_value', $test);
|
||||
}
|
||||
|
||||
public function testThenEmptyArrayExpression()
|
||||
{
|
||||
$test = $this->getTestBuilder()
|
||||
->ifString()
|
||||
->thenEmptyArray()
|
||||
->end();
|
||||
$this->assertFinalizedValueIs(array(), $test);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider castToArrayValues
|
||||
*/
|
||||
public function testcastToArrayExpression($configValue, $expectedValue)
|
||||
{
|
||||
$test = $this->getTestBuilder()
|
||||
->castToArray()
|
||||
->end();
|
||||
$this->assertFinalizedValueIs($expectedValue, $test, array('key' => $configValue));
|
||||
}
|
||||
|
||||
public function castToArrayValues()
|
||||
{
|
||||
yield array('value', array('value'));
|
||||
yield array(-3.14, array(-3.14));
|
||||
yield array(null, array(null));
|
||||
yield array(array('value'), array('value'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
||||
*/
|
||||
public function testThenInvalid()
|
||||
{
|
||||
$test = $this->getTestBuilder()
|
||||
->ifString()
|
||||
->thenInvalid('Invalid value')
|
||||
->end();
|
||||
$this->finalizeTestBuilder($test);
|
||||
}
|
||||
|
||||
public function testThenUnsetExpression()
|
||||
{
|
||||
$test = $this->getTestBuilder()
|
||||
->ifString()
|
||||
->thenUnset()
|
||||
->end();
|
||||
$this->assertEquals(array(), $this->finalizeTestBuilder($test));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage You must specify an if part.
|
||||
*/
|
||||
public function testEndIfPartNotSpecified()
|
||||
{
|
||||
$this->getTestBuilder()->end();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage You must specify a then part.
|
||||
*/
|
||||
public function testEndThenPartNotSpecified()
|
||||
{
|
||||
$builder = $this->getTestBuilder();
|
||||
$builder->ifPart = 'test';
|
||||
$builder->end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a test treebuilder with a variable node, and init the validation.
|
||||
*
|
||||
* @return TreeBuilder
|
||||
*/
|
||||
protected function getTestBuilder()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
|
||||
return $builder
|
||||
->root('test')
|
||||
->children()
|
||||
->variableNode('key')
|
||||
->validate()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the validation process and finalize with the given config.
|
||||
*
|
||||
* @param TreeBuilder $testBuilder The tree builder to finalize
|
||||
* @param array $config The config you want to use for the finalization, if nothing provided
|
||||
* a simple array('key'=>'value') will be used
|
||||
*
|
||||
* @return array The finalized config values
|
||||
*/
|
||||
protected function finalizeTestBuilder($testBuilder, $config = null)
|
||||
{
|
||||
return $testBuilder
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->buildTree()
|
||||
->finalize(null === $config ? array('key' => 'value') : $config)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a closure that will return the given value.
|
||||
*
|
||||
* @param mixed $val The value that the closure must return
|
||||
*
|
||||
* @return \Closure
|
||||
*/
|
||||
protected function returnClosure($val)
|
||||
{
|
||||
return function ($v) use ($val) {
|
||||
return $val;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the given test builder, will return the given value.
|
||||
*
|
||||
* @param mixed $value The value to test
|
||||
* @param TreeBuilder $treeBuilder The tree builder to finalize
|
||||
* @param mixed $config The config values that new to be finalized
|
||||
*/
|
||||
protected function assertFinalizedValueIs($value, $treeBuilder, $config = null)
|
||||
{
|
||||
$this->assertEquals(array('key' => $value), $this->finalizeTestBuilder($treeBuilder, $config));
|
||||
}
|
||||
}
|
95
vendor/symfony/config/Tests/Definition/Builder/NodeBuilderTest.php
vendored
Normal file
95
vendor/symfony/config/Tests/Definition/Builder/NodeBuilderTest.php
vendored
Normal file
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Config\Tests\Definition\Builder;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\Definition\Builder\NodeBuilder as BaseNodeBuilder;
|
||||
use Symfony\Component\Config\Definition\Builder\VariableNodeDefinition as BaseVariableNodeDefinition;
|
||||
|
||||
class NodeBuilderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testThrowsAnExceptionWhenTryingToCreateANonRegisteredNodeType()
|
||||
{
|
||||
$builder = new BaseNodeBuilder();
|
||||
$builder->node('', 'foobar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testThrowsAnExceptionWhenTheNodeClassIsNotFound()
|
||||
{
|
||||
$builder = new BaseNodeBuilder();
|
||||
$builder
|
||||
->setNodeClass('noclasstype', '\\foo\\bar\\noclass')
|
||||
->node('', 'noclasstype');
|
||||
}
|
||||
|
||||
public function testAddingANewNodeType()
|
||||
{
|
||||
$class = __NAMESPACE__.'\\SomeNodeDefinition';
|
||||
|
||||
$builder = new BaseNodeBuilder();
|
||||
$node = $builder
|
||||
->setNodeClass('newtype', $class)
|
||||
->node('', 'newtype');
|
||||
|
||||
$this->assertInstanceOf($class, $node);
|
||||
}
|
||||
|
||||
public function testOverridingAnExistingNodeType()
|
||||
{
|
||||
$class = __NAMESPACE__.'\\SomeNodeDefinition';
|
||||
|
||||
$builder = new BaseNodeBuilder();
|
||||
$node = $builder
|
||||
->setNodeClass('variable', $class)
|
||||
->node('', 'variable');
|
||||
|
||||
$this->assertInstanceOf($class, $node);
|
||||
}
|
||||
|
||||
public function testNodeTypesAreNotCaseSensitive()
|
||||
{
|
||||
$builder = new BaseNodeBuilder();
|
||||
|
||||
$node1 = $builder->node('', 'VaRiAbLe');
|
||||
$node2 = $builder->node('', 'variable');
|
||||
|
||||
$this->assertInstanceOf(\get_class($node1), $node2);
|
||||
|
||||
$builder->setNodeClass('CuStOm', __NAMESPACE__.'\\SomeNodeDefinition');
|
||||
|
||||
$node1 = $builder->node('', 'CUSTOM');
|
||||
$node2 = $builder->node('', 'custom');
|
||||
|
||||
$this->assertInstanceOf(\get_class($node1), $node2);
|
||||
}
|
||||
|
||||
public function testNumericNodeCreation()
|
||||
{
|
||||
$builder = new BaseNodeBuilder();
|
||||
|
||||
$node = $builder->integerNode('foo')->min(3)->max(5);
|
||||
$this->assertInstanceOf('Symfony\Component\Config\Definition\Builder\IntegerNodeDefinition', $node);
|
||||
|
||||
$node = $builder->floatNode('bar')->min(3.0)->max(5.0);
|
||||
$this->assertInstanceOf('Symfony\Component\Config\Definition\Builder\FloatNodeDefinition', $node);
|
||||
}
|
||||
}
|
||||
|
||||
class SomeNodeDefinition extends BaseVariableNodeDefinition
|
||||
{
|
||||
}
|
104
vendor/symfony/config/Tests/Definition/Builder/NumericNodeDefinitionTest.php
vendored
Normal file
104
vendor/symfony/config/Tests/Definition/Builder/NumericNodeDefinitionTest.php
vendored
Normal file
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
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\IntegerNodeDefinition as NumericNodeDefinition;
|
||||
|
||||
class NumericNodeDefinitionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage You cannot define a min(4) as you already have a max(3)
|
||||
*/
|
||||
public function testIncoherentMinAssertion()
|
||||
{
|
||||
$def = new NumericNodeDefinition('foo');
|
||||
$def->max(3)->min(4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage You cannot define a max(2) as you already have a min(3)
|
||||
*/
|
||||
public function testIncoherentMaxAssertion()
|
||||
{
|
||||
$node = new NumericNodeDefinition('foo');
|
||||
$node->min(3)->max(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
||||
* @expectedExceptionMessage The value 4 is too small for path "foo". Should be greater than or equal to 5
|
||||
*/
|
||||
public function testIntegerMinAssertion()
|
||||
{
|
||||
$def = new IntegerNodeDefinition('foo');
|
||||
$def->min(5)->getNode()->finalize(4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
||||
* @expectedExceptionMessage The value 4 is too big for path "foo". Should be less than or equal to 3
|
||||
*/
|
||||
public function testIntegerMaxAssertion()
|
||||
{
|
||||
$def = new IntegerNodeDefinition('foo');
|
||||
$def->max(3)->getNode()->finalize(4);
|
||||
}
|
||||
|
||||
public function testIntegerValidMinMaxAssertion()
|
||||
{
|
||||
$def = new IntegerNodeDefinition('foo');
|
||||
$node = $def->min(3)->max(7)->getNode();
|
||||
$this->assertEquals(4, $node->finalize(4));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
||||
* @expectedExceptionMessage The value 400 is too small for path "foo". Should be greater than or equal to 500
|
||||
*/
|
||||
public function testFloatMinAssertion()
|
||||
{
|
||||
$def = new FloatNodeDefinition('foo');
|
||||
$def->min(5E2)->getNode()->finalize(4e2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
||||
* @expectedExceptionMessage The value 4.3 is too big for path "foo". Should be less than or equal to 0.3
|
||||
*/
|
||||
public function testFloatMaxAssertion()
|
||||
{
|
||||
$def = new FloatNodeDefinition('foo');
|
||||
$def->max(0.3)->getNode()->finalize(4.3);
|
||||
}
|
||||
|
||||
public function testFloatValidMinMaxAssertion()
|
||||
{
|
||||
$def = new FloatNodeDefinition('foo');
|
||||
$node = $def->min(3.0)->max(7e2)->getNode();
|
||||
$this->assertEquals(4.5, $node->finalize(4.5));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidDefinitionException
|
||||
* @expectedExceptionMessage ->cannotBeEmpty() is not applicable to NumericNodeDefinition.
|
||||
*/
|
||||
public function testCannotBeEmptyThrowsAnException()
|
||||
{
|
||||
$def = new NumericNodeDefinition('foo');
|
||||
$def->cannotBeEmpty();
|
||||
}
|
||||
}
|
134
vendor/symfony/config/Tests/Definition/Builder/TreeBuilderTest.php
vendored
Normal file
134
vendor/symfony/config/Tests/Definition/Builder/TreeBuilderTest.php
vendored
Normal file
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Config\Tests\Definition\Builder;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Tests\Fixtures\Builder\NodeBuilder as CustomNodeBuilder;
|
||||
|
||||
class TreeBuilderTest extends TestCase
|
||||
{
|
||||
public function testUsingACustomNodeBuilder()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$root = $builder->root('custom', 'array', new CustomNodeBuilder());
|
||||
|
||||
$nodeBuilder = $root->children();
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Config\Tests\Fixtures\Builder\NodeBuilder', $nodeBuilder);
|
||||
|
||||
$nodeBuilder = $nodeBuilder->arrayNode('deeper')->children();
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Config\Tests\Fixtures\Builder\NodeBuilder', $nodeBuilder);
|
||||
}
|
||||
|
||||
public function testOverrideABuiltInNodeType()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$root = $builder->root('override', 'array', new CustomNodeBuilder());
|
||||
|
||||
$definition = $root->children()->variableNode('variable');
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Config\Tests\Fixtures\Builder\VariableNodeDefinition', $definition);
|
||||
}
|
||||
|
||||
public function testAddANodeType()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$root = $builder->root('override', 'array', new CustomNodeBuilder());
|
||||
|
||||
$definition = $root->children()->barNode('variable');
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Config\Tests\Fixtures\Builder\BarNodeDefinition', $definition);
|
||||
}
|
||||
|
||||
public function testCreateABuiltInNodeTypeWithACustomNodeBuilder()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$root = $builder->root('builtin', 'array', new CustomNodeBuilder());
|
||||
|
||||
$definition = $root->children()->booleanNode('boolean');
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition', $definition);
|
||||
}
|
||||
|
||||
public function testPrototypedArrayNodeUseTheCustomNodeBuilder()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$root = $builder->root('override', 'array', new CustomNodeBuilder());
|
||||
|
||||
$root->prototype('bar')->end();
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Config\Tests\Fixtures\BarNode', $root->getNode(true)->getPrototype());
|
||||
}
|
||||
|
||||
public function testAnExtendedNodeBuilderGetsPropagatedToTheChildren()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
|
||||
$builder->root('propagation')
|
||||
->children()
|
||||
->setNodeClass('extended', 'Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition')
|
||||
->node('foo', 'extended')->end()
|
||||
->arrayNode('child')
|
||||
->children()
|
||||
->node('foo', 'extended')
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end();
|
||||
|
||||
$node = $builder->buildTree();
|
||||
$children = $node->getChildren();
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Config\Definition\BooleanNode', $children['foo']);
|
||||
|
||||
$childChildren = $children['child']->getChildren();
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Config\Definition\BooleanNode', $childChildren['foo']);
|
||||
}
|
||||
|
||||
public function testDefinitionInfoGetsTransferredToNode()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
|
||||
$builder->root('test')->info('root info')
|
||||
->children()
|
||||
->node('child', 'variable')->info('child info')->defaultValue('default')
|
||||
->end()
|
||||
->end();
|
||||
|
||||
$tree = $builder->buildTree();
|
||||
$children = $tree->getChildren();
|
||||
|
||||
$this->assertEquals('root info', $tree->getInfo());
|
||||
$this->assertEquals('child info', $children['child']->getInfo());
|
||||
}
|
||||
|
||||
public function testDefinitionExampleGetsTransferredToNode()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
|
||||
$builder->root('test')
|
||||
->example(array('key' => 'value'))
|
||||
->children()
|
||||
->node('child', 'variable')->info('child info')->defaultValue('default')->example('example')
|
||||
->end()
|
||||
->end();
|
||||
|
||||
$tree = $builder->buildTree();
|
||||
$children = $tree->getChildren();
|
||||
|
||||
$this->assertInternalType('array', $tree->getExample());
|
||||
$this->assertEquals('example', $children['child']->getExample());
|
||||
}
|
||||
}
|
Reference in a new issue