-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Robert-Jan Bijl
committed
Nov 16, 2023
1 parent
d1b5c80
commit f5e4389
Showing
3 changed files
with
100 additions
and
96 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
tests/Doctrine/Translatable/EventListener/TranslatableListenerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/Doctrine/Translatable/EventListener/TranslatableListenerValidationTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,98 @@ | ||
<?php | ||
|
||
namespace Prezent\Tests\Tool; | ||
|
||
use Doctrine\Common\Annotations\AnnotationReader; | ||
use Doctrine\Common\Annotations\AnnotationRegistry; | ||
use Doctrine\Common\Annotations\PsrCachedReader; | ||
use Doctrine\Common\EventManager; | ||
use Doctrine\ORM\EntityManager; | ||
use Doctrine\ORM\Mapping\Driver\AnnotationDriver as ORMAnnotationDriver; | ||
use Doctrine\ORM\Tools\SchemaTool; | ||
use Doctrine\ORM\Tools\Setup; | ||
use Metadata\MetadataFactory; | ||
use PHPUnit\Framework\TestCase; | ||
use Prezent\Doctrine\Translatable\EventListener\TranslatableListener; | ||
use Prezent\Doctrine\Translatable\Mapping\Driver\AnnotationDriver; | ||
use Symfony\Component\Cache\Adapter\ArrayAdapter; | ||
|
||
abstract class ORMTestCase extends TestCase | ||
{ | ||
private $em; | ||
private $evm; | ||
private $listener; | ||
|
||
public function getEntityManager() | ||
{ | ||
if (!$this->em) { | ||
$this->em = $this->createEntityManager(); | ||
} | ||
|
||
return $this->em; | ||
} | ||
|
||
public function createEntityManager() | ||
{ | ||
$conn = array( | ||
'driver' => 'pdo_sqlite', | ||
'memory' => true, | ||
); | ||
|
||
AnnotationRegistry::registerFile(realpath(__DIR__ . '/../../vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php')); | ||
|
||
$reader = new AnnotationReader(); | ||
$reader = new PsrCachedReader($reader, new ArrayAdapter()); | ||
|
||
$config = Setup::createConfiguration(true); | ||
$config->setMetadataDriverImpl(new ORMAnnotationDriver($reader, array(__DIR__ . '/../Fixture'))); | ||
|
||
$em = EntityManager::create($conn, $config, $this->getEventManager()); | ||
|
||
$schemaTool = new SchemaTool($em); | ||
$schemaTool->createSchema(array_map(function ($class) use ($em) { | ||
return $em->getClassMetadata($class); | ||
}, $this->getFixtureClasses())); | ||
|
||
return $em; | ||
} | ||
|
||
public function getEventManager() | ||
{ | ||
if (!$this->evm) { | ||
$this->evm = $this->createEventManager(); | ||
} | ||
|
||
return $this->evm; | ||
} | ||
|
||
public function createEventManager() | ||
{ | ||
$evm = new EventManager(); | ||
$evm->addEventSubscriber($this->getTranslatableListener()); | ||
|
||
return $evm; | ||
} | ||
|
||
public function getTranslatableListener() | ||
{ | ||
if (!$this->listener) { | ||
$this->listener = $this->createTranslatableListener(); | ||
} | ||
|
||
return $this->listener; | ||
} | ||
|
||
public function createTranslatableListener() | ||
{ | ||
return new TranslatableListener(new MetadataFactory(new AnnotationDriver(new AnnotationReader()))); | ||
} | ||
|
||
public function getFixtureClasses() | ||
{ | ||
return array(); | ||
} | ||
} | ||
<?php | ||
|
||
namespace Prezent\Tests\Tool; | ||
|
||
use Doctrine\Common\Annotations\AnnotationReader; | ||
use Doctrine\Common\Annotations\AnnotationRegistry; | ||
use Doctrine\Common\Annotations\PsrCachedReader; | ||
use Doctrine\Common\EventManager; | ||
use Doctrine\ORM\EntityManager; | ||
use Doctrine\ORM\Mapping\Driver\AnnotationDriver as ORMAnnotationDriver; | ||
use Doctrine\ORM\Tools\SchemaTool; | ||
use Doctrine\ORM\Tools\Setup; | ||
use Metadata\MetadataFactory; | ||
use PHPUnit\Framework\TestCase; | ||
use Prezent\Doctrine\Translatable\EventListener\TranslatableListener; | ||
use Prezent\Doctrine\Translatable\Mapping\Driver\AnnotationDriver; | ||
use Symfony\Component\Cache\Adapter\ArrayAdapter; | ||
|
||
abstract class ORMTestCase extends TestCase | ||
{ | ||
private $em; | ||
|
||
private $evm; | ||
|
||
private $listener; | ||
|
||
public function getEntityManager() | ||
{ | ||
if (!$this->em) { | ||
$this->em = $this->createEntityManager(); | ||
} | ||
|
||
return $this->em; | ||
} | ||
|
||
public function createEntityManager() | ||
{ | ||
$conn = array( | ||
'driver' => 'pdo_sqlite', | ||
'memory' => true, | ||
); | ||
|
||
AnnotationRegistry::registerFile( | ||
realpath(__DIR__ . '/../../vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php') | ||
); | ||
|
||
$reader = new AnnotationReader(); | ||
$reader = new PsrCachedReader($reader, new ArrayAdapter()); | ||
|
||
$config = Setup::createConfiguration(true); | ||
$config->setMetadataDriverImpl(new ORMAnnotationDriver($reader, array(__DIR__ . '/../Fixture'))); | ||
|
||
$em = EntityManager::create($conn, $config, $this->getEventManager()); | ||
|
||
$schemaTool = new SchemaTool($em); | ||
$schemaTool->createSchema(array_map(function ($class) use ($em) { | ||
return $em->getClassMetadata($class); | ||
}, $this->getFixtureClasses())); | ||
|
||
return $em; | ||
} | ||
|
||
public function getEventManager() | ||
{ | ||
if (!$this->evm) { | ||
$this->evm = $this->createEventManager(); | ||
} | ||
|
||
return $this->evm; | ||
} | ||
|
||
public function createEventManager() | ||
{ | ||
$evm = new EventManager(); | ||
$evm->addEventSubscriber($this->getTranslatableListener()); | ||
|
||
return $evm; | ||
} | ||
|
||
public function getTranslatableListener() | ||
{ | ||
if (!$this->listener) { | ||
$this->listener = $this->createTranslatableListener(); | ||
} | ||
|
||
return $this->listener; | ||
} | ||
|
||
public function createTranslatableListener() | ||
{ | ||
return new TranslatableListener(new MetadataFactory(new AnnotationDriver(new AnnotationReader()))); | ||
} | ||
|
||
public function getFixtureClasses() | ||
{ | ||
return array(); | ||
} | ||
} |