Пример #1
0
 public function testAddService()
 {
     $container = (include self::$fixturesPath . '/containers/container9.php');
     $dumper = new YamlDumper($container);
     $this->assertEquals($dumper->dump(), str_replace('%path%', self::$fixturesPath . '/includes', file_get_contents(self::$fixturesPath . '/yaml/services9.yml')), '->dump() dumps services');
     $dumper = new YamlDumper($container = new Builder());
     $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 (\RuntimeException $e) {
     }
 }
Пример #2
0
 public function testAddService()
 {
     $container = (include self::$fixturesPath . '/containers/container9.php');
     $dumper = new YamlDumper($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 = new YamlDumper($container = new ContainerBuilder());
     $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');
     }
 }
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../../bootstrap.php';
use Symfony\Components\DependencyInjection\Builder;
use Symfony\Components\DependencyInjection\Dumper\YamlDumper;
$t = new LimeTest(4);
$fixturesPath = realpath(__DIR__ . '/../../../../../fixtures/Symfony/Components/DependencyInjection/');
// ->dump()
$t->diag('->dump()');
$dumper = new YamlDumper($container = new Builder());
$t->is($dumper->dump(), file_get_contents($fixturesPath . '/yaml/services1.yml'), '->dump() dumps an empty container as an empty YAML file');
$container = new Builder();
$dumper = new YamlDumper($container);
// ->addParameters()
$t->diag('->addParameters()');
$container = (include $fixturesPath . '/containers/container8.php');
$dumper = new YamlDumper($container);
$t->is($dumper->dump(), file_get_contents($fixturesPath . '/yaml/services8.yml'), '->dump() dumps parameters');
// ->addService()
$t->diag('->addService()');
$container = (include $fixturesPath . '/containers/container9.php');
$dumper = new YamlDumper($container);
$t->is($dumper->dump(), str_replace('%path%', $fixturesPath . '/includes', file_get_contents($fixturesPath . '/yaml/services9.yml')), '->dump() dumps services');
$dumper = new YamlDumper($container = new Builder());
$container->register('foo', 'FooClass')->addArgument(new stdClass());
try {
    $dumper->dump();
    $t->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
} catch (RuntimeException $e) {
    $t->pass('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
}