/** * @dataProvider provider * * @param string $supportedClass * @param array $inserts * @param array $updates * @param array $deletions * @param bool $isExpectedCache */ public function testOnFlush($supportedClass, array $inserts, array $updates, array $deletions, $isExpectedCache) { $treeProvider = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\Owner\\OwnerTreeProviderInterface')->disableOriginalConstructor()->getMock(); /** @var ContainerInterface|\PHPUnit_Framework_MockObject_MockObject $args */ $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); $container->expects($this->any())->method('get')->with('oro_security.ownership_tree_provider.chain')->willReturn($treeProvider); /** @var OnFlushEventArgs|\PHPUnit_Framework_MockObject_MockObject $args */ $args = $this->getMockBuilder('Doctrine\\ORM\\Event\\OnFlushEventArgs')->disableOriginalConstructor()->getMock(); $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $uow = $this->getMockBuilder('Doctrine\\ORM\\UnitOfWork')->disableOriginalConstructor()->getMock(); $args->expects($this->once())->method('getEntityManager')->will($this->returnValue($em)); $em->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($uow)); $uow->expects($this->once())->method('getScheduledEntityInsertions')->will($this->returnValue($inserts)); $uow->expects($this->any())->method('getScheduledEntityUpdates')->will($this->returnValue($updates)); $uow->expects($this->any())->method('getScheduledEntityDeletions')->will($this->returnValue($deletions)); if ($isExpectedCache) { $treeProvider->expects($this->once())->method('clear'); } else { $treeProvider->expects($this->never())->method('clear'); } $treeListener = new OwnerTreeListener(); $treeListener->setContainer($container); $treeListener->addSupportedClass($supportedClass); $treeListener->onFlush($args); }