TestCase.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.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\Bundle\DoctrineBundle\Tests;
  11. use Doctrine\ORM\EntityManager;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
  14. use Symfony\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension;
  15. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  16. class TestCase extends \PHPUnit_Framework_TestCase
  17. {
  18. protected function setUp()
  19. {
  20. if (!class_exists('Doctrine\\Common\\Version')) {
  21. $this->markTestSkipped('Doctrine is not available.');
  22. }
  23. }
  24. /**
  25. * @return EntityManager
  26. */
  27. protected function createTestEntityManager($paths = array())
  28. {
  29. $config = new \Doctrine\ORM\Configuration();
  30. $config->setAutoGenerateProxyClasses(true);
  31. $config->setProxyDir(\sys_get_temp_dir());
  32. $config->setProxyNamespace('SymfonyTests\Doctrine');
  33. $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver($paths));
  34. $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
  35. $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
  36. $params = array(
  37. 'driver' => 'pdo_sqlite',
  38. 'memory' => true,
  39. );
  40. return EntityManager::create($params, $config);
  41. }
  42. public function createYamlBundleTestContainer()
  43. {
  44. $container = new ContainerBuilder(new ParameterBag(array(
  45. 'kernel.bundles' => array('YamlBundle' => 'DoctrineBundle\Tests\DependencyInjection\Fixtures\Bundles\YamlBundle\YamlBundle'),
  46. 'kernel.cache_dir' => sys_get_temp_dir(),
  47. 'kernel.root_dir' => __DIR__ . "/../../../../" // src dir
  48. )));
  49. $loader = new DoctrineExtension();
  50. $container->registerExtension($loader);
  51. $loader->dbalLoad(array(array(
  52. 'connections' => array(
  53. 'default' => array(
  54. 'driver' => 'pdo_mysql',
  55. 'charset' => 'UTF-8',
  56. 'platform-service' => 'my.platform',
  57. )
  58. ),
  59. 'types' => array(
  60. 'test' => 'Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestType',
  61. ),
  62. )), $container);
  63. $loader->ormLoad(array(
  64. array(
  65. 'mappings' => array('YamlBundle' => array(
  66. 'type' => 'yml',
  67. 'dir' => __DIR__ . "/DependencyInjection/Fixtures/Bundles/YamlBundle/Resources/config/doctrine/metadata/orm",
  68. 'prefix' => 'DoctrineBundle\Tests\DependencyInjection\Fixtures\Bundles\YamlBundle',
  69. )))), $container);
  70. $container->setDefinition('my.platform', new \Symfony\Component\DependencyInjection\Definition('Doctrine\DBAL\Platforms\MySqlPlatform'));
  71. return $container;
  72. }
  73. }