2010-03-18 07:48:03 +00:00
< ? php
/*
2010-04-25 16:06:54 +01:00
* This file is part of the Symfony package .
2011-01-15 13:29:43 +00:00
*
2011-03-06 11:40:06 +00:00
* ( c ) Fabien Potencier < fabien @ symfony . com >
2010-04-07 02:07:59 +01:00
*
2010-03-18 07:48:03 +00:00
* For the full copyright and license information , please view the LICENSE
* file that was distributed with this source code .
*/
2010-08-20 22:09:55 +01:00
namespace Symfony\Tests\Component\DependencyInjection ;
2010-03-18 07:48:03 +00:00
2010-08-20 22:09:55 +01:00
use Symfony\Component\DependencyInjection\ContainerBuilder ;
2011-02-10 15:15:51 +00:00
use Symfony\Component\Config\FileLocator ;
2010-03-18 07:48:03 +00:00
class CrossCheckTest extends \PHPUnit_Framework_TestCase
{
2010-05-06 12:25:53 +01:00
static protected $fixturesPath ;
2010-03-18 07:48:03 +00:00
2010-05-06 12:25:53 +01:00
static public function setUpBeforeClass ()
{
2010-06-28 08:31:54 +01:00
self :: $fixturesPath = __DIR__ . '/Fixtures/' ;
2010-03-18 07:48:03 +00:00
2010-05-06 12:25:53 +01:00
require_once self :: $fixturesPath . '/includes/classes.php' ;
require_once self :: $fixturesPath . '/includes/foo.php' ;
}
2010-03-18 07:48:03 +00:00
2010-05-06 12:25:53 +01:00
/**
* @ dataProvider crossCheckLoadersDumpers
*/
public function testCrossCheck ( $fixture , $type )
{
2010-08-20 22:09:55 +01:00
$loaderClass = 'Symfony\\Component\\DependencyInjection\\Loader\\' . ucfirst ( $type ) . 'FileLoader' ;
$dumperClass = 'Symfony\\Component\\DependencyInjection\\Dumper\\' . ucfirst ( $type ) . 'Dumper' ;
2010-03-18 07:48:03 +00:00
2010-07-16 08:15:22 +01:00
$tmp = tempnam ( 'sf_service_container' , 'sf' );
file_put_contents ( $tmp , file_get_contents ( self :: $fixturesPath . '/' . $type . '/' . $fixture ));
2010-07-16 08:12:58 +01:00
$container1 = new ContainerBuilder ();
2011-02-09 23:44:02 +00:00
$loader1 = new $loaderClass ( $container1 , new FileLocator ());
2010-07-16 08:12:58 +01:00
$loader1 -> load ( $tmp );
2010-03-18 07:48:03 +00:00
2010-05-06 12:25:53 +01:00
$dumper = new $dumperClass ( $container1 );
file_put_contents ( $tmp , $dumper -> dump ());
2010-03-18 07:48:03 +00:00
2010-07-16 08:12:58 +01:00
$container2 = new ContainerBuilder ();
2011-02-09 23:44:02 +00:00
$loader2 = new $loaderClass ( $container2 , new FileLocator ());
2010-07-16 08:12:58 +01:00
$loader2 -> load ( $tmp );
2010-03-18 07:48:03 +00:00
2010-05-06 12:25:53 +01:00
unlink ( $tmp );
2010-03-18 07:48:03 +00:00
2010-07-16 08:15:22 +01:00
$this -> assertEquals ( $container2 -> getAliases (), $container1 -> getAliases (), 'loading a dump from a previously loaded container returns the same container' );
$this -> assertEquals ( $container2 -> getDefinitions (), $container1 -> getDefinitions (), 'loading a dump from a previously loaded container returns the same container' );
$this -> assertEquals ( $container2 -> getParameterBag () -> all (), $container1 -> getParameterBag () -> all (), '->getParameterBag() returns the same value for both containers' );
2010-05-06 12:25:53 +01:00
$this -> assertEquals ( serialize ( $container2 ), serialize ( $container1 ), 'loading a dump from a previously loaded container returns the same container' );
2010-03-18 07:48:03 +00:00
2010-05-06 12:25:53 +01:00
$services1 = array ();
2010-05-07 15:09:11 +01:00
foreach ( $container1 as $id => $service ) {
2010-05-06 12:25:53 +01:00
$services1 [ $id ] = serialize ( $service );
}
$services2 = array ();
2010-05-07 15:09:11 +01:00
foreach ( $container2 as $id => $service ) {
2010-05-06 12:25:53 +01:00
$services2 [ $id ] = serialize ( $service );
}
unset ( $services1 [ 'service_container' ], $services2 [ 'service_container' ]);
$this -> assertEquals ( $services2 , $services1 , 'Iterator on the containers returns the same services' );
2010-04-14 08:57:47 +01:00
}
2010-05-06 12:25:53 +01:00
public function crossCheckLoadersDumpers ()
2010-04-14 08:57:47 +01:00
{
2010-05-06 12:25:53 +01:00
return array (
array ( 'services1.xml' , 'xml' ),
array ( 'services2.xml' , 'xml' ),
array ( 'services6.xml' , 'xml' ),
array ( 'services8.xml' , 'xml' ),
array ( 'services9.xml' , 'xml' ),
array ( 'services1.yml' , 'yaml' ),
array ( 'services2.yml' , 'yaml' ),
array ( 'services6.yml' , 'yaml' ),
array ( 'services8.yml' , 'yaml' ),
array ( 'services9.yml' , 'yaml' ),
);
2010-04-14 08:57:47 +01:00
}
2010-03-18 07:48:03 +00:00
}