*/ class DbTest extends PHPUnit_Framework_TestCase { protected $adapter; protected $moduleOptions; protected $mapper; /** * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. */ protected function setUp() { $this->moduleOptions = $moduleOptions = new ModuleOptions(array( 'cas' => array( 'connection' => array( 'default' => array( 'params' => array( 'hostname' => 'cas.unicaen.fr', 'port' => 443, 'version' => "2.0", 'uri' => "", 'debug' => false, ), ), ), ), )); $this->mapper = $mapper = $this->getMock('ZfcUser\Mapper\User', array('findByUsername', 'findByEmail')); $serviceManager = $this->getMock('Zend\ServiceManager\ServiceManager', array('get')); $serviceManager->expects($this->any()) ->method('get') ->will($this->returnCallback(function($serviceName) use ($moduleOptions, $mapper) { if ('zfcuser_module_options' === $serviceName) { return new \ZfcUser\Options\ModuleOptions(); } if ('unicaen-auth_module_options' === $serviceName) { return $moduleOptions; } if ('zfcuser_user_mapper' === $serviceName) { return $mapper; } return null; })); $this->adapter = new Db(); $this->adapter->setServiceManager($serviceManager); } public function getException() { return array( array(new PDOException()), array(new ServiceNotFoundException()), ); } /** * @dataProvider getException */ public function testAuthenticateReturnsFalseIfExceptionThrown($exception) { $this->mapper->expects($this->once()) ->method($this->logicalOr('findByUsername', 'findByEmail')) ->will($this->throwException($exception)); $request = new Request(); $request->setPost(new Parameters(array('identity' => 'bob', 'credential' => "xxxxx"))); $event = new AdapterChainEvent(); $event->setRequest($request); $result = $this->adapter->authenticate($event); $this->assertFalse($result); } public function testAuthenticateReturnsParentMethodResult() { $request = new Request(); $request->setPost(new Parameters(array('identity' => 'bob', 'credential' => "xxxxx"))); $event = new AdapterChainEvent(); $event->setRequest($request); $result = $this->adapter->authenticate($event); $this->assertFalse($result); } }