/** * @param string $entityName * @param bool $isEntity * @param bool $isException * @param bool $isAlreadyConfigured * @param bool $isActionEnabled * @param array|null $expected * * @dataProvider onBuildBeforeProvider */ public function testOnBuildBefore($entityName, $isEntity, $isException, $isAlreadyConfigured, $isActionEnabled, $expected = null) { $datagrid = $this->getDatagrid($entityName, $isAlreadyConfigured); // prepare mocks if ($isException) { $this->classResolverMock->expects($this->once())->method('isEntity')->with($entityName)->will($this->throwException(new \ReflectionException("Not valid class"))); } else { $this->classResolverMock->expects($this->once())->method('isEntity')->with($entityName)->will($this->returnValue($isEntity)); if ($isEntity && !$isAlreadyConfigured && $isActionEnabled) { $this->doctrineHelperMock->expects($this->once())->method('getSingleEntityIdentifierFieldName')->will($this->returnValue('id')); } $isEmptyAndEnabled = !$isAlreadyConfigured && $isEntity; $this->handlerMock->expects($isEmptyAndEnabled ? $this->once() : $this->never())->method('isMassActionEnabled')->with($entityName)->will($this->returnValue($isActionEnabled)); } $event = new BuildBefore($datagrid, $datagrid->getConfig()); $this->listener->onBuildBefore($event); $this->assertEquals($expected, $event->getConfig()->offsetGetByPath(sprintf(GridListener::ACTION_CONFIGURATION_KEY, MassUpdateActionHandler::ACTION_NAME)), 'Failed asserting that mass action config added by listener'); }