Skip to content

Commit

Permalink
- updated OrderWorkflowStart listener to use the doctrine helper from…
Browse files Browse the repository at this point in the history
… Oro to get the correct entity manager for the class instead of the event's entity manager
  • Loading branch information
24198 committed Jun 5, 2020
1 parent df0ac89 commit a2215e6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Doctrine\ORM\Event\PostFlushEventArgs;

use Oro\Bundle\WorkflowBundle\Model\Workflow;
use Oro\Bundle\EntityBundle\ORM\DoctrineHelper;
use Oro\Bundle\WorkflowBundle\Model\WorkflowManager;

use Marello\Bundle\OrderBundle\Entity\Order;
Expand All @@ -21,6 +22,9 @@ class OrderWorkflowStartListener
/** @var string $orderId*/
private $orderId;

/** @var DoctrineHelper $doctrineHelper */
private $doctrineHelper;

/**
* @param WorkflowManager $workflowManager
*/
Expand Down Expand Up @@ -49,7 +53,8 @@ public function postFlush(PostFlushEventArgs $args): void
if ($this->orderId) {
$entityManager = $args->getEntityManager();
/** @var Order $entity */
$entity = $entityManager
$entity = $this->doctrineHelper
->getEntityManagerForClass(Order::class)
->getRepository(Order::class)
->find($this->orderId);
if ($entity && $workflow = $this->getApplicableWorkflow($entity)) {
Expand Down Expand Up @@ -95,4 +100,12 @@ protected function getDefaultWorkflowNames(): array
WorkflowNameProviderInterface::ORDER_WORKFLOW_2
];
}

/**
* @param DoctrineHelper $doctrineHelper
*/
public function setDoctrineHelper(DoctrineHelper $doctrineHelper)
{
$this->doctrineHelper = $doctrineHelper;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PHPUnit\Framework\TestCase;

use Oro\Bundle\WorkflowBundle\Model\Workflow;
use Oro\Bundle\EntityBundle\ORM\DoctrineHelper;
use Oro\Bundle\WorkflowBundle\Model\WorkflowManager;

use Marello\Bundle\OrderBundle\Entity\Order;
Expand All @@ -27,13 +28,17 @@ class OrderWorkflowStartListenerTest extends TestCase
/** @var OrderWorkflowStartListener $orderWorkflowStartListener */
private $orderWorkflowStartListener;

/** @var DoctrineHelper|\PHPUnit_Framework_MockObject_MockObject $doctrineHelperMock */
private $doctrineHelperMock;
/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->workflowManagerMock = $this->createMock(WorkflowManager::class);
$this->doctrineHelperMock = $this->createMock(DoctrineHelper::class);
$this->orderWorkflowStartListener = new OrderWorkflowStartListener($this->workflowManagerMock);
$this->orderWorkflowStartListener->setDoctrineHelper($this->doctrineHelperMock);
}

/**
Expand All @@ -45,8 +50,8 @@ public function testEntityIsNotEligibleToProcess()
$this->runFirstSequenceOfWorkflowListenerTest($entity, static::never());
/** @var PostFlushEventArgs|\PHPUnit\Framework\MockObject\MockObject $eventPostFlushArgs */
$eventPostFlushArgs = $this->createMock(PostFlushEventArgs::class);
$eventPostFlushArgs->expects(static::never())
->method('getEntityManager');
$this->doctrineHelperMock->expects(static::never())
->method('getEntityManagerForClass');

$this->orderWorkflowStartListener->postFlush($eventPostFlushArgs);
}
Expand Down Expand Up @@ -181,8 +186,8 @@ protected function createPostFlushEventArgsMock($entity)
{
$eventPostFlushArgs = $this->createMock(PostFlushEventArgs::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$eventPostFlushArgs->expects(static::once())
->method('getEntityManager')
$this->doctrineHelperMock->expects(static::once())
->method('getEntityManagerForClass')
->willReturn($entityManager);

$entityRepository = $this->createMock(EntityRepository::class);
Expand Down

0 comments on commit a2215e6

Please sign in to comment.