XmlDumperTest.php 2.0 KB

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