PhpDumperTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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\PhpDumper;
  12. $t = new LimeTest(5);
  13. $fixturesPath = realpath(__DIR__.'/../../../../../fixtures/Symfony/Components/DependencyInjection/');
  14. // ->dump()
  15. $t->diag('->dump()');
  16. $dumper = new PhpDumper($container = new Builder());
  17. $t->is($dumper->dump(), file_get_contents($fixturesPath.'/php/services1.php'), '->dump() dumps an empty container as an empty PHP class');
  18. $t->is($dumper->dump(array('class' => 'Container', 'base_class' => 'AbstractContainer')), file_get_contents($fixturesPath.'/php/services1-1.php'), '->dump() takes a class and a base_class options');
  19. $container = new Builder();
  20. $dumper = new PhpDumper($container);
  21. // ->addParameters()
  22. $t->diag('->addParameters()');
  23. $container = include $fixturesPath.'/containers/container8.php';
  24. $dumper = new PhpDumper($container);
  25. $t->is($dumper->dump(), file_get_contents($fixturesPath.'/php/services8.php'), '->dump() dumps parameters');
  26. // ->addService()
  27. $t->diag('->addService()');
  28. $container = include $fixturesPath.'/containers/container9.php';
  29. $dumper = new PhpDumper($container);
  30. $t->is($dumper->dump(), str_replace('%path%', $fixturesPath.'/includes', file_get_contents($fixturesPath.'/php/services9.php')), '->dump() dumps services');
  31. $dumper = new PhpDumper($container = new Builder());
  32. $container->register('foo', 'FooClass')->addArgument(new stdClass());
  33. try
  34. {
  35. $dumper->dump();
  36. $t->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
  37. }
  38. catch (RuntimeException $e)
  39. {
  40. $t->pass('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
  41. }