<?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.
*/namespaceSymfony\Component\DependencyInjection\Tests\Dumper;
useSymfony\Component\DependencyInjection\ContainerBuilder;
useSymfony\Component\DependencyInjection\Dumper\YamlDumper;
class YamlDumperTestextends \PHPUnit_Framework_TestCase {
protected static $fixturesPath;
protected functionsetUp() {
if (!class_exists('Symfony\\Component\\Config\\Loader\\Loader')) {
$this
->markTestSkipped('The "Config" component is not available');
}
}
public static functionsetUpBeforeClass() {
self::$fixturesPath = realpath(__DIR__ . '/../Fixtures/');
}
public functiontestDump() {
$dumper = newYamlDumper($container = newContainerBuilder());
$this
->assertStringEqualsFile(self::$fixturesPath . '/yaml/services1.yml', $dumper
->dump(), '->dump() dumps an empty container as an empty YAML file');
$container = newContainerBuilder();
$dumper = newYamlDumper($container);
}
public functiontestAddParameters() {
$container = (includeself::$fixturesPath . '/containers/container8.php');
$dumper = newYamlDumper($container);
$this
->assertStringEqualsFile(self::$fixturesPath . '/yaml/services8.yml', $dumper
->dump(), '->dump() dumps parameters');
}
public functiontestAddService() {
$container = (includeself::$fixturesPath . '/containers/container9.php');
$dumper = newYamlDumper($container);
$this
->assertEquals(str_replace('%path%', self::$fixturesPath . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR, file_get_contents(self::$fixturesPath . '/yaml/services9.yml')), $dumper
->dump(), '->dump() dumps services');
$dumper = newYamlDumper($container = newContainerBuilder());
$container
->register('foo', 'FooClass')
->addArgument(new\stdClass());
try {
$dumper
->dump();
$this
->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
} catch (\Exception $e) {
$this
->assertInstanceOf('\\RuntimeException', $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
$this
->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e
->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
}
}
}