/** * @param array $data * @param bool $expectsDisable * @param bool $expectedFlush * @param bool $exception * * @dataProvider eventDataProvider */ public function testOnProcessHandleAfter(array $data, $expectsDisable, $expectedFlush, $exception = false) { $trigger = new ProcessTrigger(); $data = new ProcessData($data); $event = new ProcessHandleEvent($trigger, $data); $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $this->doctrineHelper->expects($this->any())->method('getEntityManager')->will($this->returnValue($em)); if ($expectsDisable) { $this->processListener->expects($this->at(0))->method('setEnabled')->with(false); $this->processListener->expects($this->at(1))->method('setEnabled')->with(true); } if ($expectedFlush) { $em->expects($this->once())->method('flush')->with($this->isType('object')); } else { if ($exception) { $em->expects($this->once())->method('flush')->will($this->throwException(new \Exception())); $this->setExpectedException('\\Exception'); } else { $em->expects($this->never())->method('flush'); } } $this->listener->onProcessHandleAfter($event); }