mirror of
https://github.com/wallabag/wallabag.git
synced 2025-09-05 18:41:02 +00:00
twig implementation
This commit is contained in:
parent
2b840e0cfb
commit
4f5b44bd3b
1418 changed files with 108207 additions and 1586 deletions
681
vendor/symfony/options-resolver/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php
vendored
Normal file
681
vendor/symfony/options-resolver/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php
vendored
Normal file
|
@ -0,0 +1,681 @@
|
|||
<?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\OptionsResolver\Tests;
|
||||
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
|
||||
class OptionsResolverTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var OptionsResolver
|
||||
*/
|
||||
private $resolver;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->resolver = new OptionsResolver();
|
||||
}
|
||||
|
||||
public function testResolve()
|
||||
{
|
||||
$this->resolver->setDefaults(array(
|
||||
'one' => '1',
|
||||
'two' => '2',
|
||||
));
|
||||
|
||||
$options = array(
|
||||
'two' => '20',
|
||||
);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'one' => '1',
|
||||
'two' => '20',
|
||||
), $this->resolver->resolve($options));
|
||||
}
|
||||
|
||||
public function testResolveLazy()
|
||||
{
|
||||
$this->resolver->setDefaults(array(
|
||||
'one' => '1',
|
||||
'two' => function (Options $options) {
|
||||
return '20';
|
||||
},
|
||||
));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'one' => '1',
|
||||
'two' => '20',
|
||||
), $this->resolver->resolve(array()));
|
||||
}
|
||||
|
||||
public function testResolveLazyDependencyOnOptional()
|
||||
{
|
||||
$this->resolver->setDefaults(array(
|
||||
'one' => '1',
|
||||
'two' => function (Options $options) {
|
||||
return $options['one'].'2';
|
||||
},
|
||||
));
|
||||
|
||||
$options = array(
|
||||
'one' => '10',
|
||||
);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'one' => '10',
|
||||
'two' => '102',
|
||||
), $this->resolver->resolve($options));
|
||||
}
|
||||
|
||||
public function testResolveLazyDependencyOnMissingOptionalWithoutDefault()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
$this->resolver->setOptional(array(
|
||||
'one',
|
||||
));
|
||||
|
||||
$this->resolver->setDefaults(array(
|
||||
'two' => function (Options $options) use ($test) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->assertFalse(isset($options['one']));
|
||||
|
||||
return '2';
|
||||
},
|
||||
));
|
||||
|
||||
$options = array(
|
||||
);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'two' => '2',
|
||||
), $this->resolver->resolve($options));
|
||||
}
|
||||
|
||||
public function testResolveLazyDependencyOnOptionalWithoutDefault()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
$this->resolver->setOptional(array(
|
||||
'one',
|
||||
));
|
||||
|
||||
$this->resolver->setDefaults(array(
|
||||
'two' => function (Options $options) use ($test) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->assertTrue(isset($options['one']));
|
||||
|
||||
return $options['one'].'2';
|
||||
},
|
||||
));
|
||||
|
||||
$options = array(
|
||||
'one' => '10',
|
||||
);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'one' => '10',
|
||||
'two' => '102',
|
||||
), $this->resolver->resolve($options));
|
||||
}
|
||||
|
||||
public function testResolveLazyDependencyOnRequired()
|
||||
{
|
||||
$this->resolver->setRequired(array(
|
||||
'one',
|
||||
));
|
||||
$this->resolver->setDefaults(array(
|
||||
'two' => function (Options $options) {
|
||||
return $options['one'].'2';
|
||||
},
|
||||
));
|
||||
|
||||
$options = array(
|
||||
'one' => '10',
|
||||
);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'one' => '10',
|
||||
'two' => '102',
|
||||
), $this->resolver->resolve($options));
|
||||
}
|
||||
|
||||
public function testResolveLazyReplaceDefaults()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
$this->resolver->setDefaults(array(
|
||||
'one' => function (Options $options) use ($test) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->fail('Previous closure should not be executed');
|
||||
},
|
||||
));
|
||||
|
||||
$this->resolver->replaceDefaults(array(
|
||||
'one' => function (Options $options, $previousValue) {
|
||||
return '1';
|
||||
},
|
||||
));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'one' => '1',
|
||||
), $this->resolver->resolve(array()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
|
||||
*/
|
||||
public function testResolveFailsIfNonExistingOption()
|
||||
{
|
||||
$this->resolver->setDefaults(array(
|
||||
'one' => '1',
|
||||
));
|
||||
|
||||
$this->resolver->setRequired(array(
|
||||
'two',
|
||||
));
|
||||
|
||||
$this->resolver->setOptional(array(
|
||||
'three',
|
||||
));
|
||||
|
||||
$this->resolver->resolve(array(
|
||||
'foo' => 'bar',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\MissingOptionsException
|
||||
*/
|
||||
public function testResolveFailsIfMissingRequiredOption()
|
||||
{
|
||||
$this->resolver->setRequired(array(
|
||||
'one',
|
||||
));
|
||||
|
||||
$this->resolver->setDefaults(array(
|
||||
'two' => '2',
|
||||
));
|
||||
|
||||
$this->resolver->resolve(array(
|
||||
'two' => '20',
|
||||
));
|
||||
}
|
||||
|
||||
public function testResolveSucceedsIfOptionValueAllowed()
|
||||
{
|
||||
$this->resolver->setDefaults(array(
|
||||
'one' => '1',
|
||||
));
|
||||
|
||||
$this->resolver->setAllowedValues(array(
|
||||
'one' => array('1', 'one'),
|
||||
));
|
||||
|
||||
$options = array(
|
||||
'one' => 'one',
|
||||
);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'one' => 'one',
|
||||
), $this->resolver->resolve($options));
|
||||
}
|
||||
|
||||
public function testResolveSucceedsIfOptionValueAllowed2()
|
||||
{
|
||||
$this->resolver->setDefaults(array(
|
||||
'one' => '1',
|
||||
'two' => '2',
|
||||
));
|
||||
|
||||
$this->resolver->setAllowedValues(array(
|
||||
'one' => '1',
|
||||
'two' => '2',
|
||||
));
|
||||
$this->resolver->addAllowedValues(array(
|
||||
'one' => 'one',
|
||||
'two' => 'two',
|
||||
));
|
||||
|
||||
$options = array(
|
||||
'one' => '1',
|
||||
'two' => 'two',
|
||||
);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'one' => '1',
|
||||
'two' => 'two',
|
||||
), $this->resolver->resolve($options));
|
||||
}
|
||||
|
||||
public function testResolveSucceedsIfOptionalWithAllowedValuesNotSet()
|
||||
{
|
||||
$this->resolver->setRequired(array(
|
||||
'one',
|
||||
));
|
||||
|
||||
$this->resolver->setOptional(array(
|
||||
'two',
|
||||
));
|
||||
|
||||
$this->resolver->setAllowedValues(array(
|
||||
'one' => array('1', 'one'),
|
||||
'two' => array('2', 'two'),
|
||||
));
|
||||
|
||||
$options = array(
|
||||
'one' => '1',
|
||||
);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'one' => '1',
|
||||
), $this->resolver->resolve($options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
|
||||
*/
|
||||
public function testResolveFailsIfOptionValueNotAllowed()
|
||||
{
|
||||
$this->resolver->setDefaults(array(
|
||||
'one' => '1',
|
||||
));
|
||||
|
||||
$this->resolver->setAllowedValues(array(
|
||||
'one' => array('1', 'one'),
|
||||
));
|
||||
|
||||
$this->resolver->resolve(array(
|
||||
'one' => '2',
|
||||
));
|
||||
}
|
||||
|
||||
public function testResolveSucceedsIfOptionTypeAllowed()
|
||||
{
|
||||
$this->resolver->setDefaults(array(
|
||||
'one' => '1',
|
||||
));
|
||||
|
||||
$this->resolver->setAllowedTypes(array(
|
||||
'one' => 'string',
|
||||
));
|
||||
|
||||
$options = array(
|
||||
'one' => 'one',
|
||||
);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'one' => 'one',
|
||||
), $this->resolver->resolve($options));
|
||||
}
|
||||
|
||||
public function testResolveSucceedsIfOptionTypeAllowedPassArray()
|
||||
{
|
||||
$this->resolver->setDefaults(array(
|
||||
'one' => '1',
|
||||
));
|
||||
|
||||
$this->resolver->setAllowedTypes(array(
|
||||
'one' => array('string', 'bool'),
|
||||
));
|
||||
|
||||
$options = array(
|
||||
'one' => true,
|
||||
);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'one' => true,
|
||||
), $this->resolver->resolve($options));
|
||||
}
|
||||
|
||||
public function testResolveSucceedsIfOptionTypeAllowedPassObject()
|
||||
{
|
||||
$this->resolver->setDefaults(array(
|
||||
'one' => '1',
|
||||
));
|
||||
|
||||
$this->resolver->setAllowedTypes(array(
|
||||
'one' => 'object',
|
||||
));
|
||||
|
||||
$object = new \stdClass();
|
||||
$options = array(
|
||||
'one' => $object,
|
||||
);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'one' => $object,
|
||||
), $this->resolver->resolve($options));
|
||||
}
|
||||
|
||||
public function testResolveSucceedsIfOptionTypeAllowedPassClass()
|
||||
{
|
||||
$this->resolver->setDefaults(array(
|
||||
'one' => '1',
|
||||
));
|
||||
|
||||
$this->resolver->setAllowedTypes(array(
|
||||
'one' => '\stdClass',
|
||||
));
|
||||
|
||||
$object = new \stdClass();
|
||||
$options = array(
|
||||
'one' => $object,
|
||||
);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'one' => $object,
|
||||
), $this->resolver->resolve($options));
|
||||
}
|
||||
|
||||
public function testResolveSucceedsIfOptionTypeAllowedAddTypes()
|
||||
{
|
||||
$this->resolver->setDefaults(array(
|
||||
'one' => '1',
|
||||
'two' => '2',
|
||||
));
|
||||
|
||||
$this->resolver->setAllowedTypes(array(
|
||||
'one' => 'string',
|
||||
'two' => 'bool',
|
||||
));
|
||||
$this->resolver->addAllowedTypes(array(
|
||||
'one' => 'float',
|
||||
'two' => 'integer',
|
||||
));
|
||||
|
||||
$options = array(
|
||||
'one' => 1.23,
|
||||
'two' => false,
|
||||
);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'one' => 1.23,
|
||||
'two' => false,
|
||||
), $this->resolver->resolve($options));
|
||||
}
|
||||
|
||||
public function testResolveSucceedsIfOptionalWithTypeAndWithoutValue()
|
||||
{
|
||||
$this->resolver->setOptional(array(
|
||||
'one',
|
||||
'two',
|
||||
));
|
||||
|
||||
$this->resolver->setAllowedTypes(array(
|
||||
'one' => 'string',
|
||||
'two' => 'int',
|
||||
));
|
||||
|
||||
$options = array(
|
||||
'two' => 1,
|
||||
);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'two' => 1,
|
||||
), $this->resolver->resolve($options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
|
||||
*/
|
||||
public function testResolveFailsIfOptionTypeNotAllowed()
|
||||
{
|
||||
$this->resolver->setDefaults(array(
|
||||
'one' => '1',
|
||||
));
|
||||
|
||||
$this->resolver->setAllowedTypes(array(
|
||||
'one' => array('string', 'bool'),
|
||||
));
|
||||
|
||||
$this->resolver->resolve(array(
|
||||
'one' => 1.23,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
|
||||
*/
|
||||
public function testResolveFailsIfOptionTypeNotAllowedMultipleOptions()
|
||||
{
|
||||
$this->resolver->setDefaults(array(
|
||||
'one' => '1',
|
||||
'two' => '2',
|
||||
));
|
||||
|
||||
$this->resolver->setAllowedTypes(array(
|
||||
'one' => 'string',
|
||||
'two' => 'bool',
|
||||
));
|
||||
|
||||
$this->resolver->resolve(array(
|
||||
'one' => 'foo',
|
||||
'two' => 1.23,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
|
||||
*/
|
||||
public function testResolveFailsIfOptionTypeNotAllowedAddTypes()
|
||||
{
|
||||
$this->resolver->setDefaults(array(
|
||||
'one' => '1',
|
||||
));
|
||||
|
||||
$this->resolver->setAllowedTypes(array(
|
||||
'one' => 'string',
|
||||
));
|
||||
$this->resolver->addAllowedTypes(array(
|
||||
'one' => 'bool',
|
||||
));
|
||||
|
||||
$this->resolver->resolve(array(
|
||||
'one' => 1.23,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException
|
||||
*/
|
||||
public function testSetRequiredFailsIfDefaultIsPassed()
|
||||
{
|
||||
$this->resolver->setRequired(array(
|
||||
'one' => '1',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException
|
||||
*/
|
||||
public function testSetOptionalFailsIfDefaultIsPassed()
|
||||
{
|
||||
$this->resolver->setOptional(array(
|
||||
'one' => '1',
|
||||
));
|
||||
}
|
||||
|
||||
public function testFluidInterface()
|
||||
{
|
||||
$this->resolver->setDefaults(array('one' => '1'))
|
||||
->replaceDefaults(array('one' => '2'))
|
||||
->setAllowedValues(array('one' => array('1', '2')))
|
||||
->addAllowedValues(array('one' => array('3')))
|
||||
->setRequired(array('two'))
|
||||
->setOptional(array('three'));
|
||||
|
||||
$options = array(
|
||||
'two' => '2',
|
||||
);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'one' => '2',
|
||||
'two' => '2',
|
||||
), $this->resolver->resolve($options));
|
||||
}
|
||||
|
||||
public function testKnownIfDefaultWasSet()
|
||||
{
|
||||
$this->assertFalse($this->resolver->isKnown('foo'));
|
||||
|
||||
$this->resolver->setDefaults(array(
|
||||
'foo' => 'bar',
|
||||
));
|
||||
|
||||
$this->assertTrue($this->resolver->isKnown('foo'));
|
||||
}
|
||||
|
||||
public function testKnownIfRequired()
|
||||
{
|
||||
$this->assertFalse($this->resolver->isKnown('foo'));
|
||||
|
||||
$this->resolver->setRequired(array(
|
||||
'foo',
|
||||
));
|
||||
|
||||
$this->assertTrue($this->resolver->isKnown('foo'));
|
||||
}
|
||||
|
||||
public function testKnownIfOptional()
|
||||
{
|
||||
$this->assertFalse($this->resolver->isKnown('foo'));
|
||||
|
||||
$this->resolver->setOptional(array(
|
||||
'foo',
|
||||
));
|
||||
|
||||
$this->assertTrue($this->resolver->isKnown('foo'));
|
||||
}
|
||||
|
||||
public function testRequiredIfRequired()
|
||||
{
|
||||
$this->assertFalse($this->resolver->isRequired('foo'));
|
||||
|
||||
$this->resolver->setRequired(array(
|
||||
'foo',
|
||||
));
|
||||
|
||||
$this->assertTrue($this->resolver->isRequired('foo'));
|
||||
}
|
||||
|
||||
public function testNotRequiredIfRequiredAndDefaultValue()
|
||||
{
|
||||
$this->assertFalse($this->resolver->isRequired('foo'));
|
||||
|
||||
$this->resolver->setRequired(array(
|
||||
'foo',
|
||||
));
|
||||
$this->resolver->setDefaults(array(
|
||||
'foo' => 'bar',
|
||||
));
|
||||
|
||||
$this->assertFalse($this->resolver->isRequired('foo'));
|
||||
}
|
||||
|
||||
public function testNormalizersTransformFinalOptions()
|
||||
{
|
||||
$this->resolver->setDefaults(array(
|
||||
'foo' => 'bar',
|
||||
'bam' => 'baz',
|
||||
));
|
||||
$this->resolver->setNormalizers(array(
|
||||
'foo' => function (Options $options, $value) {
|
||||
return $options['bam'].'['.$value.']';
|
||||
},
|
||||
));
|
||||
|
||||
$expected = array(
|
||||
'foo' => 'baz[bar]',
|
||||
'bam' => 'baz',
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, $this->resolver->resolve(array()));
|
||||
|
||||
$expected = array(
|
||||
'foo' => 'boo[custom]',
|
||||
'bam' => 'boo',
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, $this->resolver->resolve(array(
|
||||
'foo' => 'custom',
|
||||
'bam' => 'boo',
|
||||
)));
|
||||
}
|
||||
|
||||
public function testResolveWithoutOptionSucceedsIfRequiredAndDefaultValue()
|
||||
{
|
||||
$this->resolver->setRequired(array(
|
||||
'foo',
|
||||
));
|
||||
$this->resolver->setDefaults(array(
|
||||
'foo' => 'bar',
|
||||
));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'foo' => 'bar'
|
||||
), $this->resolver->resolve(array()));
|
||||
}
|
||||
|
||||
public function testResolveWithoutOptionSucceedsIfDefaultValueAndRequired()
|
||||
{
|
||||
$this->resolver->setDefaults(array(
|
||||
'foo' => 'bar',
|
||||
));
|
||||
$this->resolver->setRequired(array(
|
||||
'foo',
|
||||
));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'foo' => 'bar'
|
||||
), $this->resolver->resolve(array()));
|
||||
}
|
||||
|
||||
public function testResolveSucceedsIfOptionRequiredAndValueAllowed()
|
||||
{
|
||||
$this->resolver->setRequired(array(
|
||||
'one', 'two',
|
||||
));
|
||||
$this->resolver->setAllowedValues(array(
|
||||
'two' => array('2'),
|
||||
));
|
||||
|
||||
$options = array(
|
||||
'one' => '1',
|
||||
'two' => '2'
|
||||
);
|
||||
|
||||
$this->assertEquals($options, $this->resolver->resolve($options));
|
||||
}
|
||||
|
||||
public function testClone()
|
||||
{
|
||||
$this->resolver->setDefaults(array('one' => '1'));
|
||||
|
||||
$clone = clone $this->resolver;
|
||||
|
||||
// Changes after cloning don't affect each other
|
||||
$this->resolver->setDefaults(array('two' => '2'));
|
||||
$clone->setDefaults(array('three' => '3'));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'one' => '1',
|
||||
'two' => '2',
|
||||
), $this->resolver->resolve());
|
||||
|
||||
$this->assertEquals(array(
|
||||
'one' => '1',
|
||||
'three' => '3',
|
||||
), $clone->resolve());
|
||||
}
|
||||
}
|
529
vendor/symfony/options-resolver/Symfony/Component/OptionsResolver/Tests/OptionsTest.php
vendored
Normal file
529
vendor/symfony/options-resolver/Symfony/Component/OptionsResolver/Tests/OptionsTest.php
vendored
Normal file
|
@ -0,0 +1,529 @@
|
|||
<?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\OptionsResolver\Tests;
|
||||
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
|
||||
class OptionsTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var Options
|
||||
*/
|
||||
private $options;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->options = new Options();
|
||||
}
|
||||
|
||||
public function testArrayAccess()
|
||||
{
|
||||
$this->assertFalse(isset($this->options['foo']));
|
||||
$this->assertFalse(isset($this->options['bar']));
|
||||
|
||||
$this->options['foo'] = 0;
|
||||
$this->options['bar'] = 1;
|
||||
|
||||
$this->assertTrue(isset($this->options['foo']));
|
||||
$this->assertTrue(isset($this->options['bar']));
|
||||
|
||||
unset($this->options['bar']);
|
||||
|
||||
$this->assertTrue(isset($this->options['foo']));
|
||||
$this->assertFalse(isset($this->options['bar']));
|
||||
$this->assertEquals(0, $this->options['foo']);
|
||||
}
|
||||
|
||||
public function testCountable()
|
||||
{
|
||||
$this->options->set('foo', 0);
|
||||
$this->options->set('bar', 1);
|
||||
|
||||
$this->assertCount(2, $this->options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \OutOfBoundsException
|
||||
*/
|
||||
public function testGetNonExisting()
|
||||
{
|
||||
$this->options->get('foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException
|
||||
*/
|
||||
public function testSetNotSupportedAfterGet()
|
||||
{
|
||||
$this->options->set('foo', 'bar');
|
||||
$this->options->get('foo');
|
||||
$this->options->set('foo', 'baz');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException
|
||||
*/
|
||||
public function testRemoveNotSupportedAfterGet()
|
||||
{
|
||||
$this->options->set('foo', 'bar');
|
||||
$this->options->get('foo');
|
||||
$this->options->remove('foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException
|
||||
*/
|
||||
public function testSetNormalizerNotSupportedAfterGet()
|
||||
{
|
||||
$this->options->set('foo', 'bar');
|
||||
$this->options->get('foo');
|
||||
$this->options->setNormalizer('foo', function () {});
|
||||
}
|
||||
|
||||
public function testSetLazyOption()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
$this->options->set('foo', function (Options $options) use ($test) {
|
||||
return 'dynamic';
|
||||
});
|
||||
|
||||
$this->assertEquals('dynamic', $this->options->get('foo'));
|
||||
}
|
||||
|
||||
public function testSetDiscardsPreviousValue()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
// defined by superclass
|
||||
$this->options->set('foo', 'bar');
|
||||
|
||||
// defined by subclass
|
||||
$this->options->set('foo', function (Options $options, $previousValue) use ($test) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->assertNull($previousValue);
|
||||
|
||||
return 'dynamic';
|
||||
});
|
||||
|
||||
$this->assertEquals('dynamic', $this->options->get('foo'));
|
||||
}
|
||||
|
||||
public function testOverloadKeepsPreviousValue()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
// defined by superclass
|
||||
$this->options->set('foo', 'bar');
|
||||
|
||||
// defined by subclass
|
||||
$this->options->overload('foo', function (Options $options, $previousValue) use ($test) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->assertEquals('bar', $previousValue);
|
||||
|
||||
return 'dynamic';
|
||||
});
|
||||
|
||||
$this->assertEquals('dynamic', $this->options->get('foo'));
|
||||
}
|
||||
|
||||
public function testPreviousValueIsEvaluatedIfLazy()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
// defined by superclass
|
||||
$this->options->set('foo', function (Options $options) {
|
||||
return 'bar';
|
||||
});
|
||||
|
||||
// defined by subclass
|
||||
$this->options->overload('foo', function (Options $options, $previousValue) use ($test) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->assertEquals('bar', $previousValue);
|
||||
|
||||
return 'dynamic';
|
||||
});
|
||||
|
||||
$this->assertEquals('dynamic', $this->options->get('foo'));
|
||||
}
|
||||
|
||||
public function testPreviousValueIsNotEvaluatedIfNoSecondArgument()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
// defined by superclass
|
||||
$this->options->set('foo', function (Options $options) use ($test) {
|
||||
$test->fail('Should not be called');
|
||||
});
|
||||
|
||||
// defined by subclass, no $previousValue argument defined!
|
||||
$this->options->overload('foo', function (Options $options) use ($test) {
|
||||
return 'dynamic';
|
||||
});
|
||||
|
||||
$this->assertEquals('dynamic', $this->options->get('foo'));
|
||||
}
|
||||
|
||||
public function testLazyOptionCanAccessOtherOptions()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
$this->options->set('foo', 'bar');
|
||||
|
||||
$this->options->set('bam', function (Options $options) use ($test) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->assertEquals('bar', $options->get('foo'));
|
||||
|
||||
return 'dynamic';
|
||||
});
|
||||
|
||||
$this->assertEquals('bar', $this->options->get('foo'));
|
||||
$this->assertEquals('dynamic', $this->options->get('bam'));
|
||||
}
|
||||
|
||||
public function testLazyOptionCanAccessOtherLazyOptions()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
$this->options->set('foo', function (Options $options) {
|
||||
return 'bar';
|
||||
});
|
||||
|
||||
$this->options->set('bam', function (Options $options) use ($test) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->assertEquals('bar', $options->get('foo'));
|
||||
|
||||
return 'dynamic';
|
||||
});
|
||||
|
||||
$this->assertEquals('bar', $this->options->get('foo'));
|
||||
$this->assertEquals('dynamic', $this->options->get('bam'));
|
||||
}
|
||||
|
||||
public function testNormalizer()
|
||||
{
|
||||
$this->options->set('foo', 'bar');
|
||||
|
||||
$this->options->setNormalizer('foo', function () {
|
||||
return 'normalized';
|
||||
});
|
||||
|
||||
$this->assertEquals('normalized', $this->options->get('foo'));
|
||||
}
|
||||
|
||||
public function testNormalizerReceivesUnnormalizedValue()
|
||||
{
|
||||
$this->options->set('foo', 'bar');
|
||||
|
||||
$this->options->setNormalizer('foo', function (Options $options, $value) {
|
||||
return 'normalized['.$value.']';
|
||||
});
|
||||
|
||||
$this->assertEquals('normalized[bar]', $this->options->get('foo'));
|
||||
}
|
||||
|
||||
public function testNormalizerCanAccessOtherOptions()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
$this->options->set('foo', 'bar');
|
||||
$this->options->set('bam', 'baz');
|
||||
|
||||
$this->options->setNormalizer('bam', function (Options $options) use ($test) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->assertEquals('bar', $options->get('foo'));
|
||||
|
||||
return 'normalized';
|
||||
});
|
||||
|
||||
$this->assertEquals('bar', $this->options->get('foo'));
|
||||
$this->assertEquals('normalized', $this->options->get('bam'));
|
||||
}
|
||||
|
||||
public function testNormalizerCanAccessOtherLazyOptions()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
$this->options->set('foo', function (Options $options) {
|
||||
return 'bar';
|
||||
});
|
||||
$this->options->set('bam', 'baz');
|
||||
|
||||
$this->options->setNormalizer('bam', function (Options $options) use ($test) {
|
||||
/* @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->assertEquals('bar', $options->get('foo'));
|
||||
|
||||
return 'normalized';
|
||||
});
|
||||
|
||||
$this->assertEquals('bar', $this->options->get('foo'));
|
||||
$this->assertEquals('normalized', $this->options->get('bam'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException
|
||||
*/
|
||||
public function testFailForCyclicDependencies()
|
||||
{
|
||||
$this->options->set('foo', function (Options $options) {
|
||||
$options->get('bam');
|
||||
});
|
||||
|
||||
$this->options->set('bam', function (Options $options) {
|
||||
$options->get('foo');
|
||||
});
|
||||
|
||||
$this->options->get('foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException
|
||||
*/
|
||||
public function testFailForCyclicDependenciesBetweenNormalizers()
|
||||
{
|
||||
$this->options->set('foo', 'bar');
|
||||
$this->options->set('bam', 'baz');
|
||||
|
||||
$this->options->setNormalizer('foo', function (Options $options) {
|
||||
$options->get('bam');
|
||||
});
|
||||
|
||||
$this->options->setNormalizer('bam', function (Options $options) {
|
||||
$options->get('foo');
|
||||
});
|
||||
|
||||
$this->options->get('foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException
|
||||
*/
|
||||
public function testFailForCyclicDependenciesBetweenNormalizerAndLazyOption()
|
||||
{
|
||||
$this->options->set('foo', function (Options $options) {
|
||||
$options->get('bam');
|
||||
});
|
||||
$this->options->set('bam', 'baz');
|
||||
|
||||
$this->options->setNormalizer('bam', function (Options $options) {
|
||||
$options->get('foo');
|
||||
});
|
||||
|
||||
$this->options->get('foo');
|
||||
}
|
||||
|
||||
public function testAllInvokesEachLazyOptionOnlyOnce()
|
||||
{
|
||||
$test = $this;
|
||||
$i = 1;
|
||||
|
||||
$this->options->set('foo', function (Options $options) use ($test, &$i) {
|
||||
$test->assertSame(1, $i);
|
||||
++$i;
|
||||
|
||||
// Implicitly invoke lazy option for "bam"
|
||||
$options->get('bam');
|
||||
});
|
||||
$this->options->set('bam', function (Options $options) use ($test, &$i) {
|
||||
$test->assertSame(2, $i);
|
||||
++$i;
|
||||
});
|
||||
|
||||
$this->options->all();
|
||||
}
|
||||
|
||||
public function testAllInvokesEachNormalizerOnlyOnce()
|
||||
{
|
||||
$test = $this;
|
||||
$i = 1;
|
||||
|
||||
$this->options->set('foo', 'bar');
|
||||
$this->options->set('bam', 'baz');
|
||||
|
||||
$this->options->setNormalizer('foo', function (Options $options) use ($test, &$i) {
|
||||
$test->assertSame(1, $i);
|
||||
++$i;
|
||||
|
||||
// Implicitly invoke normalizer for "bam"
|
||||
$options->get('bam');
|
||||
});
|
||||
$this->options->setNormalizer('bam', function (Options $options) use ($test, &$i) {
|
||||
$test->assertSame(2, $i);
|
||||
++$i;
|
||||
});
|
||||
|
||||
$this->options->all();
|
||||
}
|
||||
|
||||
public function testReplaceClearsAndSets()
|
||||
{
|
||||
$this->options->set('one', '1');
|
||||
|
||||
$this->options->replace(array(
|
||||
'two' => '2',
|
||||
'three' => function (Options $options) {
|
||||
return '2' === $options['two'] ? '3' : 'foo';
|
||||
}
|
||||
));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'two' => '2',
|
||||
'three' => '3',
|
||||
), $this->options->all());
|
||||
}
|
||||
|
||||
public function testClearRemovesAllOptions()
|
||||
{
|
||||
$this->options->set('one', 1);
|
||||
$this->options->set('two', 2);
|
||||
|
||||
$this->options->clear();
|
||||
|
||||
$this->assertEmpty($this->options->all());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\OptionsResolver\Options::replace
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException
|
||||
*/
|
||||
public function testCannotReplaceAfterOptionWasRead()
|
||||
{
|
||||
$this->options->set('one', 1);
|
||||
$this->options->all();
|
||||
|
||||
$this->options->replace(array(
|
||||
'two' => '2',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\OptionsResolver\Options::overload
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException
|
||||
*/
|
||||
public function testCannotOverloadAfterOptionWasRead()
|
||||
{
|
||||
$this->options->set('one', 1);
|
||||
$this->options->all();
|
||||
|
||||
$this->options->overload('one', 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\OptionsResolver\Options::clear
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException
|
||||
*/
|
||||
public function testCannotClearAfterOptionWasRead()
|
||||
{
|
||||
$this->options->set('one', 1);
|
||||
$this->options->all();
|
||||
|
||||
$this->options->clear();
|
||||
}
|
||||
|
||||
public function testOverloadCannotBeEvaluatedLazilyWithoutExpectedClosureParams()
|
||||
{
|
||||
$this->options->set('foo', 'bar');
|
||||
|
||||
$this->options->overload('foo', function () {
|
||||
return 'test';
|
||||
});
|
||||
|
||||
$this->assertNotEquals('test', $this->options->get('foo'));
|
||||
$this->assertTrue(is_callable($this->options->get('foo')));
|
||||
}
|
||||
|
||||
public function testOverloadCannotBeEvaluatedLazilyWithoutFirstParamTypeHint()
|
||||
{
|
||||
$this->options->set('foo', 'bar');
|
||||
|
||||
$this->options->overload('foo', function ($object) {
|
||||
return 'test';
|
||||
});
|
||||
|
||||
$this->assertNotEquals('test', $this->options->get('foo'));
|
||||
$this->assertTrue(is_callable($this->options->get('foo')));
|
||||
}
|
||||
|
||||
public function testOptionsIteration()
|
||||
{
|
||||
$this->options->set('foo', 'bar');
|
||||
$this->options->set('foo1', 'bar1');
|
||||
$expectedResult = array('foo' => 'bar', 'foo1' => 'bar1');
|
||||
|
||||
$this->assertEquals($expectedResult, iterator_to_array($this->options, true));
|
||||
}
|
||||
|
||||
public function testHasWithNullValue()
|
||||
{
|
||||
$this->options->set('foo', null);
|
||||
|
||||
$this->assertTrue($this->options->has('foo'));
|
||||
}
|
||||
|
||||
public function testRemoveOptionAndNormalizer()
|
||||
{
|
||||
$this->options->set('foo1', 'bar');
|
||||
$this->options->setNormalizer('foo1', function (Options $options) {
|
||||
return '';
|
||||
});
|
||||
$this->options->set('foo2', 'bar');
|
||||
$this->options->setNormalizer('foo2', function (Options $options) {
|
||||
return '';
|
||||
});
|
||||
|
||||
$this->options->remove('foo2');
|
||||
$this->assertEquals(array('foo1' => ''), $this->options->all());
|
||||
}
|
||||
|
||||
public function testReplaceOptionAndNormalizer()
|
||||
{
|
||||
$this->options->set('foo1', 'bar');
|
||||
$this->options->setNormalizer('foo1', function (Options $options) {
|
||||
return '';
|
||||
});
|
||||
$this->options->set('foo2', 'bar');
|
||||
$this->options->setNormalizer('foo2', function (Options $options) {
|
||||
return '';
|
||||
});
|
||||
|
||||
$this->options->replace(array('foo1' => 'new'));
|
||||
$this->assertEquals(array('foo1' => 'new'), $this->options->all());
|
||||
}
|
||||
|
||||
public function testClearOptionAndNormalizer()
|
||||
{
|
||||
$this->options->set('foo1', 'bar');
|
||||
$this->options->setNormalizer('foo1', function (Options $options) {
|
||||
return '';
|
||||
});
|
||||
$this->options->set('foo2', 'bar');
|
||||
$this->options->setNormalizer('foo2', function (Options $options) {
|
||||
return '';
|
||||
});
|
||||
|
||||
$this->options->clear();
|
||||
$this->assertEmpty($this->options->all());
|
||||
}
|
||||
|
||||
public function testNormalizerWithoutCorrespondingOption()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
$this->options->setNormalizer('foo', function (Options $options, $previousValue) use ($test) {
|
||||
$test->assertNull($previousValue);
|
||||
|
||||
return '';
|
||||
});
|
||||
$this->assertEquals(array('foo' => ''), $this->options->all());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue