DoctrineOrmTestCase.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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\Bridge\Doctrine\Tests;
  11. use Doctrine\Common\Annotations\AnnotationReader;
  12. use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
  13. use Doctrine\ORM\EntityManager;
  14. abstract class DoctrineOrmTestCase extends \PHPUnit_Framework_TestCase
  15. {
  16. protected function setUp()
  17. {
  18. if (!class_exists('Doctrine\Common\Version')) {
  19. $this->markTestSkipped('Doctrine Common is not available.');
  20. }
  21. if (!class_exists('Doctrine\DBAL\Platforms\MySqlPlatform')) {
  22. $this->markTestSkipped('Doctrine DBAL is not available.');
  23. }
  24. if (!class_exists('Doctrine\ORM\EntityManager')) {
  25. $this->markTestSkipped('Doctrine ORM is not available.');
  26. }
  27. }
  28. /**
  29. * @return EntityManager
  30. */
  31. public static function createTestEntityManager($paths = array())
  32. {
  33. if (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers())) {
  34. self::markTestSkipped('This test requires SQLite support in your environment');
  35. }
  36. $config = new \Doctrine\ORM\Configuration();
  37. $config->setEntityNamespaces(array('SymfonyTestsDoctrine' => 'Symfony\Bridge\Doctrine\Tests\Fixtures'));
  38. $config->setAutoGenerateProxyClasses(true);
  39. $config->setProxyDir(\sys_get_temp_dir());
  40. $config->setProxyNamespace('SymfonyTests\Doctrine');
  41. $config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader()));
  42. $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
  43. $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
  44. $params = array(
  45. 'driver' => 'pdo_sqlite',
  46. 'memory' => true,
  47. );
  48. return EntityManager::create($params, $config);
  49. }
  50. }