TestCase.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /*
  3. * This file is part of the Doctrine Bundle
  4. *
  5. * The code was originally distributed inside the Symfony framework.
  6. *
  7. * (c) Fabien Potencier <fabien@symfony.com>
  8. * (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
  9. *
  10. * For the full copyright and license information, please view the LICENSE
  11. * file that was distributed with this source code.
  12. */
  13. namespace Doctrine\Bundle\DoctrineBundle\Tests;
  14. use Doctrine\Common\Annotations\AnnotationReader;
  15. use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension;
  16. use Symfony\Component\DependencyInjection\ContainerBuilder;
  17. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
  18. use Symfony\Component\DependencyInjection\Compiler\ResolveDefinitionTemplatesPass;
  19. use Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterEventListenersAndSubscribersPass;
  20. class TestCase extends \PHPUnit_Framework_TestCase
  21. {
  22. protected function setUp()
  23. {
  24. if (!class_exists('Doctrine\\Common\\Version')) {
  25. $this->markTestSkipped('Doctrine is not available.');
  26. }
  27. }
  28. public function createYamlBundleTestContainer()
  29. {
  30. $container = new ContainerBuilder(new ParameterBag(array(
  31. 'kernel.debug' => false,
  32. 'kernel.bundles' => array('YamlBundle' => 'Fixtures\Bundles\YamlBundle\YamlBundle'),
  33. 'kernel.cache_dir' => sys_get_temp_dir(),
  34. 'kernel.environment' => 'test',
  35. 'kernel.root_dir' => __DIR__.'/../../../../' // src dir
  36. )));
  37. $container->set('annotation_reader', new AnnotationReader());
  38. $loader = new DoctrineExtension();
  39. $container->registerExtension($loader);
  40. $loader->load(array(array(
  41. 'dbal' => array(
  42. 'connections' => array(
  43. 'default' => array(
  44. 'driver' => 'pdo_mysql',
  45. 'charset' => 'UTF8',
  46. 'platform-service' => 'my.platform',
  47. )
  48. ),
  49. 'default_connection' => 'default',
  50. 'types' => array(
  51. 'test' => 'Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestType',
  52. ),
  53. ), 'orm' => array(
  54. 'default_entity_manager' => 'default',
  55. 'entity_managers' => array (
  56. 'default' => array(
  57. 'mappings' => array('YamlBundle' => array(
  58. 'type' => 'yml',
  59. 'dir' => __DIR__.'/DependencyInjection/Fixtures/Bundles/YamlBundle/Resources/config/doctrine',
  60. 'prefix' => 'Fixtures\Bundles\YamlBundle\Entity',
  61. )
  62. ))),
  63. 'resolve_target_entities' => array(
  64. 'Symfony\Component\Security\Core\User\UserInterface' => 'stdClass',
  65. ),
  66. )
  67. )), $container);
  68. $container->setDefinition('my.platform', new \Symfony\Component\DependencyInjection\Definition('Doctrine\DBAL\Platforms\MySqlPlatform'));
  69. $container->getCompilerPassConfig()->setOptimizationPasses(array(new ResolveDefinitionTemplatesPass()));
  70. $container->getCompilerPassConfig()->setRemovingPasses(array());
  71. $container->compile();
  72. return $container;
  73. }
  74. }