-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit also comes with a dependencies upgrade: - PHP 7.4 & 8.0 are no more supported - Symfony 4.x is not supported anymore
- Loading branch information
Showing
11 changed files
with
170 additions
and
92 deletions.
There are no files selected for viewing
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
27 changes: 27 additions & 0 deletions
27
Tests/Model/Instantiator/PostLoadDispatcherInjectionListenerTest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Biig\Component\Domain\Tests\Model\Instantiator; | ||
|
||
use Biig\Component\Domain\Event\DomainEventDispatcher; | ||
use Biig\Component\Domain\Tests\fixtures\Entity\FakeModel; | ||
use Biig\Component\Domain\Tests\SetupDatabaseTrait; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class PostLoadDispatcherInjectionListenerTest extends TestCase | ||
{ | ||
use SetupDatabaseTrait; | ||
|
||
public function testItInjectDispatcherOnStandardEntity() | ||
{ | ||
$dispatcher = new DomainEventDispatcher(); | ||
$entityManager = $this->setupDatabase($dispatcher, 'testPostLoadDispatcherInjection'); | ||
$entity = $entityManager->getRepository(FakeModel::class)->find(1); | ||
|
||
$this->assertTrue($entity->hasDispatcher()); | ||
} | ||
|
||
public function testItLoadsDispatcherInProxyEntity() | ||
{ | ||
|
||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Biig\Component\Domain\Tests; | ||
|
||
use Biig\Component\Domain\Event\DomainEventDispatcher; | ||
use Biig\Component\Domain\Model\Instantiator\DoctrineConfig\PostLoadDispatcherInjectionListener; | ||
use Biig\Component\Domain\PostPersistListener\DoctrinePostPersistListener; | ||
use Doctrine\ORM\EntityManager; | ||
use Biig\Component\Domain\Model\Instantiator\DoctrineConfig\ClassMetadataFactory; | ||
use Doctrine\ORM\ORMSetup; | ||
|
||
trait SetupDatabaseTrait | ||
{ | ||
private $dbPath; | ||
|
||
private function setupDatabase(DomainEventDispatcher $dispatcher, string $name) | ||
{ | ||
$this->dbPath = \sys_get_temp_dir() . '/'.$name.'.' . \microtime() . '.sqlite'; | ||
copy(__DIR__ . '/fixtures/dbtest/initial_fake_model.db', $this->dbPath); | ||
|
||
$config = ORMSetup::createAttributeMetadataConfiguration(array(__DIR__ . '/../fixtures/Entity'), true); | ||
$config->setClassMetadataFactoryName(ClassMetadataFactory::class); | ||
$conn = [ | ||
'driver' => 'pdo_sqlite', | ||
'path' => $this->dbPath, | ||
]; | ||
|
||
$entityManager = EntityManager::create($conn, $config); | ||
$entityManager->getEventManager()->addEventSubscriber(new DoctrinePostPersistListener($dispatcher)); | ||
$entityManager->getEventManager()->addEventSubscriber(new PostLoadDispatcherInjectionListener($dispatcher)); | ||
|
||
$entityManager->getMetadataFactory()->setDispatcher($dispatcher); | ||
|
||
return $entityManager; | ||
} | ||
|
||
private function dropDatabase() | ||
{ | ||
if (!$this->dbPath) { | ||
return; | ||
} | ||
|
||
@unlink($this->dbPath); | ||
} | ||
} |
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
Binary file not shown.
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,25 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit bootstrap="Tests/bootstrap.php" colors="true"> | ||
|
||
<php> | ||
<server name="APP_ENV" value="test" force="true" /> | ||
<server name="KERNEL_CLASS" value="Biig\Component\Domain\Tests\TestKernel" force="true" /> | ||
</php> | ||
<testsuites> | ||
<testsuite name="BiiG Domain"> | ||
<directory suffix="Test.php">./Tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>./</directory> | ||
<exclude> | ||
<directory>./docs</directory> | ||
<directory>./Tests</directory> | ||
<directory>./vendor</directory> | ||
</exclude> | ||
</whitelist> | ||
</filter> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="Tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> | ||
<coverage> | ||
<include> | ||
<directory>./</directory> | ||
</include> | ||
<exclude> | ||
<directory>./docs</directory> | ||
<directory>./Tests</directory> | ||
<directory>./vendor</directory> | ||
</exclude> | ||
</coverage> | ||
<php> | ||
<server name="APP_ENV" value="test" force="true"/> | ||
<server name="KERNEL_CLASS" value="Biig\Component\Domain\Tests\TestKernel" force="true"/> | ||
</php> | ||
<testsuites> | ||
<testsuite name="BiiG Domain"> | ||
<directory suffix="Test.php">./Tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit bootstrap="Tests/bootstrap.php" colors="true"> | ||
|
||
<php> | ||
<server name="APP_ENV" value="test" force="true" /> | ||
<server name="KERNEL_CLASS" value="Biig\Component\Domain\Tests\TestKernel" force="true" /> | ||
</php> | ||
<testsuites> | ||
<testsuite name="BiiG Domain"> | ||
<directory suffix="Test.php">./Tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>./</directory> | ||
<exclude> | ||
<directory>./docs</directory> | ||
<directory>./Tests</directory> | ||
<directory>./vendor</directory> | ||
</exclude> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
33 changes: 33 additions & 0 deletions
33
src/Model/Instantiator/DoctrineConfig/PostLoadDispatcherInjectionListener.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Biig\Component\Domain\Model\Instantiator\DoctrineConfig; | ||
|
||
use Biig\Component\Domain\Event\DomainEventDispatcherInterface; | ||
use Biig\Component\Domain\Model\DomainModel; | ||
use Doctrine\Common\EventSubscriber; | ||
use Doctrine\ORM\Event\LifecycleEventArgs; | ||
|
||
class PostLoadDispatcherInjectionListener implements EventSubscriber | ||
{ | ||
public function __construct(private DomainEventDispatcherInterface $dispatcher) | ||
{ | ||
} | ||
|
||
public function getSubscribedEvents() | ||
{ | ||
return ['postLoad']; | ||
} | ||
|
||
/** | ||
* BC Layer: typing LifecycleEventArgs for previous Doctrine versions. | ||
* New versions use \Doctrine\ORM\Event\PostLoadEventArgs. | ||
*/ | ||
public function postLoad(LifecycleEventArgs $args) | ||
{ | ||
$entity = $args->getObject(); | ||
|
||
if ($entity instanceof DomainModel) { | ||
$entity->setDispatcher($this->dispatcher); | ||
} | ||
} | ||
} |
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