db = $db; $this->storage = $this->getMock('Zend\Authentication\Storage\Session'); $this->mapper = $this->getMock('ZfcUser\Mapper\User'); } /** * @covers ZfcUser\Authentication\Storage\Db::isEmpty */ public function testIsEmpty() { $this->storage->expects($this->once()) ->method('isEmpty') ->will($this->returnValue(true)); $this->db->setStorage($this->storage); $this->assertTrue($this->db->isEmpty()); } /** * @covers ZfcUser\Authentication\Storage\Db::read */ public function testReadWithResolvedEntitySet() { $reflectionClass = new \ReflectionClass('ZfcUser\Authentication\Storage\Db'); $reflectionProperty = $reflectionClass->getProperty('resolvedIdentity'); $reflectionProperty->setAccessible(true); $reflectionProperty->setValue($this->db, 'zfcUser'); $this->assertSame('zfcUser', $this->db->read()); } /** * @covers ZfcUser\Authentication\Storage\Db::read */ public function testReadWithoutResolvedEntitySetIdentityIntUserFound() { $this->storage->expects($this->once()) ->method('read') ->will($this->returnValue(1)); $this->db->setStorage($this->storage); $user = $this->getMock('ZfcUser\Entity\User'); $user->setUsername('zfcUser'); $this->mapper->expects($this->once()) ->method('findById') ->with(1) ->will($this->returnValue($user)); $this->db->setMapper($this->mapper); $result = $this->db->read(); $this->assertSame($user, $result); } /** * @covers ZfcUser\Authentication\Storage\Db::read */ public function testReadWithoutResolvedEntitySetIdentityIntUserNotFound() { $this->storage->expects($this->once()) ->method('read') ->will($this->returnValue(1)); $this->db->setStorage($this->storage); $this->mapper->expects($this->once()) ->method('findById') ->with(1) ->will($this->returnValue(false)); $this->db->setMapper($this->mapper); $result = $this->db->read(); $this->assertNull($result); } /** * @covers ZfcUser\Authentication\Storage\Db::read */ public function testReadWithoutResolvedEntitySetIdentityObject() { $user = $this->getMock('ZfcUser\Entity\User'); $user->setUsername('zfcUser'); $this->storage->expects($this->once()) ->method('read') ->will($this->returnValue($user)); $this->db->setStorage($this->storage); $result = $this->db->read(); $this->assertSame($user, $result); } /** * @covers ZfcUser\Authentication\Storage\Db::write */ public function testWrite() { $reflectionClass = new \ReflectionClass('ZfcUser\Authentication\Storage\Db'); $reflectionProperty = $reflectionClass->getProperty('resolvedIdentity'); $reflectionProperty->setAccessible(true); $this->storage->expects($this->once()) ->method('write') ->with('zfcUser'); $this->db->setStorage($this->storage); $this->db->write('zfcUser'); $this->assertNull($reflectionProperty->getValue($this->db)); } /** * @covers ZfcUser\Authentication\Storage\Db::clear */ public function testClear() { $reflectionClass = new \ReflectionClass('ZfcUser\Authentication\Storage\Db'); $reflectionProperty = $reflectionClass->getProperty('resolvedIdentity'); $reflectionProperty->setAccessible(true); $this->storage->expects($this->once()) ->method('clear'); $this->db->setStorage($this->storage); $this->db->clear(); $this->assertNull($reflectionProperty->getValue($this->db)); } /** * @covers ZfcUser\Authentication\Storage\Db::getMapper */ public function testGetMapperWithNoMapperSet() { $sm = $this->getMock('Zend\ServiceManager\ServiceManager'); $sm->expects($this->once()) ->method('get') ->with('zfcuser_user_mapper') ->will($this->returnValue($this->mapper)); $this->db->setServiceManager($sm); $this->assertInstanceOf('ZfcUser\Mapper\UserInterface', $this->db->getMapper()); } /** * @covers ZfcUser\Authentication\Storage\Db::setMapper * @covers ZfcUser\Authentication\Storage\Db::getMapper */ public function testSetGetMapper() { $mapper = new \ZfcUser\Mapper\User; $mapper->setTableName('zfcUser'); $this->db->setMapper($mapper); $this->assertInstanceOf('ZfcUser\Mapper\User', $this->db->getMapper()); $this->assertSame('zfcUser', $this->db->getMapper()->getTableName()); } /** * @covers ZfcUser\Authentication\Storage\Db::setServiceManager * @covers ZfcUser\Authentication\Storage\Db::getServiceManager */ public function testSetGetServicemanager() { $sm = $this->getMock('Zend\ServiceManager\ServiceManager'); $this->db->setServiceManager($sm); $this->assertInstanceOf('Zend\ServiceManager\ServiceLocatorInterface', $this->db->getServiceManager()); $this->assertSame($sm, $this->db->getServiceManager()); } /** * @covers ZfcUser\Authentication\Storage\Db::getStorage * @covers ZfcUser\Authentication\Storage\Db::setStorage */ public function testGetStorageWithoutStorageSet() { $this->assertInstanceOf('Zend\Authentication\Storage\Session', $this->db->getStorage()); } /** * @covers ZfcUser\Authentication\Storage\Db::getStorage * @covers ZfcUser\Authentication\Storage\Db::setStorage */ public function testSetGetStorage() { $storage = new \Zend\Authentication\Storage\Session('ZfcUserStorage'); $this->db->setStorage($storage); $this->assertInstanceOf('Zend\Authentication\Storage\Session', $this->db->getStorage()); } }