DoctrineOrmTestCase.php 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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\Tests\Bridge\Doctrine;
  11. use Symfony\Bridge\Doctrine\Annotations\IndexedReader;
  12. use Doctrine\Common\Annotations\AnnotationReader;
  13. use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
  14. use Doctrine\ORM\EntityManager;
  15. abstract class DoctrineOrmTestCase extends \PHPUnit_Framework_TestCase
  16. {
  17. protected function setUp()
  18. {
  19. if (!class_exists('Doctrine\\Common\\Version')) {
  20. $this->markTestSkipped('Doctrine is not available.');
  21. }
  22. }
  23. /**
  24. * @return EntityManager
  25. */
  26. static public function createTestEntityManager($paths = array())
  27. {
  28. if (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers())) {
  29. self::markTestSkipped('This test requires SQLite support in your environment');
  30. }
  31. $config = new \Doctrine\ORM\Configuration();
  32. $config->setAutoGenerateProxyClasses(true);
  33. $config->setProxyDir(\sys_get_temp_dir());
  34. $config->setProxyNamespace('SymfonyTests\Doctrine');
  35. $config->setMetadataDriverImpl(new AnnotationDriver(new IndexedReader(new AnnotationReader())));
  36. $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
  37. $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
  38. $params = array(
  39. 'driver' => 'pdo_sqlite',
  40. 'memory' => true,
  41. );
  42. return EntityManager::create($params, $config);
  43. }
  44. }