Update Composer, update everything

This commit is contained in:
Oliver Davies 2018-11-23 12:29:20 +00:00
parent ea3e94409f
commit dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions

View file

@ -0,0 +1,165 @@
<?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\DependencyInjection\Tests\ParameterBag;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
class EnvPlaceholderParameterBagTest extends TestCase
{
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
*/
public function testGetThrowsInvalidArgumentExceptionIfEnvNameContainsNonWordCharacters()
{
$bag = new EnvPlaceholderParameterBag();
$bag->get('env(%foo%)');
}
public function testMergeWillNotDuplicateIdenticalParameters()
{
$envVariableName = 'DB_HOST';
$parameter = sprintf('env(%s)', $envVariableName);
$firstBag = new EnvPlaceholderParameterBag();
// initialize placeholders
$firstBag->get($parameter);
$secondBag = clone $firstBag;
$firstBag->mergeEnvPlaceholders($secondBag);
$mergedPlaceholders = $firstBag->getEnvPlaceholders();
$placeholderForVariable = $mergedPlaceholders[$envVariableName];
$placeholder = array_values($placeholderForVariable)[0];
$this->assertCount(1, $placeholderForVariable);
$this->assertInternalType('string', $placeholder);
$this->assertContains($envVariableName, $placeholder);
}
public function testMergeWhereFirstBagIsEmptyWillWork()
{
$envVariableName = 'DB_HOST';
$parameter = sprintf('env(%s)', $envVariableName);
$firstBag = new EnvPlaceholderParameterBag();
$secondBag = new EnvPlaceholderParameterBag();
// initialize placeholder only in second bag
$secondBag->get($parameter);
$this->assertEmpty($firstBag->getEnvPlaceholders());
$firstBag->mergeEnvPlaceholders($secondBag);
$mergedPlaceholders = $firstBag->getEnvPlaceholders();
$placeholderForVariable = $mergedPlaceholders[$envVariableName];
$placeholder = array_values($placeholderForVariable)[0];
$this->assertCount(1, $placeholderForVariable);
$this->assertInternalType('string', $placeholder);
$this->assertContains($envVariableName, $placeholder);
}
public function testMergeWherePlaceholderOnlyExistsInSecond()
{
$uniqueEnvName = 'DB_HOST';
$commonEnvName = 'DB_USER';
$uniqueParamName = sprintf('env(%s)', $uniqueEnvName);
$commonParamName = sprintf('env(%s)', $commonEnvName);
$firstBag = new EnvPlaceholderParameterBag();
// initialize common placeholder
$firstBag->get($commonParamName);
$secondBag = clone $firstBag;
// initialize unique placeholder
$secondBag->get($uniqueParamName);
$firstBag->mergeEnvPlaceholders($secondBag);
$merged = $firstBag->getEnvPlaceholders();
$this->assertCount(1, $merged[$uniqueEnvName]);
// second bag has same placeholder for commonEnvName
$this->assertCount(1, $merged[$commonEnvName]);
}
public function testMergeWithDifferentIdentifiersForPlaceholders()
{
$envName = 'DB_USER';
$paramName = sprintf('env(%s)', $envName);
$firstBag = new EnvPlaceholderParameterBag();
$secondBag = new EnvPlaceholderParameterBag();
// initialize placeholders
$firstPlaceholder = $firstBag->get($paramName);
$secondPlaceholder = $secondBag->get($paramName);
$firstBag->mergeEnvPlaceholders($secondBag);
$merged = $firstBag->getEnvPlaceholders();
$this->assertNotEquals($firstPlaceholder, $secondPlaceholder);
$this->assertCount(2, $merged[$envName]);
}
public function testResolveEnvCastsIntToString()
{
$bag = new EnvPlaceholderParameterBag();
$bag->get('env(INT_VAR)');
$bag->set('env(INT_VAR)', 2);
$bag->resolve();
$this->assertSame('2', $bag->all()['env(INT_VAR)']);
}
public function testResolveEnvAllowsNull()
{
$bag = new EnvPlaceholderParameterBag();
$bag->get('env(NULL_VAR)');
$bag->set('env(NULL_VAR)', null);
$bag->resolve();
$this->assertNull($bag->all()['env(NULL_VAR)']);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
* @expectedExceptionMessage The default value of env parameter "ARRAY_VAR" must be scalar or null, array given.
*/
public function testResolveThrowsOnBadDefaultValue()
{
$bag = new EnvPlaceholderParameterBag();
$bag->get('env(ARRAY_VAR)');
$bag->set('env(ARRAY_VAR)', array());
$bag->resolve();
}
public function testGetEnvAllowsNull()
{
$bag = new EnvPlaceholderParameterBag();
$bag->set('env(NULL_VAR)', null);
$bag->get('env(NULL_VAR)');
$bag->resolve();
$this->assertNull($bag->all()['env(NULL_VAR)']);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
* @expectedExceptionMessage The default value of an env() parameter must be scalar or null, but "array" given to "env(ARRAY_VAR)".
*/
public function testGetThrowsOnBadDefaultValue()
{
$bag = new EnvPlaceholderParameterBag();
$bag->set('env(ARRAY_VAR)', array());
$bag->get('env(ARRAY_VAR)');
$bag->resolve();
}
}

View file

@ -0,0 +1,64 @@
<?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\DependencyInjection\Tests\ParameterBag;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
class FrozenParameterBagTest extends TestCase
{
public function testConstructor()
{
$parameters = array(
'foo' => 'foo',
'bar' => 'bar',
);
$bag = new FrozenParameterBag($parameters);
$this->assertEquals($parameters, $bag->all(), '__construct() takes an array of parameters as its first argument');
}
/**
* @expectedException \LogicException
*/
public function testClear()
{
$bag = new FrozenParameterBag(array());
$bag->clear();
}
/**
* @expectedException \LogicException
*/
public function testSet()
{
$bag = new FrozenParameterBag(array());
$bag->set('foo', 'bar');
}
/**
* @expectedException \LogicException
*/
public function testAdd()
{
$bag = new FrozenParameterBag(array());
$bag->add(array());
}
/**
* @expectedException \LogicException
*/
public function testRemove()
{
$bag = new FrozenParameterBag(array('foo' => 'bar'));
$bag->remove('foo');
}
}

View file

@ -0,0 +1,268 @@
<?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\DependencyInjection\Tests\ParameterBag;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException;
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
class ParameterBagTest extends TestCase
{
public function testConstructor()
{
$bag = new ParameterBag($parameters = array(
'foo' => 'foo',
'bar' => 'bar',
));
$this->assertEquals($parameters, $bag->all(), '__construct() takes an array of parameters as its first argument');
}
public function testClear()
{
$bag = new ParameterBag($parameters = array(
'foo' => 'foo',
'bar' => 'bar',
));
$bag->clear();
$this->assertEquals(array(), $bag->all(), '->clear() removes all parameters');
}
public function testRemove()
{
$bag = new ParameterBag(array(
'foo' => 'foo',
'bar' => 'bar',
));
$bag->remove('foo');
$this->assertEquals(array('bar' => 'bar'), $bag->all(), '->remove() removes a parameter');
}
public function testGetSet()
{
$bag = new ParameterBag(array('foo' => 'bar'));
$bag->set('bar', 'foo');
$this->assertEquals('foo', $bag->get('bar'), '->set() sets the value of a new parameter');
$bag->set('foo', 'baz');
$this->assertEquals('baz', $bag->get('foo'), '->set() overrides previously set parameter');
try {
$bag->get('baba');
$this->fail('->get() throws an Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException if the key does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException', $e, '->get() throws an Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException if the key does not exist');
$this->assertEquals('You have requested a non-existent parameter "baba".', $e->getMessage(), '->get() throws an Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException if the key does not exist');
}
}
/**
* @dataProvider provideGetThrowParameterNotFoundExceptionData
*/
public function testGetThrowParameterNotFoundException($parameterKey, $exceptionMessage)
{
$bag = new ParameterBag(array(
'foo' => 'foo',
'bar' => 'bar',
'baz' => 'baz',
'fiz' => array('bar' => array('boo' => 12)),
));
if (method_exists($this, 'expectException')) {
$this->expectException(ParameterNotFoundException::class);
$this->expectExceptionMessage($exceptionMessage);
} else {
$this->setExpectedException(ParameterNotFoundException::class, $exceptionMessage);
}
$bag->get($parameterKey);
}
public function provideGetThrowParameterNotFoundExceptionData()
{
return array(
array('foo1', 'You have requested a non-existent parameter "foo1". Did you mean this: "foo"?'),
array('bag', 'You have requested a non-existent parameter "bag". Did you mean one of these: "bar", "baz"?'),
array('', 'You have requested a non-existent parameter "".'),
array('fiz.bar.boo', 'You have requested a non-existent parameter "fiz.bar.boo". You cannot access nested array items, do you want to inject "fiz" instead?'),
);
}
public function testHas()
{
$bag = new ParameterBag(array('foo' => 'bar'));
$this->assertTrue($bag->has('foo'), '->has() returns true if a parameter is defined');
$this->assertFalse($bag->has('bar'), '->has() returns false if a parameter is not defined');
}
/**
* @group legacy
* @expectedDeprecation Parameter names will be made case sensitive in Symfony 4.0. Using "BAR" instead of "bar" is deprecated since Symfony 3.4.
* @expectedDeprecation Parameter names will be made case sensitive in Symfony 4.0. Using "Foo" instead of "foo" is deprecated since Symfony 3.4.
* @expectedDeprecation Parameter names will be made case sensitive in Symfony 4.0. Using "FOO" instead of "foo" is deprecated since Symfony 3.4.
* @expectedDeprecation Parameter names will be made case sensitive in Symfony 4.0. Using "Foo" instead of "foo" is deprecated since Symfony 3.4.
*/
public function testMixedCase()
{
$bag = new ParameterBag(array(
'foo' => 'foo',
'bar' => 'bar',
));
$bag->remove('BAR');
$this->assertEquals(array('foo' => 'foo'), $bag->all(), '->remove() converts key to lowercase before removing');
$bag->set('Foo', 'baz1');
$this->assertEquals('baz1', $bag->get('foo'), '->set() converts the key to lowercase');
$this->assertEquals('baz1', $bag->get('FOO'), '->get() converts the key to lowercase');
$this->assertTrue($bag->has('Foo'), '->has() converts the key to lowercase');
}
public function testResolveValue()
{
$bag = new ParameterBag(array());
$this->assertEquals('foo', $bag->resolveValue('foo'), '->resolveValue() returns its argument unmodified if no placeholders are found');
$bag = new ParameterBag(array('foo' => 'bar'));
$this->assertEquals('I\'m a bar', $bag->resolveValue('I\'m a %foo%'), '->resolveValue() replaces placeholders by their values');
$this->assertEquals(array('bar' => 'bar'), $bag->resolveValue(array('%foo%' => '%foo%')), '->resolveValue() replaces placeholders in keys and values of arrays');
$this->assertEquals(array('bar' => array('bar' => array('bar' => 'bar'))), $bag->resolveValue(array('%foo%' => array('%foo%' => array('%foo%' => '%foo%')))), '->resolveValue() replaces placeholders in nested arrays');
$this->assertEquals('I\'m a %%foo%%', $bag->resolveValue('I\'m a %%foo%%'), '->resolveValue() supports % escaping by doubling it');
$this->assertEquals('I\'m a bar %%foo bar', $bag->resolveValue('I\'m a %foo% %%foo %foo%'), '->resolveValue() supports % escaping by doubling it');
$this->assertEquals(array('foo' => array('bar' => array('ding' => 'I\'m a bar %%foo %%bar'))), $bag->resolveValue(array('foo' => array('bar' => array('ding' => 'I\'m a bar %%foo %%bar')))), '->resolveValue() supports % escaping by doubling it');
$bag = new ParameterBag(array('foo' => true));
$this->assertTrue($bag->resolveValue('%foo%'), '->resolveValue() replaces arguments that are just a placeholder by their value without casting them to strings');
$bag = new ParameterBag(array('foo' => null));
$this->assertNull($bag->resolveValue('%foo%'), '->resolveValue() replaces arguments that are just a placeholder by their value without casting them to strings');
$bag = new ParameterBag(array('foo' => 'bar', 'baz' => '%%%foo% %foo%%% %%foo%% %%%foo%%%'));
$this->assertEquals('%%bar bar%% %%foo%% %%bar%%', $bag->resolveValue('%baz%'), '->resolveValue() replaces params placed besides escaped %');
$bag = new ParameterBag(array('baz' => '%%s?%%s'));
$this->assertEquals('%%s?%%s', $bag->resolveValue('%baz%'), '->resolveValue() is not replacing greedily');
$bag = new ParameterBag(array());
try {
$bag->resolveValue('%foobar%');
$this->fail('->resolveValue() throws an InvalidArgumentException if a placeholder references a non-existent parameter');
} catch (ParameterNotFoundException $e) {
$this->assertEquals('You have requested a non-existent parameter "foobar".', $e->getMessage(), '->resolveValue() throws a ParameterNotFoundException if a placeholder references a non-existent parameter');
}
try {
$bag->resolveValue('foo %foobar% bar');
$this->fail('->resolveValue() throws a ParameterNotFoundException if a placeholder references a non-existent parameter');
} catch (ParameterNotFoundException $e) {
$this->assertEquals('You have requested a non-existent parameter "foobar".', $e->getMessage(), '->resolveValue() throws a ParameterNotFoundException if a placeholder references a non-existent parameter');
}
$bag = new ParameterBag(array('foo' => 'a %bar%', 'bar' => array()));
try {
$bag->resolveValue('%foo%');
$this->fail('->resolveValue() throws a RuntimeException when a parameter embeds another non-string parameter');
} catch (RuntimeException $e) {
$this->assertEquals('A string value must be composed of strings and/or numbers, but found parameter "bar" of type array inside string value "a %bar%".', $e->getMessage(), '->resolveValue() throws a RuntimeException when a parameter embeds another non-string parameter');
}
$bag = new ParameterBag(array('foo' => '%bar%', 'bar' => '%foobar%', 'foobar' => '%foo%'));
try {
$bag->resolveValue('%foo%');
$this->fail('->resolveValue() throws a ParameterCircularReferenceException when a parameter has a circular reference');
} catch (ParameterCircularReferenceException $e) {
$this->assertEquals('Circular reference detected for parameter "foo" ("foo" > "bar" > "foobar" > "foo").', $e->getMessage(), '->resolveValue() throws a ParameterCircularReferenceException when a parameter has a circular reference');
}
$bag = new ParameterBag(array('foo' => 'a %bar%', 'bar' => 'a %foobar%', 'foobar' => 'a %foo%'));
try {
$bag->resolveValue('%foo%');
$this->fail('->resolveValue() throws a ParameterCircularReferenceException when a parameter has a circular reference');
} catch (ParameterCircularReferenceException $e) {
$this->assertEquals('Circular reference detected for parameter "foo" ("foo" > "bar" > "foobar" > "foo").', $e->getMessage(), '->resolveValue() throws a ParameterCircularReferenceException when a parameter has a circular reference');
}
$bag = new ParameterBag(array('host' => 'foo.bar', 'port' => 1337));
$this->assertEquals('foo.bar:1337', $bag->resolveValue('%host%:%port%'));
}
public function testResolveIndicatesWhyAParameterIsNeeded()
{
$bag = new ParameterBag(array('foo' => '%bar%'));
try {
$bag->resolve();
} catch (ParameterNotFoundException $e) {
$this->assertEquals('The parameter "foo" has a dependency on a non-existent parameter "bar".', $e->getMessage());
}
$bag = new ParameterBag(array('foo' => '%bar%'));
try {
$bag->resolve();
} catch (ParameterNotFoundException $e) {
$this->assertEquals('The parameter "foo" has a dependency on a non-existent parameter "bar".', $e->getMessage());
}
}
public function testResolveUnescapesValue()
{
$bag = new ParameterBag(array(
'foo' => array('bar' => array('ding' => 'I\'m a bar %%foo %%bar')),
'bar' => 'I\'m a %%foo%%',
));
$bag->resolve();
$this->assertEquals('I\'m a %foo%', $bag->get('bar'), '->resolveValue() supports % escaping by doubling it');
$this->assertEquals(array('bar' => array('ding' => 'I\'m a bar %foo %bar')), $bag->get('foo'), '->resolveValue() supports % escaping by doubling it');
}
public function testEscapeValue()
{
$bag = new ParameterBag();
$bag->add(array(
'foo' => $bag->escapeValue(array('bar' => array('ding' => 'I\'m a bar %foo %bar', 'zero' => null))),
'bar' => $bag->escapeValue('I\'m a %foo%'),
));
$this->assertEquals('I\'m a %%foo%%', $bag->get('bar'), '->escapeValue() escapes % by doubling it');
$this->assertEquals(array('bar' => array('ding' => 'I\'m a bar %%foo %%bar', 'zero' => null)), $bag->get('foo'), '->escapeValue() escapes % by doubling it');
}
/**
* @dataProvider stringsWithSpacesProvider
*/
public function testResolveStringWithSpacesReturnsString($expected, $test, $description)
{
$bag = new ParameterBag(array('foo' => 'bar'));
try {
$this->assertEquals($expected, $bag->resolveString($test), $description);
} catch (ParameterNotFoundException $e) {
$this->fail(sprintf('%s - "%s"', $description, $expected));
}
}
public function stringsWithSpacesProvider()
{
return array(
array('bar', '%foo%', 'Parameters must be wrapped by %.'),
array('% foo %', '% foo %', 'Parameters should not have spaces.'),
array('{% set my_template = "foo" %}', '{% set my_template = "foo" %}', 'Twig-like strings are not parameters.'),
array('50% is less than 100%', '50% is less than 100%', 'Text between % signs is allowed, if there are spaces.'),
);
}
}