diff --git a/src/Marello/Bundle/OrderBundle/EventListener/Doctrine/OrderWorkflowStartListener.php b/src/Marello/Bundle/OrderBundle/EventListener/Doctrine/OrderWorkflowStartListener.php index 426acc75f..a342324ed 100644 --- a/src/Marello/Bundle/OrderBundle/EventListener/Doctrine/OrderWorkflowStartListener.php +++ b/src/Marello/Bundle/OrderBundle/EventListener/Doctrine/OrderWorkflowStartListener.php @@ -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; @@ -21,6 +22,9 @@ class OrderWorkflowStartListener /** @var string $orderId*/ private $orderId; + /** @var DoctrineHelper $doctrineHelper */ + private $doctrineHelper; + /** * @param WorkflowManager $workflowManager */ @@ -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)) { @@ -95,4 +100,12 @@ protected function getDefaultWorkflowNames(): array WorkflowNameProviderInterface::ORDER_WORKFLOW_2 ]; } + + /** + * @param DoctrineHelper $doctrineHelper + */ + public function setDoctrineHelper(DoctrineHelper $doctrineHelper) + { + $this->doctrineHelper = $doctrineHelper; + } } diff --git a/src/Marello/Bundle/OrderBundle/Tests/Unit/EventListener/Doctrine/OrderWorkflowStartListenerTest.php b/src/Marello/Bundle/OrderBundle/Tests/Unit/EventListener/Doctrine/OrderWorkflowStartListenerTest.php index cb44680d7..02e69d030 100644 --- a/src/Marello/Bundle/OrderBundle/Tests/Unit/EventListener/Doctrine/OrderWorkflowStartListenerTest.php +++ b/src/Marello/Bundle/OrderBundle/Tests/Unit/EventListener/Doctrine/OrderWorkflowStartListenerTest.php @@ -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; @@ -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); } /** @@ -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); } @@ -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);