|
11 | 11 |
|
12 | 12 | namespace Symfony\Bridge\Doctrine\Tests;
|
13 | 13 |
|
14 |
| -use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper as TestDoctrineTestHelper; |
| 14 | +use Doctrine\Common\Annotations\AnnotationReader; |
| 15 | +use Doctrine\ORM\Configuration; |
| 16 | +use Doctrine\ORM\EntityManager; |
| 17 | +use Doctrine\ORM\Mapping\Driver\AnnotationDriver; |
| 18 | +use Doctrine\ORM\Mapping\Driver\XmlDriver; |
| 19 | +use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; |
| 20 | +use Doctrine\Persistence\Mapping\Driver\SymfonyFileLocator; |
| 21 | +use PHPUnit\Framework\TestCase; |
15 | 22 |
|
16 | 23 | /**
|
17 | 24 | * Provides utility functions needed in tests.
|
18 | 25 | *
|
19 | 26 | * @author Bernhard Schussek <bschussek@gmail.com>
|
20 | 27 | */
|
21 |
| -final class DoctrineTestHelper extends TestDoctrineTestHelper |
| 28 | +final class DoctrineTestHelper |
22 | 29 | {
|
| 30 | + /** |
| 31 | + * Returns an entity manager for testing. |
| 32 | + */ |
| 33 | + public static function createTestEntityManager(Configuration $config = null): EntityManager |
| 34 | + { |
| 35 | + if (!\extension_loaded('pdo_sqlite')) { |
| 36 | + TestCase::markTestSkipped('Extension pdo_sqlite is required.'); |
| 37 | + } |
| 38 | + |
| 39 | + $params = [ |
| 40 | + 'driver' => 'pdo_sqlite', |
| 41 | + 'memory' => true, |
| 42 | + ]; |
| 43 | + |
| 44 | + return EntityManager::create($params, $config ?? self::createTestConfiguration()); |
| 45 | + } |
| 46 | + |
| 47 | + public static function createTestConfiguration(): Configuration |
| 48 | + { |
| 49 | + $config = new Configuration(); |
| 50 | + $config->setEntityNamespaces(['SymfonyTestsDoctrine' => 'Symfony\Bridge\Doctrine\Tests\Fixtures']); |
| 51 | + $config->setAutoGenerateProxyClasses(true); |
| 52 | + $config->setProxyDir(sys_get_temp_dir()); |
| 53 | + $config->setProxyNamespace('SymfonyTests\Doctrine'); |
| 54 | + $config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader())); |
| 55 | + |
| 56 | + return $config; |
| 57 | + } |
| 58 | + |
| 59 | + public static function createTestConfigurationWithXmlLoader(): Configuration |
| 60 | + { |
| 61 | + $config = self::createTestConfiguration(); |
| 62 | + |
| 63 | + $driverChain = new MappingDriverChain(); |
| 64 | + $driverChain->addDriver( |
| 65 | + new XmlDriver( |
| 66 | + new SymfonyFileLocator( |
| 67 | + [__DIR__.'/../Tests/Resources/orm' => 'Symfony\\Bridge\\Doctrine\\Tests\\Fixtures'], '.orm.xml' |
| 68 | + ) |
| 69 | + ), |
| 70 | + 'Symfony\\Bridge\\Doctrine\\Tests\\Fixtures' |
| 71 | + ); |
| 72 | + |
| 73 | + $config->setMetadataDriverImpl($driverChain); |
| 74 | + |
| 75 | + return $config; |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * This class cannot be instantiated. |
| 80 | + */ |
| 81 | + private function __construct() |
| 82 | + { |
| 83 | + } |
23 | 84 | }
|
0 commit comments