GraphvizDumperTest.php 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\DependencyInjection\Tests\Dumper;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\Dumper\GraphvizDumper;
  14. class GraphvizDumperTest extends TestCase
  15. {
  16. protected static $fixturesPath;
  17. public static function setUpBeforeClass()
  18. {
  19. self::$fixturesPath = __DIR__.'/../Fixtures/';
  20. }
  21. /**
  22. * @group legacy
  23. */
  24. public function testLegacyDump()
  25. {
  26. $container = include self::$fixturesPath.'/containers/legacy-container9.php';
  27. $dumper = new GraphvizDumper($container);
  28. $this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/legacy-services9.dot')), $dumper->dump(), '->dump() dumps services');
  29. }
  30. public function testDump()
  31. {
  32. $dumper = new GraphvizDumper($container = new ContainerBuilder());
  33. $this->assertStringEqualsFile(self::$fixturesPath.'/graphviz/services1.dot', $dumper->dump(), '->dump() dumps an empty container as an empty dot file');
  34. $container = include self::$fixturesPath.'/containers/container9.php';
  35. $dumper = new GraphvizDumper($container);
  36. $this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services9.dot')), $dumper->dump(), '->dump() dumps services');
  37. $container = include self::$fixturesPath.'/containers/container10.php';
  38. $dumper = new GraphvizDumper($container);
  39. $this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services10.dot')), $dumper->dump(), '->dump() dumps services');
  40. $container = include self::$fixturesPath.'/containers/container10.php';
  41. $dumper = new GraphvizDumper($container);
  42. $this->assertEquals($dumper->dump(array(
  43. 'graph' => array('ratio' => 'normal'),
  44. 'node' => array('fontsize' => 13, 'fontname' => 'Verdana', 'shape' => 'square'),
  45. 'edge' => array('fontsize' => 12, 'fontname' => 'Verdana', 'color' => 'white', 'arrowhead' => 'closed', 'arrowsize' => 1),
  46. 'node.instance' => array('fillcolor' => 'green', 'style' => 'empty'),
  47. 'node.definition' => array('fillcolor' => 'grey'),
  48. 'node.missing' => array('fillcolor' => 'red', 'style' => 'empty'),
  49. )), str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services10-1.dot')), '->dump() dumps services');
  50. }
  51. public function testDumpWithFrozenContainer()
  52. {
  53. $container = include self::$fixturesPath.'/containers/container13.php';
  54. $dumper = new GraphvizDumper($container);
  55. $this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services13.dot')), $dumper->dump(), '->dump() dumps services');
  56. }
  57. public function testDumpWithFrozenCustomClassContainer()
  58. {
  59. $container = include self::$fixturesPath.'/containers/container14.php';
  60. $dumper = new GraphvizDumper($container);
  61. $this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services14.dot')), $dumper->dump(), '->dump() dumps services');
  62. }
  63. public function testDumpWithUnresolvedParameter()
  64. {
  65. $container = include self::$fixturesPath.'/containers/container17.php';
  66. $dumper = new GraphvizDumper($container);
  67. $this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services17.dot')), $dumper->dump(), '->dump() dumps services');
  68. }
  69. /**
  70. * @group legacy
  71. */
  72. public function testDumpWithScopes()
  73. {
  74. $container = include self::$fixturesPath.'/containers/legacy-container18.php';
  75. $dumper = new GraphvizDumper($container);
  76. $this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services18.dot')), $dumper->dump(), '->dump() dumps services');
  77. }
  78. }