DoctrineTestHelper.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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\Test;
  11. use Doctrine\Common\Annotations\AnnotationReader;
  12. use Doctrine\ORM\EntityManager;
  13. use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
  14. use PHPUnit\Framework\TestCase;
  15. /**
  16. * Provides utility functions needed in tests.
  17. *
  18. * @author Bernhard Schussek <bschussek@gmail.com>
  19. */
  20. class DoctrineTestHelper
  21. {
  22. /**
  23. * Returns an entity manager for testing.
  24. *
  25. * @return EntityManager
  26. */
  27. public static function createTestEntityManager()
  28. {
  29. if (!\extension_loaded('pdo_sqlite')) {
  30. TestCase::markTestSkipped('Extension pdo_sqlite is required.');
  31. }
  32. $config = new \Doctrine\ORM\Configuration();
  33. $config->setEntityNamespaces(array('SymfonyTestsDoctrine' => 'Symfony\Bridge\Doctrine\Tests\Fixtures'));
  34. $config->setAutoGenerateProxyClasses(true);
  35. $config->setProxyDir(\sys_get_temp_dir());
  36. $config->setProxyNamespace('SymfonyTests\Doctrine');
  37. $config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader()));
  38. $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
  39. $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
  40. $params = array(
  41. 'driver' => 'pdo_sqlite',
  42. 'memory' => true,
  43. );
  44. return EntityManager::create($params, $config);
  45. }
  46. /**
  47. * This class cannot be instantiated.
  48. */
  49. private function __construct()
  50. {
  51. }
  52. }