*/ class DbServiceFactoryTest extends BaseServiceFactoryTest { protected $factoryClass = 'UnicaenAuth\Provider\Role\DbServiceFactory'; protected $serviceClass = 'UnicaenAuth\Provider\Role\Db'; public function provideInvalidOptions() { return array( 'a' => array(array()), 'b' => array(array('role_providers')), 'c' => array(array('role_providers' => array())), 'd' => array(array('role_providers' => array('UnicaenAuth\Provider\Role\Db' => array()))), 'e' => array(array('role_providers' => array('UnicaenAuth\Provider\Role\Db' => array('role_entity_class' => null)))), 'f' => array(array('role_providers' => array('UnicaenAuth\Provider\Role\Db' => array('role_entity_class' => 'A', 'object_manager' => null)))), ); } /** * @dataProvider provideInvalidOptions * @expectedException \BjyAuthorize\Exception\InvalidArgumentException */ public function testCannotCreateServiceWithInvalidOptions($options) { $this->serviceLocator->expects($this->once()) ->method('get') ->with('BjyAuthorize\Config') ->will($this->returnValue($options)); $this->factory->createService($this->serviceLocator); } public function testCanCreateService() { $options = array( 'role_providers' => array( 'UnicaenAuth\Provider\Role\Db' => array( 'role_entity_class' => 'Entity', 'object_manager' => 'orm_default', ) ) ); $objectManager = $this->getMockForAbstractClass('Doctrine\Common\Persistence\ObjectManager', array('getRepository')); $objectManager->expects($this->once()) ->method('getRepository') ->will($this->returnValue($this->getMock('Doctrine\Common\Persistence\ObjectRepository', array()))); $map = array( array('BjyAuthorize\Config', $options), array('orm_default', $objectManager), ); $this->serviceLocator->expects($this->exactly(2)) ->method('get') ->will($this->returnValueMap($map)); $service = $this->factory->createService($this->serviceLocator); $this->assertInstanceOf('UnicaenAuth\Provider\Role\Db', $service); } }