YamlDumperTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. require_once __DIR__.'/../../../../bootstrap.php';
  10. use Symfony\Components\DependencyInjection\Builder;
  11. use Symfony\Components\DependencyInjection\Dumper\YamlDumper;
  12. $t = new LimeTest(4);
  13. $fixturesPath = realpath(__DIR__.'/../../../../../fixtures/Symfony/Components/DependencyInjection/');
  14. // ->dump()
  15. $t->diag('->dump()');
  16. $dumper = new YamlDumper($container = new Builder());
  17. $t->is($dumper->dump(), file_get_contents($fixturesPath.'/yaml/services1.yml'), '->dump() dumps an empty container as an empty YAML file');
  18. $container = new Builder();
  19. $dumper = new YamlDumper($container);
  20. // ->addParameters()
  21. $t->diag('->addParameters()');
  22. $container = include $fixturesPath.'/containers/container8.php';
  23. $dumper = new YamlDumper($container);
  24. $t->is($dumper->dump(), file_get_contents($fixturesPath.'/yaml/services8.yml'), '->dump() dumps parameters');
  25. // ->addService()
  26. $t->diag('->addService()');
  27. $container = include $fixturesPath.'/containers/container9.php';
  28. $dumper = new YamlDumper($container);
  29. $t->is($dumper->dump(), str_replace('%path%', $fixturesPath.'/includes', file_get_contents($fixturesPath.'/yaml/services9.yml')), '->dump() dumps services');
  30. $dumper = new YamlDumper($container = new Builder());
  31. $container->register('foo', 'FooClass')->addArgument(new stdClass());
  32. try
  33. {
  34. $dumper->dump();
  35. $t->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
  36. }
  37. catch (RuntimeException $e)
  38. {
  39. $t->pass('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
  40. }