2010-03-18 07:48:03 +00:00
< ? php
/*
2010-04-25 16:06:54 +01:00
* This file is part of the Symfony package .
2011-01-15 13:29:43 +00:00
*
2011-03-06 11:40:06 +00:00
* ( c ) Fabien Potencier < fabien @ symfony . com >
2010-03-18 07:48:03 +00:00
*
* For the full copyright and license information , please view the LICENSE
* file that was distributed with this source code .
*/
2012-03-28 14:43:52 +01:00
namespace Symfony\Component\Yaml\Tests ;
2010-03-18 07:48:03 +00:00
2010-08-20 22:09:55 +01:00
use Symfony\Component\Yaml\Yaml ;
use Symfony\Component\Yaml\Parser ;
2010-03-18 07:48:03 +00:00
class ParserTest extends \PHPUnit_Framework_TestCase
{
2010-05-06 12:25:53 +01:00
protected $parser ;
2010-03-18 07:48:03 +00:00
2010-12-06 14:45:37 +00:00
protected function setUp ()
2010-03-18 07:48:03 +00:00
{
2010-05-06 12:25:53 +01:00
$this -> parser = new Parser ();
}
2010-03-18 07:48:03 +00:00
2011-06-14 09:40:42 +01:00
protected function tearDown ()
{
$this -> parser = null ;
}
2010-06-29 16:45:09 +01:00
/**
* @ dataProvider getDataFormSpecifications
*/
2012-04-19 18:28:53 +01:00
public function testSpecifications ( $file , $expected , $yaml , $comment )
2010-05-06 12:25:53 +01:00
{
2010-06-29 16:45:09 +01:00
$this -> assertEquals ( $expected , var_export ( $this -> parser -> parse ( $yaml ), true ), $comment );
}
public function getDataFormSpecifications ()
{
$parser = new Parser ();
$path = __DIR__ . '/Fixtures' ;
$tests = array ();
$files = $parser -> parse ( file_get_contents ( $path . '/index.yml' ));
2010-05-07 15:09:11 +01:00
foreach ( $files as $file ) {
2010-06-29 16:45:09 +01:00
$yamls = file_get_contents ( $path . '/' . $file . '.yml' );
2010-03-18 07:48:03 +00:00
2010-05-06 12:25:53 +01:00
// split YAMLs documents
2010-05-07 15:09:11 +01:00
foreach ( preg_split ( '/^---( %YAML\:1\.0)?/m' , $yamls ) as $yaml ) {
2010-05-08 14:32:30 +01:00
if ( ! $yaml ) {
2010-05-06 12:25:53 +01:00
continue ;
}
2010-06-29 16:45:09 +01:00
$test = $parser -> parse ( $yaml );
2010-05-07 15:09:11 +01:00
if ( isset ( $test [ 'todo' ]) && $test [ 'todo' ]) {
2010-05-06 12:25:53 +01:00
// TODO
2010-05-07 15:09:11 +01:00
} else {
2014-03-04 16:04:39 +00:00
eval ( '$expected = ' . trim ( $test [ 'php' ]) . ';' );
2010-03-18 07:48:03 +00:00
2014-03-04 16:04:39 +00:00
$tests [] = array ( $file , var_export ( $expected , true ), $test [ 'yaml' ], $test [ 'test' ]);
2010-05-06 12:25:53 +01:00
}
}
2010-03-18 07:48:03 +00:00
}
2010-06-29 16:45:09 +01:00
return $tests ;
2010-03-18 07:48:03 +00:00
}
2010-05-06 12:25:53 +01:00
public function testTabsInYaml ()
2010-03-18 07:48:03 +00:00
{
2010-05-06 12:25:53 +01:00
// test tabs in YAML
$yamls = array (
" foo: \n bar " ,
" foo: \n bar " ,
" foo: \n bar " ,
" foo: \n bar " ,
);
2010-05-07 15:09:11 +01:00
foreach ( $yamls as $yaml ) {
2010-05-08 14:32:30 +01:00
try {
2010-05-06 12:25:53 +01:00
$content = $this -> parser -> parse ( $yaml );
2010-03-18 07:48:03 +00:00
2010-05-06 12:25:53 +01:00
$this -> fail ( 'YAML files must not contain tabs' );
2010-05-07 15:09:11 +01:00
} catch ( \Exception $e ) {
2010-05-06 12:25:53 +01:00
$this -> assertInstanceOf ( '\Exception' , $e , 'YAML files must not contain tabs' );
2011-06-14 11:44:54 +01:00
$this -> assertEquals ( 'A YAML file cannot contain tabs as indentation at line 2 (near "' . strpbrk ( $yaml , " \t " ) . '").' , $e -> getMessage (), 'YAML files must not contain tabs' );
2010-05-06 12:25:53 +01:00
}
}
2010-03-18 07:48:03 +00:00
}
2010-06-29 16:51:05 +01:00
public function testEndOfTheDocumentMarker ()
{
$yaml = <<< EOF
--- % YAML : 1.0
foo
...
EOF ;
$this -> assertEquals ( 'foo' , $this -> parser -> parse ( $yaml ));
}
2013-01-17 23:42:00 +00:00
public function getBlockChompingTests ()
{
$tests = array ();
$yaml = <<< 'EOF'
foo : |-
one
two
2013-03-23 01:54:33 +00:00
bar : |-
one
two
EOF ;
$expected = array (
'foo' => " one \n two " ,
'bar' => " one \n two " ,
);
$tests [ 'Literal block chomping strip with single trailing newline' ] = array ( $expected , $yaml );
$yaml = <<< 'EOF'
foo : |-
one
two
2013-01-17 23:42:00 +00:00
bar : |-
one
two
2013-03-23 01:54:33 +00:00
2013-01-17 23:42:00 +00:00
EOF ;
$expected = array (
'foo' => " one \n two " ,
'bar' => " one \n two " ,
);
2013-03-23 01:54:33 +00:00
$tests [ 'Literal block chomping strip with multiple trailing newlines' ] = array ( $expected , $yaml );
2013-01-17 23:42:00 +00:00
2015-01-12 11:05:05 +00:00
$yaml = <<< 'EOF'
{}
EOF ;
$expected = array ();
$tests [ 'Literal block chomping strip with multiple trailing newlines after a 1-liner' ] = array ( $expected , $yaml );
2013-01-17 23:42:00 +00:00
$yaml = <<< 'EOF'
foo : |-
one
two
bar : |-
one
two
EOF ;
$expected = array (
'foo' => " one \n two " ,
'bar' => " one \n two " ,
);
$tests [ 'Literal block chomping strip without trailing newline' ] = array ( $expected , $yaml );
$yaml = <<< 'EOF'
foo : |
one
two
bar : |
one
two
EOF ;
$expected = array (
'foo' => " one \n two \n " ,
'bar' => " one \n two \n " ,
);
2013-03-23 01:54:33 +00:00
$tests [ 'Literal block chomping clip with single trailing newline' ] = array ( $expected , $yaml );
2013-01-17 23:42:00 +00:00
$yaml = <<< 'EOF'
foo : |
one
two
2013-03-23 01:54:33 +00:00
2013-01-17 23:42:00 +00:00
bar : |
one
two
2013-03-23 01:54:33 +00:00
2013-01-17 23:42:00 +00:00
EOF ;
$expected = array (
'foo' => " one \n two \n " ,
'bar' => " one \n two \n " ,
);
2013-03-23 01:54:33 +00:00
$tests [ 'Literal block chomping clip with multiple trailing newlines' ] = array ( $expected , $yaml );
$yaml = <<< 'EOF'
foo : |
one
two
bar : |
one
two
EOF ;
$expected = array (
'foo' => " one \n two \n " ,
'bar' => " one \n two " ,
);
2013-01-17 23:42:00 +00:00
$tests [ 'Literal block chomping clip without trailing newline' ] = array ( $expected , $yaml );
$yaml = <<< 'EOF'
foo : |+
one
two
2013-03-23 01:54:33 +00:00
bar : |+
one
two
EOF ;
$expected = array (
'foo' => " one \n two \n " ,
'bar' => " one \n two \n " ,
);
$tests [ 'Literal block chomping keep with single trailing newline' ] = array ( $expected , $yaml );
$yaml = <<< 'EOF'
foo : |+
one
two
2013-01-17 23:42:00 +00:00
bar : |+
one
two
2013-03-23 01:54:33 +00:00
2013-01-17 23:42:00 +00:00
EOF ;
$expected = array (
'foo' => " one \n two \n \n " ,
'bar' => " one \n two \n \n " ,
);
2013-03-23 01:54:33 +00:00
$tests [ 'Literal block chomping keep with multiple trailing newlines' ] = array ( $expected , $yaml );
2013-01-17 23:42:00 +00:00
$yaml = <<< 'EOF'
foo : |+
one
two
bar : |+
one
two
EOF ;
$expected = array (
'foo' => " one \n two \n " ,
2013-03-23 01:54:33 +00:00
'bar' => " one \n two " ,
2013-01-17 23:42:00 +00:00
);
$tests [ 'Literal block chomping keep without trailing newline' ] = array ( $expected , $yaml );
$yaml = <<< 'EOF'
foo : >-
one
two
2013-03-23 01:54:33 +00:00
bar : >-
one
two
EOF ;
$expected = array (
2015-03-21 10:51:07 +00:00
'foo' => 'one two' ,
'bar' => 'one two' ,
2013-03-23 01:54:33 +00:00
);
$tests [ 'Folded block chomping strip with single trailing newline' ] = array ( $expected , $yaml );
$yaml = <<< 'EOF'
foo : >-
one
two
2013-01-17 23:42:00 +00:00
bar : >-
one
two
2013-03-23 01:54:33 +00:00
2013-01-17 23:42:00 +00:00
EOF ;
$expected = array (
2015-03-21 10:51:07 +00:00
'foo' => 'one two' ,
'bar' => 'one two' ,
2013-01-17 23:42:00 +00:00
);
2013-03-23 01:54:33 +00:00
$tests [ 'Folded block chomping strip with multiple trailing newlines' ] = array ( $expected , $yaml );
2013-01-17 23:42:00 +00:00
$yaml = <<< 'EOF'
foo : >-
one
two
bar : >-
one
two
EOF ;
$expected = array (
2015-03-21 10:51:07 +00:00
'foo' => 'one two' ,
'bar' => 'one two' ,
2013-01-17 23:42:00 +00:00
);
$tests [ 'Folded block chomping strip without trailing newline' ] = array ( $expected , $yaml );
$yaml = <<< 'EOF'
foo : >
one
two
bar : >
one
two
EOF ;
$expected = array (
'foo' => " one two \n " ,
'bar' => " one two \n " ,
);
2013-03-23 01:54:33 +00:00
$tests [ 'Folded block chomping clip with single trailing newline' ] = array ( $expected , $yaml );
2013-01-17 23:42:00 +00:00
$yaml = <<< 'EOF'
foo : >
one
two
2013-03-23 01:54:33 +00:00
2013-01-17 23:42:00 +00:00
bar : >
one
two
2013-03-23 01:54:33 +00:00
2013-01-17 23:42:00 +00:00
EOF ;
$expected = array (
'foo' => " one two \n " ,
'bar' => " one two \n " ,
);
2013-03-23 01:54:33 +00:00
$tests [ 'Folded block chomping clip with multiple trailing newlines' ] = array ( $expected , $yaml );
$yaml = <<< 'EOF'
foo : >
one
two
bar : >
one
two
EOF ;
$expected = array (
'foo' => " one two \n " ,
2015-03-21 10:51:07 +00:00
'bar' => 'one two' ,
2013-03-23 01:54:33 +00:00
);
2013-01-17 23:42:00 +00:00
$tests [ 'Folded block chomping clip without trailing newline' ] = array ( $expected , $yaml );
$yaml = <<< 'EOF'
foo : >+
one
two
2013-03-23 01:54:33 +00:00
bar : >+
one
two
EOF ;
$expected = array (
'foo' => " one two \n " ,
'bar' => " one two \n " ,
);
$tests [ 'Folded block chomping keep with single trailing newline' ] = array ( $expected , $yaml );
$yaml = <<< 'EOF'
foo : >+
one
two
2013-01-17 23:42:00 +00:00
bar : >+
one
two
2013-03-23 01:54:33 +00:00
2013-01-17 23:42:00 +00:00
EOF ;
$expected = array (
'foo' => " one two \n \n " ,
'bar' => " one two \n \n " ,
);
2013-03-23 01:54:33 +00:00
$tests [ 'Folded block chomping keep with multiple trailing newlines' ] = array ( $expected , $yaml );
2013-01-17 23:42:00 +00:00
$yaml = <<< 'EOF'
foo : >+
one
two
bar : >+
one
two
EOF ;
$expected = array (
'foo' => " one two \n " ,
2015-03-21 10:51:07 +00:00
'bar' => 'one two' ,
2013-01-17 23:42:00 +00:00
);
$tests [ 'Folded block chomping keep without trailing newline' ] = array ( $expected , $yaml );
return $tests ;
}
/**
* @ dataProvider getBlockChompingTests
*/
public function testBlockChomping ( $expected , $yaml )
{
$this -> assertSame ( $expected , $this -> parser -> parse ( $yaml ));
}
2013-05-10 01:09:46 +01:00
/**
* Regression test for issue #7989.
*
* @ see https :// github . com / symfony / symfony / issues / 7989
*/
public function testBlockLiteralWithLeadingNewlines ()
{
$yaml = <<< 'EOF'
foo : |-
bar
EOF ;
$expected = array (
2014-09-21 19:53:12 +01:00
'foo' => " \n \n bar " ,
2013-05-10 01:09:46 +01:00
);
$this -> assertSame ( $expected , $this -> parser -> parse ( $yaml ));
}
added a way to enable/disable object support when parsing/dumping
By default, object support is disabled, and instead of throwing an
exception when an object is handled, null is returned.
If you do need object support, enable it via:
Yaml::dump($data, false, true);
If you want an exception to be thrown in case an invalid type is handled
(a PHP resource or a PHP object), pass true as the second argument:
Yaml::dump($data, true, true);
The same can be done when parsing:
Yaml::parse($data, 2, false, true);
2013-01-17 08:34:45 +00:00
public function testObjectSupportEnabled ()
2010-05-06 12:25:53 +01:00
{
added a way to enable/disable object support when parsing/dumping
By default, object support is disabled, and instead of throwing an
exception when an object is handled, null is returned.
If you do need object support, enable it via:
Yaml::dump($data, false, true);
If you want an exception to be thrown in case an invalid type is handled
(a PHP resource or a PHP object), pass true as the second argument:
Yaml::dump($data, true, true);
The same can be done when parsing:
Yaml::parse($data, 2, false, true);
2013-01-17 08:34:45 +00:00
$input = <<< EOF
2012-03-28 14:43:52 +01:00
foo : !! php / object : O : 30 : " Symfony \ Component \ Yaml \T ests \ B " : 1 : { s : 1 : " b " ; s : 3 : " foo " ;}
2010-03-18 07:48:03 +00:00
bar : 1
added a way to enable/disable object support when parsing/dumping
By default, object support is disabled, and instead of throwing an
exception when an object is handled, null is returned.
If you do need object support, enable it via:
Yaml::dump($data, false, true);
If you want an exception to be thrown in case an invalid type is handled
(a PHP resource or a PHP object), pass true as the second argument:
Yaml::dump($data, true, true);
The same can be done when parsing:
Yaml::parse($data, 2, false, true);
2013-01-17 08:34:45 +00:00
EOF ;
$this -> assertEquals ( array ( 'foo' => new B (), 'bar' => 1 ), $this -> parser -> parse ( $input , false , true ), '->parse() is able to parse objects' );
}
public function testObjectSupportDisabledButNoExceptions ()
{
$input = <<< EOF
foo : !! php / object : O : 30 : " Symfony \T ests \ Component \ Yaml \ B " : 1 : { s : 1 : " b " ; s : 3 : " foo " ;}
bar : 1
EOF ;
$this -> assertEquals ( array ( 'foo' => null , 'bar' => 1 ), $this -> parser -> parse ( $input ), '->parse() does not parse objects' );
}
/**
* @ expectedException \Symfony\Component\Yaml\Exception\ParseException
*/
public function testObjectsSupportDisabledWithExceptions ()
{
$this -> parser -> parse ( 'foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}' , true , false );
2010-05-06 12:25:53 +01:00
}
2011-05-12 21:02:56 +01:00
2015-10-08 10:41:54 +01:00
/**
* @ requires extension iconv
*/
2011-05-12 21:02:56 +01:00
public function testNonUtf8Exception ()
{
$yamls = array (
2015-03-21 10:51:07 +00:00
iconv ( 'UTF-8' , 'ISO-8859-1' , " foo: 'äöüß' " ),
iconv ( 'UTF-8' , 'ISO-8859-15' , " euro: '€' " ),
iconv ( 'UTF-8' , 'CP1252' , " cp1252: '©ÉÇáñ' " ),
2011-05-12 21:02:56 +01:00
);
2011-05-13 00:08:37 +01:00
foreach ( $yamls as $yaml ) {
2011-05-12 21:02:56 +01:00
try {
$this -> parser -> parse ( $yaml );
$this -> fail ( 'charsets other than UTF-8 are rejected.' );
2011-05-13 00:08:37 +01:00
} catch ( \Exception $e ) {
2014-09-21 19:53:12 +01:00
$this -> assertInstanceOf ( 'Symfony\Component\Yaml\Exception\ParseException' , $e , 'charsets other than UTF-8 are rejected.' );
2011-05-12 21:02:56 +01:00
}
}
}
2012-04-26 18:34:19 +01:00
/**
2013-01-05 17:52:40 +00:00
* @ expectedException \Symfony\Component\Yaml\Exception\ParseException
2012-04-26 18:34:19 +01:00
*/
public function testUnindentedCollectionException ()
{
$yaml = <<< EOF
collection :
- item1
- item2
- item3
2015-01-10 08:51:00 +00:00
EOF ;
$this -> parser -> parse ( $yaml );
}
/**
* @ expectedException \Symfony\Component\Yaml\Exception\ParseException
*/
public function testShortcutKeyUnindentedCollectionException ()
{
$yaml = <<< EOF
collection :
- key : foo
foo : bar
2012-04-26 18:34:19 +01:00
EOF ;
$this -> parser -> parse ( $yaml );
}
2014-11-01 12:21:10 +00:00
/**
* @ expectedException \Symfony\Component\Yaml\Exception\ParseException
* @ expectedExceptionMessage Multiple documents are not supported .
*/
public function testMultipleDocumentsNotSupportedException ()
{
Yaml :: parse ( <<< EOL
# Ranking of 1998 home runs
---
- Mark McGwire
- Sammy Sosa
- Ken Griffey
# Team ranking
---
- Chicago Cubs
- St Louis Cardinals
EOL
);
}
2012-07-01 10:19:53 +01:00
/**
2013-01-05 17:52:40 +00:00
* @ expectedException \Symfony\Component\Yaml\Exception\ParseException
2012-07-01 10:19:53 +01:00
*/
public function testSequenceInAMapping ()
{
Yaml :: parse ( <<< EOF
yaml :
hash : me
- array stuff
EOF
);
}
/**
2013-01-05 17:52:40 +00:00
* @ expectedException \Symfony\Component\Yaml\Exception\ParseException
2012-07-01 10:19:53 +01:00
*/
public function testMappingInASequence ()
{
Yaml :: parse ( <<< EOF
yaml :
- array stuff
hash : me
EOF
);
}
2013-04-12 10:29:40 +01:00
2015-07-22 07:30:32 +01:00
/**
* @ expectedException \Symfony\Component\Yaml\Exception\ParseException
* @ expectedExceptionMessage missing colon
*/
public function testScalarInSequence ()
{
Yaml :: parse ( <<< EOF
foo :
- bar
" missing colon "
foo : bar
EOF
);
}
2014-05-15 01:05:21 +01:00
/**
* > It is an error for two equal keys to appear in the same mapping node .
* > In such a case the YAML processor may continue , ignoring the second
* > `key: value` pair and issuing an appropriate warning . This strategy
* > preserves a consistent information model for one - pass and random access
* > applications .
*
* @ see http :// yaml . org / spec / 1.2 / spec . html #id2759572
* @ see http :// yaml . org / spec / 1.1 / #id932806
*/
public function testMappingDuplicateKeyBlock ()
{
$input = <<< EOD
parent :
child : first
child : duplicate
parent :
child : duplicate
child : duplicate
EOD ;
$expected = array (
'parent' => array (
'child' => 'first' ,
),
);
$this -> assertSame ( $expected , Yaml :: parse ( $input ));
}
public function testMappingDuplicateKeyFlow ()
{
$input = <<< EOD
parent : { child : first , child : duplicate }
parent : { child : duplicate , child : duplicate }
EOD ;
$expected = array (
'parent' => array (
'child' => 'first' ,
),
);
$this -> assertSame ( $expected , Yaml :: parse ( $input ));
}
2013-04-12 10:29:40 +01:00
public function testEmptyValue ()
{
$input = <<< EOF
hash :
EOF ;
$this -> assertEquals ( array ( 'hash' => null ), Yaml :: parse ( $input ));
}
2013-07-11 10:21:24 +01:00
2015-10-02 12:13:24 +01:00
public function testCommentAtTheRootIndent ()
{
$this -> assertEquals ( array (
'services' => array (
'app.foo_service' => array (
'class' => 'Foo' ,
),
'app/bar_service' => array (
'class' => 'Bar' ,
),
),
), Yaml :: parse ( <<< EOF
# comment 1
services :
# comment 2
# comment 3
app . foo_service :
class : Foo
# comment 4
# comment 5
app / bar_service :
class : Bar
EOF
));
}
2013-07-11 10:21:24 +01:00
public function testStringBlockWithComments ()
{
$this -> assertEquals ( array ( 'content' => <<< EOT
# comment 1
header
# comment 2
< body >
< h1 > title </ h1 >
</ body >
footer # comment3
EOT
), Yaml :: parse ( <<< EOF
content : |
# comment 1
header
# comment 2
< body >
< h1 > title </ h1 >
</ body >
footer # comment3
EOF
));
}
2013-08-24 07:35:53 +01:00
public function testFoldedStringBlockWithComments ()
2013-07-11 10:21:24 +01:00
{
$this -> assertEquals ( array ( array ( 'content' => <<< EOT
# comment 1
header
# comment 2
< body >
< h1 > title </ h1 >
</ body >
footer # comment3
EOT
)), Yaml :: parse ( <<< EOF
-
content : |
# comment 1
header
# comment 2
< body >
< h1 > title </ h1 >
</ body >
footer # comment3
2013-08-24 07:35:53 +01:00
EOF
));
}
public function testNestedFoldedStringBlockWithComments ()
{
$this -> assertEquals ( array ( array (
2014-10-22 19:27:13 +01:00
'title' => 'some title' ,
2013-08-24 07:35:53 +01:00
'content' => <<< EOT
# comment 1
header
# comment 2
< body >
< h1 > title </ h1 >
</ body >
footer # comment3
EOT
)), Yaml :: parse ( <<< EOF
-
title : some title
content : |
# comment 1
header
# comment 2
< body >
< h1 > title </ h1 >
</ body >
footer # comment3
2014-08-15 13:16:41 +01:00
EOF
));
}
public function testReferenceResolvingInInlineStrings ()
{
$this -> assertEquals ( array (
'var' => 'var-value' ,
'scalar' => 'var-value' ,
'list' => array ( 'var-value' ),
'list_in_list' => array ( array ( 'var-value' )),
'map_in_list' => array ( array ( 'key' => 'var-value' )),
'embedded_mapping' => array ( array ( 'key' => 'var-value' )),
'map' => array ( 'key' => 'var-value' ),
'list_in_map' => array ( 'key' => array ( 'var-value' )),
'map_in_map' => array ( 'foo' => array ( 'bar' => 'var-value' )),
), Yaml :: parse ( <<< EOF
var : & var var - value
scalar : * var
list : [ * var ]
list_in_list : [[ * var ]]
map_in_list : [ { key : * var } ]
embedded_mapping : [ key : * var ]
map : { key : * var }
list_in_map : { key : [ * var ] }
map_in_map : { foo : { bar : * var } }
2013-07-11 10:21:24 +01:00
EOF
));
}
2015-01-08 15:45:16 +00:00
public function testYamlDirective ()
{
$yaml = <<< EOF
% YAML 1.2
---
foo : 1
bar : 2
EOF ;
$this -> assertEquals ( array ( 'foo' => 1 , 'bar' => 2 ), $this -> parser -> parse ( $yaml ));
}
2015-09-12 16:58:59 +01:00
public function testFloatKeys ()
{
$yaml = <<< EOF
foo :
1.2 : " bar "
1.3 : " baz "
EOF ;
$expected = array (
'foo' => array (
'1.2' => 'bar' ,
'1.3' => 'baz' ,
),
);
$this -> assertEquals ( $expected , $this -> parser -> parse ( $yaml ));
}
2015-11-03 07:24:46 +00:00
/**
* @ group legacy
* throw ParseException in Symfony 3.0
*/
public function testColonInMappingValueException ()
{
$yaml = <<< EOF
foo : bar : baz
EOF ;
$deprecations = array ();
set_error_handler ( function ( $type , $msg ) use ( & $deprecations ) {
if ( E_USER_DEPRECATED === $type ) {
$deprecations [] = $msg ;
}
});
$this -> parser -> parse ( $yaml );
$this -> assertCount ( 1 , $deprecations );
$this -> assertContains ( 'Using a colon in an unquoted mapping value in line 1 is deprecated since Symfony 2.8 and will throw a ParseException in 3.0.' , $deprecations [ 0 ]);
restore_error_handler ();
}
2010-03-18 07:48:03 +00:00
}
class B
{
2010-05-06 12:25:53 +01:00
public $b = 'foo' ;
2010-03-18 07:48:03 +00:00
}