Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / symfony / dependency-injection / Tests / CrossCheckTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\DependencyInjection\Tests;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Config\FileLocator;
16 use Symfony\Component\DependencyInjection\ContainerBuilder;
17
18 class CrossCheckTest extends TestCase
19 {
20     protected static $fixturesPath;
21
22     public static function setUpBeforeClass()
23     {
24         self::$fixturesPath = __DIR__.'/Fixtures/';
25
26         require_once self::$fixturesPath.'/includes/classes.php';
27         require_once self::$fixturesPath.'/includes/foo.php';
28     }
29
30     /**
31      * @dataProvider crossCheckLoadersDumpers
32      */
33     public function testCrossCheck($fixture, $type)
34     {
35         $loaderClass = 'Symfony\\Component\\DependencyInjection\\Loader\\'.ucfirst($type).'FileLoader';
36         $dumperClass = 'Symfony\\Component\\DependencyInjection\\Dumper\\'.ucfirst($type).'Dumper';
37
38         $tmp = tempnam(sys_get_temp_dir(), 'sf');
39
40         copy(self::$fixturesPath.'/'.$type.'/'.$fixture, $tmp);
41
42         $container1 = new ContainerBuilder();
43         $loader1 = new $loaderClass($container1, new FileLocator());
44         $loader1->load($tmp);
45
46         $dumper = new $dumperClass($container1);
47         file_put_contents($tmp, $dumper->dump());
48
49         $container2 = new ContainerBuilder();
50         $loader2 = new $loaderClass($container2, new FileLocator());
51         $loader2->load($tmp);
52
53         unlink($tmp);
54
55         $this->assertEquals($container2->getAliases(), $container1->getAliases(), 'loading a dump from a previously loaded container returns the same container');
56         $this->assertEquals($container2->getDefinitions(), $container1->getDefinitions(), 'loading a dump from a previously loaded container returns the same container');
57         $this->assertEquals($container2->getParameterBag()->all(), $container1->getParameterBag()->all(), '->getParameterBag() returns the same value for both containers');
58
59         $r = new \ReflectionProperty(ContainerBuilder::class, 'normalizedIds');
60         $r->setAccessible(true);
61         $r->setValue($container2, array());
62         $r->setValue($container1, array());
63
64         $this->assertEquals(serialize($container2), serialize($container1), 'loading a dump from a previously loaded container returns the same container');
65
66         $services1 = array();
67         foreach ($container1 as $id => $service) {
68             $services1[$id] = serialize($service);
69         }
70         $services2 = array();
71         foreach ($container2 as $id => $service) {
72             $services2[$id] = serialize($service);
73         }
74
75         unset($services1['service_container'], $services2['service_container']);
76
77         $this->assertEquals($services2, $services1, 'Iterator on the containers returns the same services');
78     }
79
80     public function crossCheckLoadersDumpers()
81     {
82         return array(
83             array('services1.xml', 'xml'),
84             array('services2.xml', 'xml'),
85             array('services6.xml', 'xml'),
86             array('services8.xml', 'xml'),
87             array('services9.xml', 'xml'),
88             array('services1.yml', 'yaml'),
89             array('services2.yml', 'yaml'),
90             array('services6.yml', 'yaml'),
91             array('services8.yml', 'yaml'),
92             array('services9.yml', 'yaml'),
93         );
94     }
95 }