CrossCheckTest.php 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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\Tests\Component\DependencyInjection;
  11. use Symfony\Component\DependencyInjection\ContainerBuilder;
  12. use Symfony\Component\Config\FileLocator;
  13. class CrossCheckTest extends \PHPUnit_Framework_TestCase
  14. {
  15. static protected $fixturesPath;
  16. static public function setUpBeforeClass()
  17. {
  18. self::$fixturesPath = __DIR__.'/Fixtures/';
  19. require_once self::$fixturesPath.'/includes/classes.php';
  20. require_once self::$fixturesPath.'/includes/foo.php';
  21. }
  22. /**
  23. * @dataProvider crossCheckLoadersDumpers
  24. */
  25. public function testCrossCheck($fixture, $type)
  26. {
  27. $loaderClass = 'Symfony\\Component\\DependencyInjection\\Loader\\'.ucfirst($type).'FileLoader';
  28. $dumperClass = 'Symfony\\Component\\DependencyInjection\\Dumper\\'.ucfirst($type).'Dumper';
  29. $tmp = tempnam('sf_service_container', 'sf');
  30. file_put_contents($tmp, file_get_contents(self::$fixturesPath.'/'.$type.'/'.$fixture));
  31. $container1 = new ContainerBuilder();
  32. $loader1 = new $loaderClass($container1, new FileLocator());
  33. $loader1->load($tmp);
  34. $dumper = new $dumperClass($container1);
  35. file_put_contents($tmp, $dumper->dump());
  36. $container2 = new ContainerBuilder();
  37. $loader2 = new $loaderClass($container2, new FileLocator());
  38. $loader2->load($tmp);
  39. unlink($tmp);
  40. $this->assertEquals($container2->getAliases(), $container1->getAliases(), 'loading a dump from a previously loaded container returns the same container');
  41. $this->assertEquals($container2->getDefinitions(), $container1->getDefinitions(), 'loading a dump from a previously loaded container returns the same container');
  42. $this->assertEquals($container2->getParameterBag()->all(), $container1->getParameterBag()->all(), '->getParameterBag() returns the same value for both containers');
  43. $this->assertEquals(serialize($container2), serialize($container1), 'loading a dump from a previously loaded container returns the same container');
  44. $services1 = array();
  45. foreach ($container1 as $id => $service) {
  46. $services1[$id] = serialize($service);
  47. }
  48. $services2 = array();
  49. foreach ($container2 as $id => $service) {
  50. $services2[$id] = serialize($service);
  51. }
  52. unset($services1['service_container'], $services2['service_container']);
  53. $this->assertEquals($services2, $services1, 'Iterator on the containers returns the same services');
  54. }
  55. public function crossCheckLoadersDumpers()
  56. {
  57. return array(
  58. array('services1.xml', 'xml'),
  59. array('services2.xml', 'xml'),
  60. array('services6.xml', 'xml'),
  61. array('services8.xml', 'xml'),
  62. array('services9.xml', 'xml'),
  63. array('services1.yml', 'yaml'),
  64. array('services2.yml', 'yaml'),
  65. array('services6.yml', 'yaml'),
  66. array('services8.yml', 'yaml'),
  67. array('services9.yml', 'yaml'),
  68. );
  69. }
  70. }