YamlDumperTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. namespace Symfony\Tests\Components\DependencyInjection\Dumper;
  10. require_once __DIR__.'/../../../bootstrap.php';
  11. use Symfony\Components\DependencyInjection\Builder;
  12. use Symfony\Components\DependencyInjection\Dumper\YamlDumper;
  13. class YamlDumperTest extends \PHPUnit_Framework_TestCase
  14. {
  15. static protected $fixturesPath;
  16. static public function setUpBeforeClass()
  17. {
  18. self::$fixturesPath = realpath(__DIR__.'/../../../../../fixtures/Symfony/Components/DependencyInjection/');
  19. }
  20. public function testDump()
  21. {
  22. $dumper = new YamlDumper($container = new Builder());
  23. $this->assertEquals(file_get_contents(self::$fixturesPath.'/yaml/services1.yml'), $dumper->dump(), '->dump() dumps an empty container as an empty YAML file');
  24. $container = new Builder();
  25. $dumper = new YamlDumper($container);
  26. }
  27. public function testAddParameters()
  28. {
  29. $container = include self::$fixturesPath.'/containers/container8.php';
  30. $dumper = new YamlDumper($container);
  31. $this->assertEquals(file_get_contents(self::$fixturesPath.'/yaml/services8.yml'), $dumper->dump(), '->dump() dumps parameters');
  32. }
  33. public function testAddService()
  34. {
  35. $container = include self::$fixturesPath.'/containers/container9.php';
  36. $dumper = new YamlDumper($container);
  37. $this->assertEquals(str_replace('%path%', self::$fixturesPath.'/includes', file_get_contents(self::$fixturesPath.'/yaml/services9.yml')), $dumper->dump(), '->dump() dumps services');
  38. $dumper = new YamlDumper($container = new Builder());
  39. $container->register('foo', 'FooClass')->addArgument(new \stdClass());
  40. try
  41. {
  42. $dumper->dump();
  43. $this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
  44. }
  45. catch (\RuntimeException $e)
  46. {
  47. }
  48. }
  49. }