Skip to content

Commit

Permalink
Merge 730f1a4 into 0342c65
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-gribanov committed May 24, 2021
2 parents 0342c65 + 730f1a4 commit db334d7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"symfony/http-kernel": "~2.3|~3.0|~4.0|~5.0",
"symfony/dependency-injection": "~2.3|~3.0|~4.0|~5.0",
"symfony/expression-language": "~2.3|~3.0|~4.0|~5.0",
"doctrine/orm": "~2.4|~2.5|~2.6"
"doctrine/orm": "~2.4"
},
"require-dev": {
"phpunit/phpunit": "^4.8.36",
Expand Down
10 changes: 8 additions & 2 deletions src/Service/EventPuller.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

namespace GpsLab\Bundle\DomainEvent\Service;

use Doctrine\Common\Persistence\Proxy;
use Doctrine\Common\Persistence\Proxy as CommonProxy;
use Doctrine\Persistence\Proxy;
use Doctrine\ORM\UnitOfWork;
use GpsLab\Domain\Event\Aggregator\AggregateEvents;
use GpsLab\Domain\Event\Event;
Expand Down Expand Up @@ -46,10 +47,15 @@ public function pull(UnitOfWork $uow)
private function pullFromEntities(array $entities)
{
$events = [];

foreach ($entities as $entity) {
// ignore Doctrine not initialized proxy classes
// proxy class can't have a domain events
if ((!($entity instanceof Proxy) || $entity->__isInitialized()) && $entity instanceof AggregateEvents) {
if ((
(!$entity instanceof CommonProxy && !$entity instanceof Proxy) || $entity->__isInitialized()
) &&
$entity instanceof AggregateEvents
) {
$events = array_merge($events, $entity->pullEvents());
}
}
Expand Down
21 changes: 17 additions & 4 deletions tests/Service/EventPullerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

namespace GpsLab\Bundle\DomainEvent\Tests\Service;

use Doctrine\Common\Persistence\Proxy;
use Doctrine\Common\Persistence\Proxy as CommonProxy;
use Doctrine\Persistence\Proxy;
use Doctrine\ORM\UnitOfWork;
use GpsLab\Bundle\DomainEvent\Service\EventPuller;
use GpsLab\Domain\Event\Aggregator\AggregateEvents;
Expand Down Expand Up @@ -116,7 +117,7 @@ public function testPull(

$map = [
[
$this->getMockBuilder(Proxy::class)->getMock(),
$this->getProxyMock(),
$aggregator1,
],
[
Expand All @@ -125,7 +126,7 @@ public function testPull(
],
[
new \stdClass(),
$this->getMockBuilder(Proxy::class)->getMock(),
$this->getProxyMock(),
],
];
} else {
Expand Down Expand Up @@ -189,10 +190,22 @@ private function getEntitiesFroEvents(array $events)
;

return [
$this->getMockBuilder(Proxy::class)->getMock(),
$this->getProxyMock(),
new \stdClass(),
$aggregator1,
$aggregator2,
];
}

/**
* @return CommonProxy|Proxy|\PHPUnit_Framework_MockObject_MockObject
*/
private function getProxyMock()
{
if (class_exists(CommonProxy::class)) {
return $this->getMockBuilder(CommonProxy::class)->getMock();
}

return $this->getMockBuilder(Proxy::class)->getMock();
}
}

0 comments on commit db334d7

Please sign in to comment.