Skip to content

Commit

Permalink
Add Symfony Yaml PHP constants support integration (2.x) (#828)
Browse files Browse the repository at this point in the history
  • Loading branch information
soullivaneuh authored and theofidry committed Oct 31, 2017
1 parent c5a129a commit 41fc89e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Nelmio/Alice/Fixtures/Parser/Methods/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Nelmio\Alice\Fixtures\Parser\Methods;

use Nelmio\Alice\Fixtures\Loader;
use Symfony\Component\Yaml\Yaml as YamlParser;

/**
Expand Down Expand Up @@ -44,7 +43,9 @@ class Yaml extends Base
public function parse($file)
{
$yaml = $this->compilePhp($file);
$data = YamlParser::parse($yaml);
$data = defined('Symfony\\Component\\Yaml\\Yaml::PARSE_CONSTANT')
? YamlParser::parse($yaml, YamlParser::PARSE_CONSTANT)
: YamlParser::parse($yaml);

if (!is_array($data)) {
throw new \UnexpectedValueException('Yaml files must parse to an array of data');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# This file is part of the Alice package.
#
# (c) Nelmio <hello@nelm.io>
#
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.
#

max_int: !php/const:PHP_INT_MAX
15 changes: 15 additions & 0 deletions tests/Nelmio/Alice/Fixtures/Parser/Methods/YamlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ public function testParseReturnsAYamlArray()
);
}

public function testParseReturnsInterpretedConstants()
{
if (!defined('Symfony\\Component\\Yaml\\Yaml::PARSE_CONSTANT')) {
$this->markTestSkipped('This test needs symfony/yaml v3.2 or higher.');
}
$data = $this->parser->parse(self::$dir.'/file_with_constants.yml');

$this->assertSame(
[
'max_int' => PHP_INT_MAX,
],
$data
);
}

/**
* @group legacy
*/
Expand Down

0 comments on commit 41fc89e

Please sign in to comment.