composer update
This commit is contained in:
parent
9ac51e0523
commit
623395064f
279 changed files with 4458 additions and 16328 deletions
106
vendor/symfony/yaml/Tests/Command/LintCommandTest.php
vendored
Normal file
106
vendor/symfony/yaml/Tests/Command/LintCommandTest.php
vendored
Normal file
|
@ -0,0 +1,106 @@
|
|||
<?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\Yaml\Tests\Command;
|
||||
|
||||
use Symfony\Component\Yaml\Command\LintCommand;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
/**
|
||||
* Tests the YamlLintCommand.
|
||||
*
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
*/
|
||||
class LintCommandTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $files;
|
||||
|
||||
public function testLintCorrectFile()
|
||||
{
|
||||
$tester = $this->createCommandTester();
|
||||
$filename = $this->createFile('foo: bar');
|
||||
|
||||
$ret = $tester->execute(array('filename' => $filename), array('verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false));
|
||||
|
||||
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
|
||||
$this->assertRegExp('/^\/\/ OK in /', trim($tester->getDisplay()));
|
||||
}
|
||||
|
||||
public function testLintIncorrectFile()
|
||||
{
|
||||
$incorrectContent = '
|
||||
foo:
|
||||
bar';
|
||||
$tester = $this->createCommandTester();
|
||||
$filename = $this->createFile($incorrectContent);
|
||||
|
||||
$ret = $tester->execute(array('filename' => $filename), array('decorated' => false));
|
||||
|
||||
$this->assertEquals(1, $ret, 'Returns 1 in case of error');
|
||||
$this->assertContains('Unable to parse at line 3 (near "bar").', trim($tester->getDisplay()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testLintFileNotReadable()
|
||||
{
|
||||
$tester = $this->createCommandTester();
|
||||
$filename = $this->createFile('');
|
||||
unlink($filename);
|
||||
|
||||
$ret = $tester->execute(array('filename' => $filename), array('decorated' => false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string Path to the new file
|
||||
*/
|
||||
private function createFile($content)
|
||||
{
|
||||
$filename = tempnam(sys_get_temp_dir().'/framework-yml-lint-test', 'sf-');
|
||||
file_put_contents($filename, $content);
|
||||
|
||||
$this->files[] = $filename;
|
||||
|
||||
return $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CommandTester
|
||||
*/
|
||||
protected function createCommandTester()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->add(new LintCommand());
|
||||
$command = $application->find('lint:yaml');
|
||||
|
||||
return new CommandTester($command);
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->files = array();
|
||||
@mkdir(sys_get_temp_dir().'/framework-yml-lint-test');
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
foreach ($this->files as $file) {
|
||||
if (file_exists($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
rmdir(sys_get_temp_dir().'/framework-yml-lint-test');
|
||||
}
|
||||
}
|
122
vendor/symfony/yaml/Tests/DumperTest.php
vendored
122
vendor/symfony/yaml/Tests/DumperTest.php
vendored
|
@ -13,6 +13,7 @@ namespace Symfony\Component\Yaml\Tests;
|
|||
|
||||
use Symfony\Component\Yaml\Parser;
|
||||
use Symfony\Component\Yaml\Dumper;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class DumperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
@ -50,6 +51,34 @@ class DumperTest extends \PHPUnit_Framework_TestCase
|
|||
$this->array = null;
|
||||
}
|
||||
|
||||
public function testIndentationInConstructor()
|
||||
{
|
||||
$dumper = new Dumper(7);
|
||||
$expected = <<<'EOF'
|
||||
'': bar
|
||||
foo: '#bar'
|
||||
'foo''bar': { }
|
||||
bar:
|
||||
- 1
|
||||
- foo
|
||||
foobar:
|
||||
foo: bar
|
||||
bar:
|
||||
- 1
|
||||
- foo
|
||||
foobar:
|
||||
foo: bar
|
||||
bar:
|
||||
- 1
|
||||
- foo
|
||||
|
||||
EOF;
|
||||
$this->assertEquals($expected, $dumper->dump($this->array, 4, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testSetIndentation()
|
||||
{
|
||||
$this->dumper->setIndentation(7);
|
||||
|
@ -177,6 +206,16 @@ EOF;
|
|||
}
|
||||
|
||||
public function testObjectSupportEnabled()
|
||||
{
|
||||
$dump = $this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, Yaml::DUMP_OBJECT);
|
||||
|
||||
$this->assertEquals('{ foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";}, bar: 1 }', $dump, '->dump() is able to dump objects');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testObjectSupportEnabledPassingTrue()
|
||||
{
|
||||
$dump = $this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, false, true);
|
||||
|
||||
|
@ -195,7 +234,16 @@ EOF;
|
|||
*/
|
||||
public function testObjectSupportDisabledWithExceptions()
|
||||
{
|
||||
$this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, true, false);
|
||||
$this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedException \Symfony\Component\Yaml\Exception\DumpException
|
||||
*/
|
||||
public function testObjectSupportDisabledWithExceptionsPassingTrue()
|
||||
{
|
||||
$this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -229,13 +277,81 @@ EOF;
|
|||
);
|
||||
}
|
||||
|
||||
public function testBinaryDataIsDumpedBase64Encoded()
|
||||
{
|
||||
$binaryData = file_get_contents(__DIR__.'/Fixtures/arrow.gif');
|
||||
$expected = '{ data: !!binary '.base64_encode($binaryData).' }';
|
||||
|
||||
$this->assertSame($expected, $this->dumper->dump(array('data' => $binaryData)));
|
||||
}
|
||||
|
||||
public function testNonUtf8DataIsDumpedBase64Encoded()
|
||||
{
|
||||
// "für" (ISO-8859-1 encoded)
|
||||
$this->assertSame('!!binary ZsM/cg==', $this->dumper->dump("f\xc3\x3fr"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider objectAsMapProvider
|
||||
*/
|
||||
public function testDumpObjectAsMap($object, $expected)
|
||||
{
|
||||
$yaml = $this->dumper->dump($object, 0, 0, Yaml::DUMP_OBJECT_AS_MAP);
|
||||
|
||||
$this->assertEquals($expected, Yaml::parse($yaml, Yaml::PARSE_OBJECT_FOR_MAP));
|
||||
}
|
||||
|
||||
public function objectAsMapProvider()
|
||||
{
|
||||
$tests = array();
|
||||
|
||||
$bar = new \stdClass();
|
||||
$bar->class = 'classBar';
|
||||
$bar->args = array('bar');
|
||||
$zar = new \stdClass();
|
||||
$foo = new \stdClass();
|
||||
$foo->bar = $bar;
|
||||
$foo->zar = $zar;
|
||||
$object = new \stdClass();
|
||||
$object->foo = $foo;
|
||||
$tests['stdClass'] = array($object, $object);
|
||||
|
||||
$arrayObject = new \ArrayObject();
|
||||
$arrayObject['foo'] = 'bar';
|
||||
$arrayObject['baz'] = 'foobar';
|
||||
$parsedArrayObject = new \stdClass();
|
||||
$parsedArrayObject->foo = 'bar';
|
||||
$parsedArrayObject->baz = 'foobar';
|
||||
$tests['ArrayObject'] = array($arrayObject, $parsedArrayObject);
|
||||
|
||||
$a = new A();
|
||||
$tests['arbitrary-object'] = array($a, null);
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
public function testDumpMultiLineStringAsScalarBlock()
|
||||
{
|
||||
$data = array(
|
||||
'data' => array(
|
||||
'single_line' => 'foo bar baz',
|
||||
'multi_line' => "foo\nline with trailing spaces:\n \nbar\r\ninteger like line:\n123456789\nempty line:\n\nbaz",
|
||||
'nested_inlined_multi_line_string' => array(
|
||||
'inlined_multi_line' => "foo\nbar\r\nempty line:\n\nbaz",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertSame(file_get_contents(__DIR__.'/Fixtures/multiple_lines_as_literal_block.yml'), $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage The indentation must be greater than zero
|
||||
*/
|
||||
public function testZeroIndentationThrowsException()
|
||||
{
|
||||
$this->dumper->setIndentation(0);
|
||||
new Dumper(0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -244,7 +360,7 @@ EOF;
|
|||
*/
|
||||
public function testNegativeIndentationThrowsException()
|
||||
{
|
||||
$this->dumper->setIndentation(-4);
|
||||
new Dumper(-4);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -509,24 +509,31 @@ test: Integers
|
|||
spec: 2.19
|
||||
yaml: |
|
||||
canonical: 12345
|
||||
decimal: +12,345
|
||||
octal: 014
|
||||
hexadecimal: 0xC
|
||||
php: |
|
||||
array(
|
||||
'canonical' => 12345,
|
||||
'decimal' => 12345.0,
|
||||
'octal' => 014,
|
||||
'hexadecimal' => 0xC
|
||||
)
|
||||
---
|
||||
test: Decimal Integer
|
||||
deprecated: true
|
||||
spec: 2.19
|
||||
yaml: |
|
||||
decimal: +12,345
|
||||
php: |
|
||||
array(
|
||||
'decimal' => 12345.0,
|
||||
)
|
||||
---
|
||||
# FIX: spec shows parens around -inf and NaN
|
||||
test: Floating point
|
||||
spec: 2.20
|
||||
yaml: |
|
||||
canonical: 1.23015e+3
|
||||
exponential: 12.3015e+02
|
||||
fixed: 1,230.15
|
||||
negative infinity: -.inf
|
||||
not a number: .NaN
|
||||
float as whole number: !!float 1
|
||||
|
@ -534,12 +541,21 @@ php: |
|
|||
array(
|
||||
'canonical' => 1230.15,
|
||||
'exponential' => 1230.15,
|
||||
'fixed' => 1230.15,
|
||||
'negative infinity' => log(0),
|
||||
'not a number' => -log(0),
|
||||
'float as whole number' => (float) 1
|
||||
)
|
||||
---
|
||||
test: Fixed Floating point
|
||||
deprecated: true
|
||||
spec: 2.20
|
||||
yaml: |
|
||||
fixed: 1,230.15
|
||||
php: |
|
||||
array(
|
||||
'fixed' => 1230.15,
|
||||
)
|
||||
---
|
||||
test: Miscellaneous
|
||||
spec: 2.21
|
||||
yaml: |
|
||||
|
@ -1532,29 +1548,43 @@ php: |
|
|||
test: Integer
|
||||
yaml: |
|
||||
canonical: 12345
|
||||
decimal: +12,345
|
||||
octal: 014
|
||||
hexadecimal: 0xC
|
||||
php: |
|
||||
array(
|
||||
'canonical' => 12345,
|
||||
'decimal' => 12345.0,
|
||||
'octal' => 12,
|
||||
'hexadecimal' => 12
|
||||
)
|
||||
---
|
||||
test: Decimal
|
||||
deprecated: true
|
||||
yaml: |
|
||||
decimal: +12,345
|
||||
php: |
|
||||
array(
|
||||
'decimal' => 12345.0,
|
||||
)
|
||||
---
|
||||
test: Fixed Float
|
||||
deprecated: true
|
||||
yaml: |
|
||||
fixed: 1,230.15
|
||||
php: |
|
||||
array(
|
||||
'fixed' => 1230.15,
|
||||
)
|
||||
---
|
||||
test: Float
|
||||
yaml: |
|
||||
canonical: 1.23015e+3
|
||||
exponential: 12.3015e+02
|
||||
fixed: 1,230.15
|
||||
negative infinity: -.inf
|
||||
not a number: .NaN
|
||||
php: |
|
||||
array(
|
||||
'canonical' => 1230.15,
|
||||
'exponential' => 1230.15,
|
||||
'fixed' => 1230.15,
|
||||
'negative infinity' => log(0),
|
||||
'not a number' => -log(0)
|
||||
)
|
||||
|
|
|
@ -176,13 +176,37 @@ brief: >
|
|||
yaml: |
|
||||
zero: 0
|
||||
simple: 12
|
||||
one-thousand: 1,000
|
||||
negative one-thousand: -1,000
|
||||
php: |
|
||||
array(
|
||||
'zero' => 0,
|
||||
'simple' => 12,
|
||||
)
|
||||
---
|
||||
test: Positive Big Integer
|
||||
deprecated: true
|
||||
dump_skip: true
|
||||
brief: >
|
||||
An integer is a series of numbers, optionally
|
||||
starting with a positive or negative sign. Integers
|
||||
may also contain commas for readability.
|
||||
yaml: |
|
||||
one-thousand: 1,000
|
||||
php: |
|
||||
array(
|
||||
'one-thousand' => 1000.0,
|
||||
)
|
||||
---
|
||||
test: Negative Big Integer
|
||||
deprecated: true
|
||||
dump_skip: true
|
||||
brief: >
|
||||
An integer is a series of numbers, optionally
|
||||
starting with a positive or negative sign. Integers
|
||||
may also contain commas for readability.
|
||||
yaml: |
|
||||
negative one-thousand: -1,000
|
||||
php: |
|
||||
array(
|
||||
'negative one-thousand' => -1000.0
|
||||
)
|
||||
---
|
||||
|
@ -208,15 +232,27 @@ brief: >
|
|||
positive and negative infinity and "not a number."
|
||||
yaml: |
|
||||
a simple float: 2.00
|
||||
larger float: 1,000.09
|
||||
scientific notation: 1.00009e+3
|
||||
php: |
|
||||
array(
|
||||
'a simple float' => 2.0,
|
||||
'larger float' => 1000.09,
|
||||
'scientific notation' => 1000.09
|
||||
)
|
||||
---
|
||||
test: Larger Float
|
||||
dump_skip: true
|
||||
deprecated: true
|
||||
brief: >
|
||||
Floats are represented by numbers with decimals,
|
||||
allowing for scientific notation, as well as
|
||||
positive and negative infinity and "not a number."
|
||||
yaml: |
|
||||
larger float: 1,000.09
|
||||
php: |
|
||||
array(
|
||||
'larger float' => 1000.09,
|
||||
)
|
||||
---
|
||||
test: Time
|
||||
todo: true
|
||||
brief: >
|
||||
|
|
BIN
vendor/symfony/yaml/Tests/Fixtures/arrow.gif
vendored
Normal file
BIN
vendor/symfony/yaml/Tests/Fixtures/arrow.gif
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 185 B |
13
vendor/symfony/yaml/Tests/Fixtures/multiple_lines_as_literal_block.yml
vendored
Normal file
13
vendor/symfony/yaml/Tests/Fixtures/multiple_lines_as_literal_block.yml
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
data:
|
||||
single_line: 'foo bar baz'
|
||||
multi_line: |
|
||||
foo
|
||||
line with trailing spaces:
|
||||
|
||||
bar
|
||||
integer like line:
|
||||
123456789
|
||||
empty line:
|
||||
|
||||
baz
|
||||
nested_inlined_multi_line_string: { inlined_multi_line: "foo\nbar\r\nempty line:\n\nbaz" }
|
|
@ -18,11 +18,7 @@ yaml: |
|
|||
x: Oren
|
||||
c:
|
||||
foo: bar
|
||||
foo: ignore
|
||||
bar: foo
|
||||
duplicate:
|
||||
foo: bar
|
||||
foo: ignore
|
||||
foo2: &foo2
|
||||
a: Ballmer
|
||||
ding: &dong [ fi, fei, fo, fam]
|
||||
|
@ -48,7 +44,6 @@ php: |
|
|||
array(
|
||||
'foo' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian'),
|
||||
'bar' => array('a' => 'before', 'd' => 'other', 'b' => 'new', 'c' => array('foo' => 'bar', 'bar' => 'foo'), 'x' => 'Oren'),
|
||||
'duplicate' => array('foo' => 'bar'),
|
||||
'foo2' => array('a' => 'Ballmer'),
|
||||
'ding' => array('fi', 'fei', 'fo', 'fam'),
|
||||
'check' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'fi', 'fei', 'fo', 'fam', 'isit' => 'tested'),
|
||||
|
|
258
vendor/symfony/yaml/Tests/InlineTest.php
vendored
258
vendor/symfony/yaml/Tests/InlineTest.php
vendored
|
@ -12,6 +12,7 @@
|
|||
namespace Symfony\Component\Yaml\Tests;
|
||||
|
||||
use Symfony\Component\Yaml\Inline;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class InlineTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
@ -27,6 +28,55 @@ class InlineTest extends \PHPUnit_Framework_TestCase
|
|||
* @dataProvider getTestsForParseWithMapObjects
|
||||
*/
|
||||
public function testParseWithMapObjects($yaml, $value)
|
||||
{
|
||||
$actual = Inline::parse($yaml, Yaml::PARSE_OBJECT_FOR_MAP);
|
||||
|
||||
$this->assertSame(serialize($value), serialize($actual));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTestsForParsePhpConstants
|
||||
*/
|
||||
public function testParsePhpConstants($yaml, $value)
|
||||
{
|
||||
$actual = Inline::parse($yaml, Yaml::PARSE_CONSTANT);
|
||||
|
||||
$this->assertSame($value, $actual);
|
||||
}
|
||||
|
||||
public function getTestsForParsePhpConstants()
|
||||
{
|
||||
return array(
|
||||
array('!php/const:Symfony\Component\Yaml\Yaml::PARSE_CONSTANT', Yaml::PARSE_CONSTANT),
|
||||
array('!php/const:PHP_INT_MAX', PHP_INT_MAX),
|
||||
array('[!php/const:PHP_INT_MAX]', array(PHP_INT_MAX)),
|
||||
array('{ foo: !php/const:PHP_INT_MAX }', array('foo' => PHP_INT_MAX)),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
||||
* @expectedExceptionMessage The constant "WRONG_CONSTANT" is not defined
|
||||
*/
|
||||
public function testParsePhpConstantThrowsExceptionWhenUndefined()
|
||||
{
|
||||
Inline::parse('!php/const:WRONG_CONSTANT', Yaml::PARSE_CONSTANT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
||||
* @expectedExceptionMessageRegExp #The string "!php/const:PHP_INT_MAX" could not be parsed as a constant.*#
|
||||
*/
|
||||
public function testParsePhpConstantThrowsExceptionOnInvalidType()
|
||||
{
|
||||
Inline::parse('!php/const:PHP_INT_MAX', Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @dataProvider getTestsForParseWithMapObjects
|
||||
*/
|
||||
public function testParseWithMapObjectsPassingTrue($yaml, $value)
|
||||
{
|
||||
$actual = Inline::parse($yaml, false, false, true);
|
||||
|
||||
|
@ -114,6 +164,16 @@ class InlineTest extends \PHPUnit_Framework_TestCase
|
|||
Inline::parse($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Using a colon that is not followed by an indication character (i.e. " ", ",", "[", "]", "{", "}" is deprecated since version 3.2 and will throw a ParseException in 4.0.
|
||||
* throws \Symfony\Component\Yaml\Exception\ParseException in 4.0
|
||||
*/
|
||||
public function testParseMappingKeyWithColonNotFollowedBySpace()
|
||||
{
|
||||
Inline::parse('{1:""}');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
||||
*/
|
||||
|
@ -142,6 +202,15 @@ class InlineTest extends \PHPUnit_Framework_TestCase
|
|||
* @dataProvider getDataForParseReferences
|
||||
*/
|
||||
public function testParseReferences($yaml, $expected)
|
||||
{
|
||||
$this->assertSame($expected, Inline::parse($yaml, 0, array('var' => 'var-value')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @dataProvider getDataForParseReferences
|
||||
*/
|
||||
public function testParseReferencesAsFifthArgument($yaml, $expected)
|
||||
{
|
||||
$this->assertSame($expected, Inline::parse($yaml, false, false, false, array('var' => 'var-value')));
|
||||
}
|
||||
|
@ -161,6 +230,19 @@ class InlineTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
public function testParseMapReferenceInSequence()
|
||||
{
|
||||
$foo = array(
|
||||
'a' => 'Steve',
|
||||
'b' => 'Clark',
|
||||
'c' => 'Brian',
|
||||
);
|
||||
$this->assertSame(array($foo), Inline::parse('[*foo]', 0, array('foo' => $foo)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testParseMapReferenceInSequenceAsFifthArgument()
|
||||
{
|
||||
$foo = array(
|
||||
'a' => 'Steve',
|
||||
|
@ -190,7 +272,7 @@ class InlineTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider getReservedIndicators
|
||||
* @expectedException Symfony\Component\Yaml\Exception\ParseException
|
||||
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
||||
* @expectedExceptionMessage cannot start a plain scalar; you need to quote the scalar.
|
||||
*/
|
||||
public function testParseUnquotedScalarStartingWithReservedIndicator($indicator)
|
||||
|
@ -205,7 +287,7 @@ class InlineTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider getScalarIndicators
|
||||
* @expectedException Symfony\Component\Yaml\Exception\ParseException
|
||||
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
||||
* @expectedExceptionMessage cannot start a plain scalar; you need to quote the scalar.
|
||||
*/
|
||||
public function testParseUnquotedScalarStartingWithScalarIndicator($indicator)
|
||||
|
@ -218,6 +300,34 @@ class InlineTest extends \PHPUnit_Framework_TestCase
|
|||
return array(array('|'), array('>'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Not quoting the scalar "%bar " starting with the "%" indicator character is deprecated since Symfony 3.1 and will throw a ParseException in 4.0.
|
||||
* throws \Symfony\Component\Yaml\Exception\ParseException in 4.0
|
||||
*/
|
||||
public function testParseUnquotedScalarStartingWithPercentCharacter()
|
||||
{
|
||||
Inline::parse('{ foo: %bar }');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getDataForIsHash
|
||||
*/
|
||||
public function testIsHash($array, $expected)
|
||||
{
|
||||
$this->assertSame($expected, Inline::isHash($array));
|
||||
}
|
||||
|
||||
public function getDataForIsHash()
|
||||
{
|
||||
return array(
|
||||
array(array(), false),
|
||||
array(array(1, 2, 3), false),
|
||||
array(array(2 => 1, 1 => 2, 0 => 3), true),
|
||||
array(array('foo' => 1, 'bar' => 2), true),
|
||||
);
|
||||
}
|
||||
|
||||
public function getTestsForParse()
|
||||
{
|
||||
return array(
|
||||
|
@ -227,11 +337,17 @@ class InlineTest extends \PHPUnit_Framework_TestCase
|
|||
array('true', true),
|
||||
array('12', 12),
|
||||
array('-12', -12),
|
||||
array('1_2', 12),
|
||||
array('_12', '_12'),
|
||||
array('12_', 12),
|
||||
array('"quoted string"', 'quoted string'),
|
||||
array("'quoted string'", 'quoted string'),
|
||||
array('12.30e+02', 12.30e+02),
|
||||
array('123.45_67', 123.4567),
|
||||
array('0x4D2', 0x4D2),
|
||||
array('0x_4_D_2_', 0x4D2),
|
||||
array('02333', 02333),
|
||||
array('0_2_3_3_3', 02333),
|
||||
array('.Inf', -log(0)),
|
||||
array('-.Inf', log(0)),
|
||||
array("'686e444'", '686e444'),
|
||||
|
@ -267,7 +383,7 @@ class InlineTest extends \PHPUnit_Framework_TestCase
|
|||
array('[\'foo,bar\', \'foo bar\']', array('foo,bar', 'foo bar')),
|
||||
|
||||
// mappings
|
||||
array('{foo:bar,bar:foo,false:false,null:null,integer:12}', array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
|
||||
array('{foo: bar,bar: foo,false: false,null: null,integer: 12}', array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
|
||||
array('{ foo : bar, bar : foo, false : false, null : null, integer : 12 }', array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
|
||||
array('{foo: \'bar\', bar: \'foo: bar\'}', array('foo' => 'bar', 'bar' => 'foo: bar')),
|
||||
array('{\'foo\': \'bar\', "bar": \'foo: bar\'}', array('foo' => 'bar', 'bar' => 'foo: bar')),
|
||||
|
@ -279,6 +395,8 @@ class InlineTest extends \PHPUnit_Framework_TestCase
|
|||
array('[foo, {bar: foo}]', array('foo', array('bar' => 'foo'))),
|
||||
array('{ foo: {bar: foo} }', array('foo' => array('bar' => 'foo'))),
|
||||
array('{ foo: [bar, foo] }', array('foo' => array('bar', 'foo'))),
|
||||
array('{ foo:{bar: foo} }', array('foo' => array('bar' => 'foo'))),
|
||||
array('{ foo:[bar, foo] }', array('foo' => array('bar', 'foo'))),
|
||||
|
||||
array('[ foo, [ bar, foo ] ]', array('foo', array('bar', 'foo'))),
|
||||
|
||||
|
@ -334,7 +452,7 @@ class InlineTest extends \PHPUnit_Framework_TestCase
|
|||
array('[\'foo,bar\', \'foo bar\']', array('foo,bar', 'foo bar')),
|
||||
|
||||
// mappings
|
||||
array('{foo:bar,bar:foo,false:false,null:null,integer:12}', (object) array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
|
||||
array('{foo: bar,bar: foo,false: false,null: null,integer: 12}', (object) array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
|
||||
array('{ foo : bar, bar : foo, false : false, null : null, integer : 12 }', (object) array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
|
||||
array('{foo: \'bar\', bar: \'foo: bar\'}', (object) array('foo' => 'bar', 'bar' => 'foo: bar')),
|
||||
array('{\'foo\': \'bar\', "bar": \'foo: bar\'}', (object) array('foo' => 'bar', 'bar' => 'foo: bar')),
|
||||
|
@ -379,10 +497,15 @@ class InlineTest extends \PHPUnit_Framework_TestCase
|
|||
array('false', false),
|
||||
array('true', true),
|
||||
array('12', 12),
|
||||
array("'1_2'", '1_2'),
|
||||
array('_12', '_12'),
|
||||
array("'12_'", '12_'),
|
||||
array("'quoted string'", 'quoted string'),
|
||||
array('!!float 1230', 12.30e+02),
|
||||
array('1234', 0x4D2),
|
||||
array('1243', 02333),
|
||||
array("'0x_4_D_2_'", '0x_4_D_2_'),
|
||||
array("'0_2_3_3_3'", '0_2_3_3_3'),
|
||||
array('.Inf', -log(0)),
|
||||
array('-.Inf', log(0)),
|
||||
array("'686e444'", '686e444'),
|
||||
|
@ -424,6 +547,133 @@ class InlineTest extends \PHPUnit_Framework_TestCase
|
|||
array('[foo, { bar: foo, foo: [foo, { bar: foo }] }, [foo, { bar: foo }]]', array('foo', array('bar' => 'foo', 'foo' => array('foo', array('bar' => 'foo'))), array('foo', array('bar' => 'foo')))),
|
||||
|
||||
array('[foo, \'@foo.baz\', { \'%foo%\': \'foo is %foo%\', bar: \'%foo%\' }, true, \'@service_container\']', array('foo', '@foo.baz', array('%foo%' => 'foo is %foo%', 'bar' => '%foo%'), true, '@service_container')),
|
||||
|
||||
array('{ foo: { bar: { 1: 2, baz: 3 } } }', array('foo' => array('bar' => array(1 => 2, 'baz' => 3)))),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTimestampTests
|
||||
*/
|
||||
public function testParseTimestampAsUnixTimestampByDefault($yaml, $year, $month, $day, $hour, $minute, $second)
|
||||
{
|
||||
$this->assertSame(gmmktime($hour, $minute, $second, $month, $day, $year), Inline::parse($yaml));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTimestampTests
|
||||
*/
|
||||
public function testParseTimestampAsDateTimeObject($yaml, $year, $month, $day, $hour, $minute, $second, $timezone)
|
||||
{
|
||||
$expected = new \DateTime($yaml);
|
||||
$expected->setTimeZone(new \DateTimeZone('UTC'));
|
||||
$expected->setDate($year, $month, $day);
|
||||
|
||||
if (PHP_VERSION_ID >= 70100) {
|
||||
$expected->setTime($hour, $minute, $second, 1000000 * ($second - (int) $second));
|
||||
} else {
|
||||
$expected->setTime($hour, $minute, $second);
|
||||
}
|
||||
|
||||
$date = Inline::parse($yaml, Yaml::PARSE_DATETIME);
|
||||
$this->assertEquals($expected, $date);
|
||||
$this->assertSame($timezone, $date->format('O'));
|
||||
}
|
||||
|
||||
public function getTimestampTests()
|
||||
{
|
||||
return array(
|
||||
'canonical' => array('2001-12-15T02:59:43.1Z', 2001, 12, 15, 2, 59, 43.1, '+0000'),
|
||||
'ISO-8601' => array('2001-12-15t21:59:43.10-05:00', 2001, 12, 16, 2, 59, 43.1, '-0500'),
|
||||
'spaced' => array('2001-12-15 21:59:43.10 -5', 2001, 12, 16, 2, 59, 43.1, '-0500'),
|
||||
'date' => array('2001-12-15', 2001, 12, 15, 0, 0, 0, '+0000'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTimestampTests
|
||||
*/
|
||||
public function testParseNestedTimestampListAsDateTimeObject($yaml, $year, $month, $day, $hour, $minute, $second)
|
||||
{
|
||||
$expected = new \DateTime($yaml);
|
||||
$expected->setTimeZone(new \DateTimeZone('UTC'));
|
||||
$expected->setDate($year, $month, $day);
|
||||
if (PHP_VERSION_ID >= 70100) {
|
||||
$expected->setTime($hour, $minute, $second, 1000000 * ($second - (int) $second));
|
||||
} else {
|
||||
$expected->setTime($hour, $minute, $second);
|
||||
}
|
||||
|
||||
$expectedNested = array('nested' => array($expected));
|
||||
$yamlNested = "{nested: [$yaml]}";
|
||||
|
||||
$this->assertEquals($expectedNested, Inline::parse($yamlNested, Yaml::PARSE_DATETIME));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getDateTimeDumpTests
|
||||
*/
|
||||
public function testDumpDateTime($dateTime, $expected)
|
||||
{
|
||||
$this->assertSame($expected, Inline::dump($dateTime));
|
||||
}
|
||||
|
||||
public function getDateTimeDumpTests()
|
||||
{
|
||||
$tests = array();
|
||||
|
||||
$dateTime = new \DateTime('2001-12-15 21:59:43', new \DateTimeZone('UTC'));
|
||||
$tests['date-time-utc'] = array($dateTime, '2001-12-15T21:59:43+00:00');
|
||||
|
||||
$dateTime = new \DateTimeImmutable('2001-07-15 21:59:43', new \DateTimeZone('Europe/Berlin'));
|
||||
$tests['immutable-date-time-europe-berlin'] = array($dateTime, '2001-07-15T21:59:43+02:00');
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getBinaryData
|
||||
*/
|
||||
public function testParseBinaryData($data)
|
||||
{
|
||||
$this->assertSame('Hello world', Inline::parse($data));
|
||||
}
|
||||
|
||||
public function getBinaryData()
|
||||
{
|
||||
return array(
|
||||
'enclosed with double quotes' => array('!!binary "SGVsbG8gd29ybGQ="'),
|
||||
'enclosed with single quotes' => array("!!binary 'SGVsbG8gd29ybGQ='"),
|
||||
'containing spaces' => array('!!binary "SGVs bG8gd 29ybGQ="'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getInvalidBinaryData
|
||||
*/
|
||||
public function testParseInvalidBinaryData($data, $expectedMessage)
|
||||
{
|
||||
$this->setExpectedExceptionRegExp('\Symfony\Component\Yaml\Exception\ParseException', $expectedMessage);
|
||||
|
||||
Inline::parse($data);
|
||||
}
|
||||
|
||||
public function getInvalidBinaryData()
|
||||
{
|
||||
return array(
|
||||
'length not a multiple of four' => array('!!binary "SGVsbG8d29ybGQ="', '/The normalized base64 encoded data \(data without whitespace characters\) length must be a multiple of four \(\d+ bytes given\)/'),
|
||||
'invalid characters' => array('!!binary "SGVsbG8#d29ybGQ="', '/The base64 encoded data \(.*\) contains invalid characters/'),
|
||||
'too many equals characters' => array('!!binary "SGVsbG8gd29yb==="', '/The base64 encoded data \(.*\) contains invalid characters/'),
|
||||
'misplaced equals character' => array('!!binary "SGVsbG8gd29ybG=Q"', '/The base64 encoded data \(.*\) contains invalid characters/'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
||||
* @expectedExceptionMessage Malformed inline YAML string: {this, is not, supported}.
|
||||
*/
|
||||
public function testNotSupportedMissingValue()
|
||||
{
|
||||
Inline::parse('{this, is not, supported}');
|
||||
}
|
||||
}
|
||||
|
|
416
vendor/symfony/yaml/Tests/ParserTest.php
vendored
416
vendor/symfony/yaml/Tests/ParserTest.php
vendored
|
@ -31,9 +31,30 @@ class ParserTest extends \PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* @dataProvider getDataFormSpecifications
|
||||
*/
|
||||
public function testSpecifications($file, $expected, $yaml, $comment)
|
||||
public function testSpecifications($file, $expected, $yaml, $comment, $deprecated)
|
||||
{
|
||||
$deprecations = array();
|
||||
|
||||
if ($deprecated) {
|
||||
set_error_handler(function ($type, $msg) use (&$deprecations) {
|
||||
if (E_USER_DEPRECATED !== $type) {
|
||||
restore_error_handler();
|
||||
|
||||
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
|
||||
}
|
||||
|
||||
$deprecations[] = $msg;
|
||||
});
|
||||
}
|
||||
|
||||
$this->assertEquals($expected, var_export($this->parser->parse($yaml), true), $comment);
|
||||
|
||||
if ($deprecated) {
|
||||
restore_error_handler();
|
||||
|
||||
$this->assertCount(1, $deprecations);
|
||||
$this->assertContains('Using the comma as a group separator for floats is deprecated since version 3.2 and will be removed in 4.0.', $deprecations[0]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDataFormSpecifications()
|
||||
|
@ -58,7 +79,7 @@ class ParserTest extends \PHPUnit_Framework_TestCase
|
|||
} else {
|
||||
eval('$expected = '.trim($test['php']).';');
|
||||
|
||||
$tests[] = array($file, var_export($expected, true), $test['yaml'], $test['test']);
|
||||
$tests[] = array($file, var_export($expected, true), $test['yaml'], $test['test'], isset($test['deprecated']) ? $test['deprecated'] : false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -421,19 +442,37 @@ EOF;
|
|||
|
||||
public function testObjectSupportEnabled()
|
||||
{
|
||||
$input = <<<EOF
|
||||
foo: !!php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
|
||||
$input = <<<'EOF'
|
||||
foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
|
||||
bar: 1
|
||||
EOF;
|
||||
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, false, true), '->parse() is able to parse objects');
|
||||
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, Yaml::PARSE_OBJECT), '->parse() is able to parse objects');
|
||||
}
|
||||
|
||||
$input = <<<EOF
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testObjectSupportEnabledPassingTrue()
|
||||
{
|
||||
$input = <<<'EOF'
|
||||
foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
|
||||
bar: 1
|
||||
EOF;
|
||||
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, false, true), '->parse() is able to parse objects');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testObjectSupportEnabledWithDeprecatedTag()
|
||||
{
|
||||
$input = <<<'EOF'
|
||||
foo: !!php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
|
||||
bar: 1
|
||||
EOF;
|
||||
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, Yaml::PARSE_OBJECT), '->parse() is able to parse objects');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidDumpedObjectProvider
|
||||
*/
|
||||
|
@ -446,6 +485,15 @@ EOF;
|
|||
* @dataProvider getObjectForMapTests
|
||||
*/
|
||||
public function testObjectForMap($yaml, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, $this->parser->parse($yaml, Yaml::PARSE_OBJECT_FOR_MAP));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @dataProvider getObjectForMapTests
|
||||
*/
|
||||
public function testObjectForMapEnabledWithMappingUsingBooleanToggles($yaml, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, $this->parser->parse($yaml, false, false, true));
|
||||
}
|
||||
|
@ -454,7 +502,7 @@ EOF;
|
|||
{
|
||||
$tests = array();
|
||||
|
||||
$yaml = <<<EOF
|
||||
$yaml = <<<'EOF'
|
||||
foo:
|
||||
fiz: [cat]
|
||||
EOF;
|
||||
|
@ -475,7 +523,7 @@ EOF;
|
|||
$expected->baz = 'foobar';
|
||||
$tests['object-for-map-is-applied-after-parsing'] = array($yaml, $expected);
|
||||
|
||||
$yaml = <<<EOT
|
||||
$yaml = <<<'EOT'
|
||||
array:
|
||||
- key: one
|
||||
- key: two
|
||||
|
@ -488,7 +536,7 @@ EOT;
|
|||
$expected->array[1]->key = 'two';
|
||||
$tests['nest-map-and-sequence'] = array($yaml, $expected);
|
||||
|
||||
$yaml = <<<YAML
|
||||
$yaml = <<<'YAML'
|
||||
map:
|
||||
1: one
|
||||
2: two
|
||||
|
@ -499,7 +547,7 @@ YAML;
|
|||
$expected->map->{2} = 'two';
|
||||
$tests['numeric-keys'] = array($yaml, $expected);
|
||||
|
||||
$yaml = <<<YAML
|
||||
$yaml = <<<'YAML'
|
||||
map:
|
||||
0: one
|
||||
1: two
|
||||
|
@ -519,16 +567,26 @@ YAML;
|
|||
*/
|
||||
public function testObjectsSupportDisabledWithExceptions($yaml)
|
||||
{
|
||||
$this->parser->parse($yaml, true, false);
|
||||
$this->parser->parse($yaml, Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @dataProvider invalidDumpedObjectProvider
|
||||
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
||||
*/
|
||||
public function testObjectsSupportDisabledWithExceptionsUsingBooleanToggles($yaml)
|
||||
{
|
||||
$this->parser->parse($yaml, true);
|
||||
}
|
||||
|
||||
public function invalidDumpedObjectProvider()
|
||||
{
|
||||
$yamlTag = <<<EOF
|
||||
$yamlTag = <<<'EOF'
|
||||
foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
|
||||
bar: 1
|
||||
EOF;
|
||||
$localTag = <<<EOF
|
||||
$localTag = <<<'EOF'
|
||||
foo: !php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
|
||||
bar: 1
|
||||
EOF;
|
||||
|
@ -596,7 +654,7 @@ EOF;
|
|||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
||||
* @expectedExceptionMessage Multiple documents are not supported.
|
||||
* @expectedExceptionMessageRegExp /^Multiple documents are not supported.+/
|
||||
*/
|
||||
public function testMultipleDocumentsNotSupportedException()
|
||||
{
|
||||
|
@ -628,6 +686,53 @@ EOF
|
|||
);
|
||||
}
|
||||
|
||||
public function testSequenceInMappingStartedBySingleDashLine()
|
||||
{
|
||||
$yaml = <<<'EOT'
|
||||
a:
|
||||
-
|
||||
b:
|
||||
-
|
||||
bar: baz
|
||||
- foo
|
||||
d: e
|
||||
EOT;
|
||||
$expected = array(
|
||||
'a' => array(
|
||||
array(
|
||||
'b' => array(
|
||||
array(
|
||||
'bar' => 'baz',
|
||||
),
|
||||
),
|
||||
),
|
||||
'foo',
|
||||
),
|
||||
'd' => 'e',
|
||||
);
|
||||
|
||||
$this->assertSame($expected, $this->parser->parse($yaml));
|
||||
}
|
||||
|
||||
public function testSequenceFollowedByCommentEmbeddedInMapping()
|
||||
{
|
||||
$yaml = <<<'EOT'
|
||||
a:
|
||||
b:
|
||||
- c
|
||||
# comment
|
||||
d: e
|
||||
EOT;
|
||||
$expected = array(
|
||||
'a' => array(
|
||||
'b' => array('c'),
|
||||
'd' => 'e',
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertSame($expected, $this->parser->parse($yaml));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
||||
*/
|
||||
|
@ -647,7 +752,7 @@ EOF
|
|||
*/
|
||||
public function testScalarInSequence()
|
||||
{
|
||||
Yaml::parse(<<<EOF
|
||||
Yaml::parse(<<<'EOF'
|
||||
foo:
|
||||
- bar
|
||||
"missing colon"
|
||||
|
@ -665,10 +770,11 @@ EOF
|
|||
*
|
||||
* @see http://yaml.org/spec/1.2/spec.html#id2759572
|
||||
* @see http://yaml.org/spec/1.1/#id932806
|
||||
* @group legacy
|
||||
*/
|
||||
public function testMappingDuplicateKeyBlock()
|
||||
{
|
||||
$input = <<<EOD
|
||||
$input = <<<'EOD'
|
||||
parent:
|
||||
child: first
|
||||
child: duplicate
|
||||
|
@ -684,9 +790,12 @@ EOD;
|
|||
$this->assertSame($expected, Yaml::parse($input));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testMappingDuplicateKeyFlow()
|
||||
{
|
||||
$input = <<<EOD
|
||||
$input = <<<'EOD'
|
||||
parent: { child: first, child: duplicate }
|
||||
parent: { child: duplicate, child: duplicate }
|
||||
EOD;
|
||||
|
@ -698,6 +807,74 @@ EOD;
|
|||
$this->assertSame($expected, Yaml::parse($input));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @dataProvider getParseExceptionOnDuplicateData
|
||||
* @expectedDeprecation Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated %s.
|
||||
* throws \Symfony\Component\Yaml\Exception\ParseException in 4.0
|
||||
*/
|
||||
public function testParseExceptionOnDuplicate($input, $duplicateKey, $lineNumber)
|
||||
{
|
||||
Yaml::parse($input);
|
||||
}
|
||||
|
||||
public function getParseExceptionOnDuplicateData()
|
||||
{
|
||||
$tests = array();
|
||||
|
||||
$yaml = <<<EOD
|
||||
parent: { child: first, child: duplicate }
|
||||
EOD;
|
||||
$tests[] = array($yaml, 'child', 1);
|
||||
|
||||
$yaml = <<<EOD
|
||||
parent:
|
||||
child: first,
|
||||
child: duplicate
|
||||
EOD;
|
||||
$tests[] = array($yaml, 'child', 3);
|
||||
|
||||
$yaml = <<<EOD
|
||||
parent: { child: foo }
|
||||
parent: { child: bar }
|
||||
EOD;
|
||||
$tests[] = array($yaml, 'parent', 2);
|
||||
|
||||
$yaml = <<<EOD
|
||||
parent: { child_mapping: { value: bar}, child_mapping: { value: bar} }
|
||||
EOD;
|
||||
$tests[] = array($yaml, 'child_mapping', 1);
|
||||
|
||||
$yaml = <<<EOD
|
||||
parent:
|
||||
child_mapping:
|
||||
value: bar
|
||||
child_mapping:
|
||||
value: bar
|
||||
EOD;
|
||||
$tests[] = array($yaml, 'child_mapping', 4);
|
||||
|
||||
$yaml = <<<EOD
|
||||
parent: { child_sequence: ['key1', 'key2', 'key3'], child_sequence: ['key1', 'key2', 'key3'] }
|
||||
EOD;
|
||||
$tests[] = array($yaml, 'child_sequence', 1);
|
||||
|
||||
$yaml = <<<EOD
|
||||
parent:
|
||||
child_sequence:
|
||||
- key1
|
||||
- key2
|
||||
- key3
|
||||
child_sequence:
|
||||
- key1
|
||||
- key2
|
||||
- key3
|
||||
EOD;
|
||||
$tests[] = array($yaml, 'child_sequence', 6);
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
public function testEmptyValue()
|
||||
{
|
||||
$input = <<<'EOF'
|
||||
|
@ -883,7 +1060,7 @@ EOF;
|
|||
*/
|
||||
public function testColonInMappingValueException()
|
||||
{
|
||||
$yaml = <<<EOF
|
||||
$yaml = <<<'EOF'
|
||||
foo: bar: baz
|
||||
EOF;
|
||||
|
||||
|
@ -892,7 +1069,7 @@ EOF;
|
|||
|
||||
public function testColonInMappingValueExceptionNotTriggeredByColonInComment()
|
||||
{
|
||||
$yaml = <<<EOT
|
||||
$yaml = <<<'EOT'
|
||||
foo:
|
||||
bar: foobar # Note: a comment after a colon
|
||||
EOT;
|
||||
|
@ -977,6 +1154,7 @@ EOT
|
|||
foo
|
||||
# bar
|
||||
baz
|
||||
|
||||
EOT
|
||||
,
|
||||
),
|
||||
|
@ -992,7 +1170,7 @@ EOT
|
|||
);
|
||||
$tests[] = array($yaml, $expected);
|
||||
|
||||
$yaml = <<<EOT
|
||||
$yaml = <<<'EOT'
|
||||
foo:
|
||||
bar:
|
||||
scalar-block: >
|
||||
|
@ -1005,7 +1183,7 @@ EOT;
|
|||
$expected = array(
|
||||
'foo' => array(
|
||||
'bar' => array(
|
||||
'scalar-block' => 'line1 line2>',
|
||||
'scalar-block' => "line1 line2>\n",
|
||||
),
|
||||
'baz' => array(
|
||||
'foobar' => null,
|
||||
|
@ -1035,7 +1213,7 @@ EOT;
|
|||
|
||||
public function testBlankLinesAreParsedAsNewLinesInFoldedBlocks()
|
||||
{
|
||||
$yaml = <<<EOT
|
||||
$yaml = <<<'EOT'
|
||||
test: >
|
||||
<h2>A heading</h2>
|
||||
|
||||
|
@ -1047,7 +1225,7 @@ EOT;
|
|||
|
||||
$this->assertSame(
|
||||
array(
|
||||
'test' => <<<EOT
|
||||
'test' => <<<'EOT'
|
||||
<h2>A heading</h2>
|
||||
<ul> <li>a list</li> <li>may be a good example</li> </ul>
|
||||
EOT
|
||||
|
@ -1059,7 +1237,7 @@ EOT
|
|||
|
||||
public function testAdditionallyIndentedLinesAreParsedAsNewLinesInFoldedBlocks()
|
||||
{
|
||||
$yaml = <<<EOT
|
||||
$yaml = <<<'EOT'
|
||||
test: >
|
||||
<h2>A heading</h2>
|
||||
|
||||
|
@ -1071,7 +1249,7 @@ EOT;
|
|||
|
||||
$this->assertSame(
|
||||
array(
|
||||
'test' => <<<EOT
|
||||
'test' => <<<'EOT'
|
||||
<h2>A heading</h2>
|
||||
<ul>
|
||||
<li>a list</li>
|
||||
|
@ -1083,6 +1261,194 @@ EOT
|
|||
$this->parser->parse($yaml)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getBinaryData
|
||||
*/
|
||||
public function testParseBinaryData($data)
|
||||
{
|
||||
$this->assertSame(array('data' => 'Hello world'), $this->parser->parse($data));
|
||||
}
|
||||
|
||||
public function getBinaryData()
|
||||
{
|
||||
return array(
|
||||
'enclosed with double quotes' => array('data: !!binary "SGVsbG8gd29ybGQ="'),
|
||||
'enclosed with single quotes' => array("data: !!binary 'SGVsbG8gd29ybGQ='"),
|
||||
'containing spaces' => array('data: !!binary "SGVs bG8gd 29ybGQ="'),
|
||||
'in block scalar' => array(
|
||||
<<<'EOT'
|
||||
data: !!binary |
|
||||
SGVsbG8gd29ybGQ=
|
||||
EOT
|
||||
),
|
||||
'containing spaces in block scalar' => array(
|
||||
<<<'EOT'
|
||||
data: !!binary |
|
||||
SGVs bG8gd 29ybGQ=
|
||||
EOT
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getInvalidBinaryData
|
||||
*/
|
||||
public function testParseInvalidBinaryData($data, $expectedMessage)
|
||||
{
|
||||
$this->setExpectedExceptionRegExp('\Symfony\Component\Yaml\Exception\ParseException', $expectedMessage);
|
||||
|
||||
$this->parser->parse($data);
|
||||
}
|
||||
|
||||
public function getInvalidBinaryData()
|
||||
{
|
||||
return array(
|
||||
'length not a multiple of four' => array('data: !!binary "SGVsbG8d29ybGQ="', '/The normalized base64 encoded data \(data without whitespace characters\) length must be a multiple of four \(\d+ bytes given\)/'),
|
||||
'invalid characters' => array('!!binary "SGVsbG8#d29ybGQ="', '/The base64 encoded data \(.*\) contains invalid characters/'),
|
||||
'too many equals characters' => array('data: !!binary "SGVsbG8gd29yb==="', '/The base64 encoded data \(.*\) contains invalid characters/'),
|
||||
'misplaced equals character' => array('data: !!binary "SGVsbG8gd29ybG=Q"', '/The base64 encoded data \(.*\) contains invalid characters/'),
|
||||
'length not a multiple of four in block scalar' => array(
|
||||
<<<'EOT'
|
||||
data: !!binary |
|
||||
SGVsbG8d29ybGQ=
|
||||
EOT
|
||||
,
|
||||
'/The normalized base64 encoded data \(data without whitespace characters\) length must be a multiple of four \(\d+ bytes given\)/',
|
||||
),
|
||||
'invalid characters in block scalar' => array(
|
||||
<<<'EOT'
|
||||
data: !!binary |
|
||||
SGVsbG8#d29ybGQ=
|
||||
EOT
|
||||
,
|
||||
'/The base64 encoded data \(.*\) contains invalid characters/',
|
||||
),
|
||||
'too many equals characters in block scalar' => array(
|
||||
<<<'EOT'
|
||||
data: !!binary |
|
||||
SGVsbG8gd29yb===
|
||||
EOT
|
||||
,
|
||||
'/The base64 encoded data \(.*\) contains invalid characters/',
|
||||
),
|
||||
'misplaced equals character in block scalar' => array(
|
||||
<<<'EOT'
|
||||
data: !!binary |
|
||||
SGVsbG8gd29ybG=Q
|
||||
EOT
|
||||
,
|
||||
'/The base64 encoded data \(.*\) contains invalid characters/',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function testParseDateAsMappingValue()
|
||||
{
|
||||
$yaml = <<<'EOT'
|
||||
date: 2002-12-14
|
||||
EOT;
|
||||
$expectedDate = new \DateTime();
|
||||
$expectedDate->setTimeZone(new \DateTimeZone('UTC'));
|
||||
$expectedDate->setDate(2002, 12, 14);
|
||||
$expectedDate->setTime(0, 0, 0);
|
||||
|
||||
$this->assertEquals(array('date' => $expectedDate), $this->parser->parse($yaml, Yaml::PARSE_DATETIME));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $lineNumber
|
||||
* @param $yaml
|
||||
* @dataProvider parserThrowsExceptionWithCorrectLineNumberProvider
|
||||
*/
|
||||
public function testParserThrowsExceptionWithCorrectLineNumber($lineNumber, $yaml)
|
||||
{
|
||||
$this->setExpectedException(
|
||||
'\Symfony\Component\Yaml\Exception\ParseException',
|
||||
sprintf('Unexpected characters near "," at line %d (near "bar: "123",").', $lineNumber)
|
||||
);
|
||||
|
||||
$this->parser->parse($yaml);
|
||||
}
|
||||
|
||||
public function parserThrowsExceptionWithCorrectLineNumberProvider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
4,
|
||||
<<<'YAML'
|
||||
foo:
|
||||
-
|
||||
# bar
|
||||
bar: "123",
|
||||
YAML
|
||||
),
|
||||
array(
|
||||
5,
|
||||
<<<'YAML'
|
||||
foo:
|
||||
-
|
||||
# bar
|
||||
# bar
|
||||
bar: "123",
|
||||
YAML
|
||||
),
|
||||
array(
|
||||
8,
|
||||
<<<'YAML'
|
||||
foo:
|
||||
-
|
||||
# foobar
|
||||
baz: 123
|
||||
bar:
|
||||
-
|
||||
# bar
|
||||
bar: "123",
|
||||
YAML
|
||||
),
|
||||
array(
|
||||
10,
|
||||
<<<'YAML'
|
||||
foo:
|
||||
-
|
||||
# foobar
|
||||
# foobar
|
||||
baz: 123
|
||||
bar:
|
||||
-
|
||||
# bar
|
||||
# bar
|
||||
bar: "123",
|
||||
YAML
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function testParseMultiLineQuotedString()
|
||||
{
|
||||
$yaml = <<<EOT
|
||||
foo: "bar
|
||||
baz
|
||||
foobar
|
||||
foo"
|
||||
bar: baz
|
||||
EOT;
|
||||
|
||||
$this->assertSame(array('foo' => 'bar baz foobar foo', 'bar' => 'baz'), $this->parser->parse($yaml));
|
||||
}
|
||||
|
||||
public function testParseMultiLineUnquotedString()
|
||||
{
|
||||
$yaml = <<<EOT
|
||||
foo: bar
|
||||
baz
|
||||
foobar
|
||||
foo
|
||||
bar: baz
|
||||
EOT;
|
||||
|
||||
$this->assertSame(array('foo' => 'bar baz foobar foo', 'bar' => 'baz'), $this->parser->parse($yaml));
|
||||
}
|
||||
}
|
||||
|
||||
class B
|
||||
|
|
Reference in a new issue