vendor/symfony/src/Symfony/Bundle/DoctrineBundle/Tests/TestCase.php
changeset 0 7f95f8617b0b
equal deleted inserted replaced
-1:000000000000 0:7f95f8617b0b
       
     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\Bundle\DoctrineBundle\Tests;
       
    13 
       
    14 use Doctrine\Common\Annotations\AnnotationReader;
       
    15 use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
       
    16 use Doctrine\ORM\EntityManager;
       
    17 use Symfony\Component\DependencyInjection\ContainerBuilder;
       
    18 use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
       
    19 use Symfony\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension;
       
    20 use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
       
    21 use Symfony\Component\DependencyInjection\Compiler\ResolveDefinitionTemplatesPass;
       
    22 
       
    23 class TestCase extends \PHPUnit_Framework_TestCase
       
    24 {
       
    25     protected function setUp()
       
    26     {
       
    27         if (!class_exists('Doctrine\\Common\\Version')) {
       
    28             $this->markTestSkipped('Doctrine is not available.');
       
    29         }
       
    30     }
       
    31 
       
    32     public function createYamlBundleTestContainer()
       
    33     {
       
    34         $container = new ContainerBuilder(new ParameterBag(array(
       
    35             'kernel.debug'       => false,
       
    36             'kernel.bundles'     => array('YamlBundle' => 'Fixtures\Bundles\YamlBundle\YamlBundle'),
       
    37             'kernel.cache_dir'   => sys_get_temp_dir(),
       
    38             'kernel.environment' => 'test',
       
    39             'kernel.root_dir'    => __DIR__.'/../../../../' // src dir
       
    40         )));
       
    41         $container->set('annotation_reader', new AnnotationReader());
       
    42         $loader = new DoctrineExtension();
       
    43         $container->registerExtension($loader);
       
    44         $loader->load(array(array(
       
    45             'dbal' => array(
       
    46                 'connections' => array(
       
    47                     'default' => array(
       
    48                         'driver' => 'pdo_mysql',
       
    49                         'charset' => 'UTF8',
       
    50                         'platform-service' => 'my.platform',
       
    51                     )
       
    52                 ),
       
    53                 'default_connection' => 'default',
       
    54                 'types' => array(
       
    55                     'test' => 'Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestType',
       
    56                 ),
       
    57             ), 'orm' => array(
       
    58                 'default_entity_manager' => 'default',
       
    59                 'entity_managers' => array (
       
    60                     'default' => array(
       
    61                     'mappings' => array('YamlBundle' => array(
       
    62                         'type' => 'yml',
       
    63                         'dir' => __DIR__.'/DependencyInjection/Fixtures/Bundles/YamlBundle/Resources/config/doctrine',
       
    64                         'prefix' => 'Fixtures\Bundles\YamlBundle\Entity',
       
    65                     )
       
    66                 )
       
    67             )))
       
    68         )), $container);
       
    69 
       
    70         $container->setDefinition('my.platform', new \Symfony\Component\DependencyInjection\Definition('Doctrine\DBAL\Platforms\MySqlPlatform'));
       
    71 
       
    72         $container->getCompilerPassConfig()->setOptimizationPasses(array(new ResolveDefinitionTemplatesPass()));
       
    73         $container->getCompilerPassConfig()->setRemovingPasses(array());
       
    74         $container->compile();
       
    75 
       
    76         return $container;
       
    77     }
       
    78 }