diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php new file mode 100644 index 0000000000000000000000000000000000000000..2c872f405ff83f11dee28677eab9bfa8afc69fa7 --- /dev/null +++ b/tests/Bootstrap.php @@ -0,0 +1,88 @@ +<?php +namespace UnicaenAppTest; + +use Zend\Loader\AutoloaderFactory; +use Zend\Mvc\Service\ServiceManagerConfig; +use Zend\ServiceManager\ServiceManager; +use RuntimeException; + +error_reporting(E_ALL | E_STRICT); +chdir(__DIR__); + +/** + * Test bootstrap, for setting up autoloading + */ +class Bootstrap +{ + protected static $serviceManager; + + public static function init() + { + $zf2ModulePaths = [dirname(dirname(__DIR__))]; + if (($path = static::findParentPath('vendor'))) { + $zf2ModulePaths[] = $path; + } + if (($path = static::findParentPath('module')) !== $zf2ModulePaths[0]) { + $zf2ModulePaths[] = $path; + } + $zf2ModulePaths[] = __DIR__; + + static::initAutoloader(); + + static::$serviceManager = new ServiceManager(new ServiceManagerConfig()); + } + + public static function getServiceManager() + { + return static::$serviceManager; + } + + protected static function initAutoloader() + { + $vendorPath = static::findParentPath('vendor'); + + if (is_readable($vendorPath . '/autoload.php')) { + include $vendorPath . '/autoload.php'; + return; + } + + $zf2Path = getenv('ZF2_PATH'); + if (!$zf2Path) { + if (defined('ZF2_PATH')) { + $zf2Path = ZF2_PATH; + } elseif (is_dir($vendorPath . '/ZF2/library')) { + $zf2Path = $vendorPath . '/ZF2/library'; + } elseif (is_dir($vendorPath . '/zendframework/zendframework/library')) { + $zf2Path = $vendorPath . '/zendframework/zendframework/library'; + } + } + + if (!$zf2Path) { + throw new RuntimeException('Unable to load ZF2. Run `php composer.phar install` or define a ZF2_PATH environment variable.'); + } + + include $zf2Path . '/Zend/Loader/AutoloaderFactory.php'; + AutoloaderFactory::factory([ + 'Zend\Loader\StandardAutoloader' => [ + 'autoregister_zf' => true, + 'namespaces' => [ + __NAMESPACE__ => __DIR__ . '/' . __NAMESPACE__, + ], + ], + ]); + } + + protected static function findParentPath($path) + { + $dir = __DIR__; + $previousDir = '.'; + while (!is_dir($dir . '/' . $path)) { + $dir = dirname($dir); + if ($previousDir === $dir) return false; + $previousDir = $dir; + } + return $dir . '/' . $path; + } +} + +Bootstrap::init(); \ No newline at end of file diff --git a/tests/UnicaenAuthTest/Acl/NamedRoleTest.php b/tests/UnicaenAuthTest/Acl/NamedRoleTest.php index 8c8a85e3be3d427545d76340091656b78e726c9d..be8e2e973982634d2de138ed937787a11797c9f0 100644 --- a/tests/UnicaenAuthTest/Acl/NamedRoleTest.php +++ b/tests/UnicaenAuthTest/Acl/NamedRoleTest.php @@ -1,7 +1,7 @@ <?php namespace UnicaenAuthTest\Acl; -use PHPUnit\Framework\TestCase; +use PHPUnit_Framework_TestCase; use UnicaenAuth\Acl\NamedRole; /** @@ -9,7 +9,7 @@ use UnicaenAuth\Acl\NamedRole; * * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> */ -class NamedRoleTest extends TestCase +class NamedRoleTest extends PHPUnit_Framework_TestCase { public function testCanConstructWithoutName() { diff --git a/tests/UnicaenAuthTest/Authentication/Adapter/AbstractFactoryTest.php b/tests/UnicaenAuthTest/Authentication/Adapter/AbstractFactoryTest.php index 10d213c87788a7a71de6ec3edf28c3860cc6240e..6e4db97b8184012a9c87948da63db69259cb74db 100644 --- a/tests/UnicaenAuthTest/Authentication/Adapter/AbstractFactoryTest.php +++ b/tests/UnicaenAuthTest/Authentication/Adapter/AbstractFactoryTest.php @@ -1,7 +1,7 @@ <?php namespace UnicaenAuthTest\Authentication\Adapter; -use PHPUnit\Framework\TestCase; +use PHPUnit_Framework_TestCase; use UnicaenAuth\Authentication\Adapter\AbstractFactory; use UnicaenAuth\Service\User; use Zend\EventManager\EventManager; @@ -13,8 +13,11 @@ use Zend\ServiceManager\ServiceManager; * * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> */ -class AbstractFactoryTest extends TestCase +class AbstractFactoryTest extends PHPUnit_Framework_TestCase { + /** + * @var AbstractFactory + */ protected $factory; protected function setUp() @@ -59,7 +62,7 @@ class AbstractFactoryTest extends TestCase /** * @dataProvider getInvalidServiceClassName - * @expectedException \UnicaenApp\Exception + * @expectedException \UnicaenApp\Exception\RuntimeException * @param string $serviceClassName */ public function testCreateServiceWithNameThrowsExceptionIfInvalidServiceSpecified($serviceClassName) @@ -75,14 +78,14 @@ class AbstractFactoryTest extends TestCase { $eventManager = new EventManager(); - $serviceLocator = $this->getMock('Zend\ServiceManager\ServiceManager', ['get']); + $serviceLocator = $this->createMock('Zend\ServiceManager\ServiceManager'/*, ['get']*/); $serviceLocator->expects($this->any()) ->method('get') ->will($this->returnCallback(function($serviceName) use ($eventManager) { if ('unicaen-auth_user_service' === $serviceName) { return new User(); } - if ('EventManager' === $serviceName) { + if ('event_manager' === $serviceName) { return $eventManager; } return null; diff --git a/tests/UnicaenAuthTest/Authentication/Adapter/CasTest.php b/tests/UnicaenAuthTest/Authentication/Adapter/CasTest.php index 9777d28512a2af55997d5d46a9031e70aab7333e..82969c0304238c44a89bfbcd1b6cb1d067f2032e 100644 --- a/tests/UnicaenAuthTest/Authentication/Adapter/CasTest.php +++ b/tests/UnicaenAuthTest/Authentication/Adapter/CasTest.php @@ -1,26 +1,31 @@ <?php + namespace UnicaenAuthTest\Authentication\Adapter; -use CAS_GracefullTerminationException; -use PHPUnit\Framework\TestCase; -use UnicaenApp\Exception; +use PHPUnit_Framework_TestCase; +use UnicaenApp\Exception\RuntimeException; use UnicaenAuth\Authentication\Adapter\Cas; +use UnicaenAuth\Authentication\Adapter\phpCASWrapper; +use UnicaenAuth\Options\ModuleOptions; use Zend\EventManager\EventManager; use ZfcUser\Authentication\Adapter\AdapterChainEvent; use Zend\Authentication\Result; -define ('__VENDOR_DIR__', __DIR__ . '/../../../../vendor'); - -require_once __VENDOR_DIR__ . '/intouch/phpcas/CAS.php'; - /** * Description of CasTest * * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> */ -class CasTest extends TestCase +class CasTest extends PHPUnit_Framework_TestCase { + /** + * @var Cas + */ protected $adapter; + + /** + * @var ModuleOptions + */ protected $moduleOptions; /** @@ -29,7 +34,7 @@ class CasTest extends TestCase */ protected function setUp() { - $this->moduleOptions = $moduleOptions = new \UnicaenAuth\Options\ModuleOptions([ + $this->moduleOptions = $moduleOptions = new ModuleOptions([ 'cas' => [ 'connection' => [ 'default' => [ @@ -45,7 +50,7 @@ class CasTest extends TestCase ], ]); - $serviceManager = $this->getMock('Zend\ServiceManager\ServiceManager', ['get']); + $serviceManager = $this->createMock('Zend\ServiceManager\ServiceManager'/*, ['get']*/); $serviceManager->expects($this->any()) ->method('get') ->will($this->returnCallback(function($serviceName) use ($moduleOptions) { @@ -56,7 +61,7 @@ class CasTest extends TestCase return $moduleOptions; } if ('router' === $serviceName) { - $router = new \Zend\Router\Http\TreeRouteStack(); + $router = new \Zend\Mvc\Router\Http\TreeRouteStack(); $router->setBaseUrl('/appli')->setRequestUri(new \Zend\Uri\Http('/request')); return $router; } @@ -80,7 +85,7 @@ class CasTest extends TestCase /** * @dataProvider getInvalidCasOptions - * @expectedException Exception + * @expectedException RuntimeException */ public function testThrowsExceptionIfNoCasParamSpecified($config) { @@ -95,54 +100,11 @@ class CasTest extends TestCase $this->assertNull($result); } - public function testCanActivateCasDebugMode() - { - $this->moduleOptions->setCas([ - 'connection' => [ - 'default' => [ - 'params' => [ - 'hostname' => 'cas.unicaen.fr', - 'port' => 443, - 'version' => "2.0", - 'uri' => "", - 'debug' => true, // debug mode - ], - ], - ], - ]); - - $casClient = $this->getMock('phpCAS', ['setDebug', 'client', 'setNoCasServerValidation']); - $casClient->staticExpects($this->once()) - ->method('setDebug'); - $this->adapter->setCasClient($casClient); - - $this->adapter->getCasClient(); - } - - public function testCanRedirectToCasIfNotAuthenticated() - { - CAS_GracefullTerminationException::throwInsteadOfExiting(); - - ob_start(); - try { - $result = $this->adapter->authenticate(new AdapterChainEvent()); - $this->fail("Exception CAS_GracefullTerminationException non levée."); - } - catch (CAS_GracefullTerminationException $e) { - - } - $result = ob_get_clean(); - - $expected = <<<EOS -<html><head><title>CAS Authentication wanted!</title></head><body><h1>CAS Authentication wanted!</h1><p>You should already have been redirected to the CAS server. Click <a href="https://cas.unicaen.fr/login?service=http%3A%2F%2F%3A">here</a> to continue.</p><hr><address>phpCAS 1.3.2+ using server <a href="https://cas.unicaen.fr/">https://cas.unicaen.fr/</a> (CAS 2.0)</a></address></body></html> -EOS; - $this->assertEquals($expected, $result); - } - - public function testAuthenticateReturnsTrueWhenAuthenticationSucceeds() + public function testAuthenticatePopulatesEventWhenAuthenticationSucceeds() { - $casClient = $this->getMock('phpCAS', ['client', 'forceAuthentication', 'getUser']); - $casClient->staticExpects($this->once()) + /** @var phpCASWrapper|\PHPUnit_Framework_MockObject_MockObject $casClient */ + $casClient = $this->createMock(phpCASWrapper::class); + $casClient->expects($this->once()) ->method('getUser') ->will($this->returnValue($username = 'username')); @@ -150,16 +112,14 @@ EOS; $event = new AdapterChainEvent(); - $result = $this->adapter->authenticate($event); + $this->adapter->authenticate($event); - $this->assertTrue($result); $this->assertTrue($this->adapter->isSatisfied()); $this->assertEquals(['is_satisfied' => true, 'identity' => $username], $this->adapter->getStorage()->read()); $this->assertEquals("userAuthenticated", $event->getName()); $this->assertEquals(Result::SUCCESS, $event->getCode()); $this->assertEquals($username, $event->getIdentity()); - $this->assertTrue($event->propagationIsStopped()); } public function testLogoutReturnsNullIfNoCasConfigSpecified() @@ -171,11 +131,12 @@ EOS; public function testCanLogoutFromCasWithRedirectService() { - $casClient = $this->getMock('phpCAS', ['client', 'isAuthenticated', 'logoutWithRedirectService']); - $casClient->staticExpects($this->once()) + /** @var phpCASWrapper|\PHPUnit_Framework_MockObject_MockObject $casClient */ + $casClient = $this->createMock(phpCASWrapper::class); + $casClient->expects($this->once()) ->method('isAuthenticated') ->will($this->returnValue(true)); - $casClient->staticExpects($this->once()) + $casClient->expects($this->once()) ->method('logoutWithRedirectService'); $this->adapter->setCasClient($casClient); diff --git a/tests/UnicaenAuthTest/Authentication/Adapter/DbTest.php b/tests/UnicaenAuthTest/Authentication/Adapter/DbTest.php index 88230d15109d76e959331fda8515aaf6f010d06c..e5edf6c3e0bb8f595d8ac8456941d4f8ef213f3d 100644 --- a/tests/UnicaenAuthTest/Authentication/Adapter/DbTest.php +++ b/tests/UnicaenAuthTest/Authentication/Adapter/DbTest.php @@ -2,7 +2,7 @@ namespace UnicaenAuthTest\Authentication\Adapter; use PDOException; -use PHPUnit\Framework\TestCase; +use PHPUnit_Framework_TestCase; use UnicaenAuth\Authentication\Adapter\Db; use UnicaenAuth\Options\ModuleOptions; use Zend\Http\PhpEnvironment\Request; @@ -15,7 +15,7 @@ use ZfcUser\Authentication\Adapter\AdapterChainEvent; * * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> */ -class DbTest extends TestCase +class DbTest extends PHPUnit_Framework_TestCase { protected $adapter; protected $moduleOptions; @@ -43,9 +43,9 @@ class DbTest extends TestCase ], ]); - $this->mapper = $mapper = $this->getMock('ZfcUser\Mapper\User', ['findByUsername', 'findByEmail']); + $this->mapper = $mapper = $this->createMock('ZfcUser\Mapper\User'/*, ['findByUsername', 'findByEmail']*/); - $serviceManager = $this->getMock('Zend\ServiceManager\ServiceManager', ['get']); + $serviceManager = $this->createMock('Zend\ServiceManager\ServiceManager'/*, ['get']*/); $serviceManager->expects($this->any()) ->method('get') ->will($this->returnCallback(function($serviceName) use ($moduleOptions, $mapper) { diff --git a/tests/UnicaenAuthTest/Authentication/Adapter/LdapTest.php b/tests/UnicaenAuthTest/Authentication/Adapter/LdapTest.php index 01e68b706e841311cadd97d1bdcdc0ad00f3c916..bf14c6bdf0a98b4642e8953b4ea1afc12ecef9a3 100644 --- a/tests/UnicaenAuthTest/Authentication/Adapter/LdapTest.php +++ b/tests/UnicaenAuthTest/Authentication/Adapter/LdapTest.php @@ -1,11 +1,13 @@ <?php + namespace UnicaenAuthTest\Authentication\Adapter; -use PHPUnit\Framework\TestCase; +use PHPUnit_Framework_TestCase; use UnicaenAuth\Authentication\Adapter\Ldap; use Zend\Authentication\Result; use Zend\EventManager\EventManager; use Zend\Http\Request; +use Zend\ServiceManager\ServiceManager; use Zend\Stdlib\Parameters; use ZfcUser\Authentication\Adapter\AdapterChainEvent; @@ -14,12 +16,27 @@ use ZfcUser\Authentication\Adapter\AdapterChainEvent; * * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> */ -class LdapTest extends TestCase +class LdapTest extends PHPUnit_Framework_TestCase { + /** + * @var Ldap + */ protected $adapter; + + /** + * @var \Zend\Authentication\Adapter\Ldap|\PHPUnit_Framework_MockObject_MockObject + */ + protected $zendAuthLdapAdapter; + + /** + * @var \UnicaenApp\Options\ModuleOptions + */ protected $appModuleOptions; + + /** + * @var \UnicaenAuth\Options\ModuleOptions + */ protected $authModuleOptions; - protected $mapper; /** * Sets up the fixture, for example, open a network connection. @@ -47,12 +64,11 @@ class LdapTest extends TestCase 'usurpation_allowed_usernames' => ['usurpateur'], ]); - $this->mapper = $mapper = $this->getMock('ZfcUser\Mapper\User', ['findByUsername', 'findByEmail']); - - $serviceManager = $this->getMock('Zend\ServiceManager\ServiceManager', ['get']); + /** @var ServiceManager|\PHPUnit_Framework_MockObject_MockObject $serviceManager */ + $serviceManager = $this->createMock('Zend\ServiceManager\ServiceManager'/*, ['get']*/); $serviceManager->expects($this->any()) ->method('get') - ->will($this->returnCallback(function($serviceName) use ($authModuleOptions, $appModuleOptions, $mapper) { + ->will($this->returnCallback(function($serviceName) use ($authModuleOptions, $appModuleOptions) { if ('zfcuser_module_options' === $serviceName) { return new \ZfcUser\Options\ModuleOptions(); } @@ -62,14 +78,11 @@ class LdapTest extends TestCase if ('unicaen-auth_module_options' === $serviceName) { return $authModuleOptions; } - if ('zfcuser_user_mapper' === $serviceName) { - return $mapper; - } return null; })); $this->adapter = new Ldap(); - $this->adapter->setServiceLocator($serviceManager) + $this->adapter->setServiceManager($serviceManager) ->setEventManager(new EventManager()); } @@ -94,27 +107,84 @@ class LdapTest extends TestCase public function testUsurpationWithAllowedUsernameAndSuccessfulAuthentication() { + /** @var \Zend\Authentication\Adapter\Ldap|\PHPUnit_Framework_MockObject_MockObject $zendAuthLdapAdapter */ + $this->zendAuthLdapAdapter = $this->createMock('Zend\Authentication\Adapter\Ldap'); + + /** @var \Zend\Ldap\Ldap|\PHPUnit_Framework_MockObject_MockObject $ldap */ + $ldap = $this->createMock(\Zend\Ldap\Ldap::class); + $ldap + ->expects($this->once()) + ->method('searchEntries') + ->willReturn(true); + + /** @var \Zend\Authentication\Adapter\Ldap|\PHPUnit_Framework_MockObject_MockObject $ldapAuthAdapter */ + $this->zendAuthLdapAdapter->expects($this->once()) + ->method('getLdap') + ->willReturn($ldap); + $this->authModuleOptions->setUsurpationAllowedUsernames(['usurpateur']); $event = new AdapterChainEvent(); - $result = $this->_authenticateWithUsurpation(Result::SUCCESS, $event); + $this->_authenticateWithUsurpation(Result::SUCCESS, $event); - $this->assertTrue($result); $this->assertTrue($this->adapter->isSatisfied()); $this->assertEquals(['is_satisfied' => true, 'identity' => 'usurpe'], $this->adapter->getStorage()->read()); $this->assertEquals("userAuthenticated", $event->getName()); $this->assertEquals(Result::SUCCESS, $event->getCode()); $this->assertEquals('usurpe', $event->getIdentity()); - $this->assertTrue($event->propagationIsStopped()); } public function testUsurpationWithAllowedUsernameAndUnsuccessfulAuthentication() { + /** @var \Zend\Authentication\Adapter\Ldap|\PHPUnit_Framework_MockObject_MockObject $zendAuthLdapAdapter */ + $this->zendAuthLdapAdapter = $this->createMock('Zend\Authentication\Adapter\Ldap'); + + /** @var \Zend\Ldap\Ldap|\PHPUnit_Framework_MockObject_MockObject $ldap */ + $ldap = $this->createMock(\Zend\Ldap\Ldap::class); + $ldap + ->expects($this->once()) + ->method('searchEntries') + ->willReturn([]); + + /** @var \Zend\Authentication\Adapter\Ldap|\PHPUnit_Framework_MockObject_MockObject $ldapAuthAdapter */ + $this->zendAuthLdapAdapter->expects($this->once()) + ->method('getLdap') + ->willReturn($ldap); + + $this->authModuleOptions->setUsurpationAllowedUsernames(['usurpateur']); + $event = new AdapterChainEvent(); + $this->_authenticateWithUsurpation(Result::FAILURE, $event); + + $this->assertFalse($this->adapter->isSatisfied()); + $this->assertEquals(['is_satisfied' => false], $this->adapter->getStorage()->read()); + + $this->assertNull($event->getName()); + $this->assertEquals(Result::FAILURE, $event->getCode()); + $this->assertNull($event->getIdentity()); + $this->assertFalse($event->propagationIsStopped()); + } + + public function testUsurpationWithAllowedButUnexistingUsername() + { + /** @var \Zend\Authentication\Adapter\Ldap|\PHPUnit_Framework_MockObject_MockObject $zendAuthLdapAdapter */ + $this->zendAuthLdapAdapter = $this->createMock('Zend\Authentication\Adapter\Ldap'); + + /** @var \Zend\Ldap\Ldap|\PHPUnit_Framework_MockObject_MockObject $ldap */ + $ldap = $this->createMock(\Zend\Ldap\Ldap::class); + $ldap + ->expects($this->once()) + ->method('searchEntries') + ->willReturn([]); + + /** @var \Zend\Authentication\Adapter\Ldap|\PHPUnit_Framework_MockObject_MockObject $ldapAuthAdapter */ + $this->zendAuthLdapAdapter->expects($this->once()) + ->method('getLdap') + ->willReturn($ldap); + $this->authModuleOptions->setUsurpationAllowedUsernames(['usurpateur']); $event = new AdapterChainEvent(); - $result = $this->_authenticateWithUsurpation(Result::FAILURE, $event); + $this->_authenticateWithUsurpation(Result::FAILURE, $event); - $this->assertFalse($result); $this->assertFalse($this->adapter->isSatisfied()); $this->assertEquals(['is_satisfied' => false], $this->adapter->getStorage()->read()); @@ -126,26 +196,29 @@ class LdapTest extends TestCase public function testUsurpationWithNotAllowedUsernameAndSuccessfulAuthentication() { + /** @var \Zend\Authentication\Adapter\Ldap|\PHPUnit_Framework_MockObject_MockObject $zendAuthLdapAdapter */ + $this->zendAuthLdapAdapter = $this->createMock('Zend\Authentication\Adapter\Ldap'); + $this->authModuleOptions->setUsurpationAllowedUsernames([]); $event = new AdapterChainEvent(); - $result = $this->_authenticateWithUsurpation(Result::SUCCESS, $event); + $this->_authenticateWithUsurpation(Result::SUCCESS, $event); - $this->assertTrue($result); $this->assertTrue($this->adapter->isSatisfied()); - $this->assertEquals(['is_satisfied' => true, 'identity' => 'usurpateur'], $this->adapter->getStorage()->read()); + $this->assertEquals(['is_satisfied' => true, 'identity' => 'usurpateur=usurpe'], $this->adapter->getStorage()->read()); $this->assertEquals("userAuthenticated", $event->getName()); - $this->assertTrue($event->propagationIsStopped()); - $this->assertEquals('usurpateur', $event->getIdentity()); + $this->assertEquals('usurpateur=usurpe', $event->getIdentity()); } public function testUsurpationWithNotAllowedUsernameAndUnsuccessfulAuthentication() { + /** @var \Zend\Authentication\Adapter\Ldap|\PHPUnit_Framework_MockObject_MockObject $zendAuthLdapAdapter */ + $this->zendAuthLdapAdapter = $this->createMock('Zend\Authentication\Adapter\Ldap'); + $this->authModuleOptions->setUsurpationAllowedUsernames([]); $event = new AdapterChainEvent(); - $result = $this->_authenticateWithUsurpation(Result::FAILURE, $event); + $this->_authenticateWithUsurpation(Result::FAILURE, $event); - $this->assertFalse($result); $this->assertFalse($this->adapter->isSatisfied()); $this->assertEquals(['is_satisfied' => false], $this->adapter->getStorage()->read()); @@ -161,23 +234,22 @@ class LdapTest extends TestCase $usernameUsurpe = 'usurpe'; $username = $usernameUsurpateur . Ldap::USURPATION_USERNAMES_SEP . $usernameUsurpe; - $ldapAuthAdapter = $this->getMock('Zend\Authentication\Adapter\Ldap', ['setUsername', 'setPassword', 'authenticate']); - $ldapAuthAdapter->expects($this->once()) + $this->zendAuthLdapAdapter->expects($this->once()) ->method('setUsername') ->with($usernameUsurpateur) ->will($this->returnSelf()); - $ldapAuthAdapter->expects($this->once()) + $this->zendAuthLdapAdapter->expects($this->once()) ->method('setPassword') ->will($this->returnSelf()); - $ldapAuthAdapter->expects($this->once()) + $this->zendAuthLdapAdapter->expects($this->once()) ->method('authenticate') ->will($this->returnValue(new Result($authenticationResultCode, $usernameUsurpateur))); - $this->adapter->setLdapAuthAdapter($ldapAuthAdapter); + $this->adapter->setLdapAuthAdapter($this->zendAuthLdapAdapter); $request = new Request(); $request->setPost(new Parameters(['identity' => $username, 'credential' => "xxxxx"])); $event->setRequest($request); - return $this->adapter->authenticate($event); + $this->adapter->authenticate($event); } } \ No newline at end of file diff --git a/tests/UnicaenAuthTest/Authentication/AuthenticationServiceFactoryTest.php b/tests/UnicaenAuthTest/Authentication/AuthenticationServiceFactoryTest.php index 77c28af8bc885a95d0975e69d10a9ca37624c264..4cdb7b358ad321d99a3b7132934d983632b1dce4 100644 --- a/tests/UnicaenAuthTest/Authentication/AuthenticationServiceFactoryTest.php +++ b/tests/UnicaenAuthTest/Authentication/AuthenticationServiceFactoryTest.php @@ -16,8 +16,8 @@ class ModuleOptionsFactoryTest extends BaseServiceFactoryTest public function testCanCreateService() { - $storage = $this->getMock('UnicaenAuth\Authentication\Storage\Chain', []); - $adapter = $this->getMock('ZfcUser\Authentication\Adapter\AdapterChain', []); + $storage = $this->createMock('UnicaenAuth\Authentication\Storage\Chain'); + $adapter = $this->createMock('ZfcUser\Authentication\Adapter\AdapterChain'); $this->serviceManager->expects($this->exactly(2)) ->method('get') @@ -26,7 +26,7 @@ class ModuleOptionsFactoryTest extends BaseServiceFactoryTest ['ZfcUser\Authentication\Adapter\AdapterChain', $adapter], ])); - $service = $this->factory->createService($this->serviceManager); + $service = $this->factory->__invoke($this->serviceManager, ''); $this->assertInstanceOf($this->serviceClass, $service); } diff --git a/tests/UnicaenAuthTest/Authentication/Storage/ChainEventTest.php b/tests/UnicaenAuthTest/Authentication/Storage/ChainEventTest.php index cacc15d2e1abfe1ce4ccf12c077684e12a47035e..010219b3cc402a6a499642c71e30b97283b0694c 100644 --- a/tests/UnicaenAuthTest/Authentication/Storage/ChainEventTest.php +++ b/tests/UnicaenAuthTest/Authentication/Storage/ChainEventTest.php @@ -2,7 +2,7 @@ namespace UnicaenAuthTest\Authentication\Storage; use PDOException; -use PHPUnit\Framework\TestCase; +use PHPUnit_Framework_TestCase; use UnicaenAuth\Authentication\Storage\Db; use Zend\ServiceManager\Exception\ServiceNotFoundException; use ZfcUser\Entity\User; @@ -13,7 +13,7 @@ use UnicaenAuth\Authentication\Storage\ChainEvent; * * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> */ -class ChainEventTest extends TestCase +class ChainEventTest extends PHPUnit_Framework_TestCase { protected $event; diff --git a/tests/UnicaenAuthTest/Authentication/Storage/ChainServiceFactoryTest.php b/tests/UnicaenAuthTest/Authentication/Storage/ChainServiceFactoryTest.php index ae3a08cd4e6c7b4e0ecd7fc07f137a83bff215d2..5da08775fcccf09d78fa938ad3008fb601e84a18 100644 --- a/tests/UnicaenAuthTest/Authentication/Storage/ChainServiceFactoryTest.php +++ b/tests/UnicaenAuthTest/Authentication/Storage/ChainServiceFactoryTest.php @@ -9,7 +9,7 @@ use UnicaenAuth\Authentication\Storage\ChainServiceFactory; * * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> */ -class ChainServiceFactoryTest extends \PHPUnit\Framework\TestCase +class ChainServiceFactoryTest extends \PHPUnit_Framework_TestCase { protected $serviceLocator; protected $eventManager; @@ -23,9 +23,9 @@ class ChainServiceFactoryTest extends \PHPUnit\Framework\TestCase protected function setUp() { $this->factory = new ChainServiceFactory(); - $this->serviceLocator = $this->getMock('Zend\ServiceManager\ServiceLocatorInterface', []); - $this->ldapStorage = $this->getMock('UnicaenAuth\Authentication\Storage\Ldap', $this->events); - $this->dbStorage = $this->getMock('UnicaenAuth\Authentication\Storage\Db', $this->events); + $this->serviceLocator = $this->createMock('Zend\ServiceManager\ServiceLocatorInterface'/*, []*/); + $this->ldapStorage = $this->createMock('UnicaenAuth\Authentication\Storage\Ldap'/*, $this->events*/); + $this->dbStorage = $this->createMock('UnicaenAuth\Authentication\Storage\Db'/*, $this->events*/); } public function testCanCreateService() @@ -34,7 +34,7 @@ class ChainServiceFactoryTest extends \PHPUnit\Framework\TestCase ->method('get') ->will($this->onConsecutiveCalls($this->ldapStorage, $this->dbStorage)); - $service = $this->factory->createService($this->serviceLocator); + $service = $this->factory->__invoke($this->serviceLocator, ''); $this->assertInstanceOf('UnicaenAuth\Authentication\Storage\Chain', $service); diff --git a/tests/UnicaenAuthTest/Authentication/Storage/ChainTest.php b/tests/UnicaenAuthTest/Authentication/Storage/ChainTest.php index 665fd183f06168670ebffa07ab6de90e40e8ab55..04f1426cbec06bd5452655630bbd2149a8e04ad1 100644 --- a/tests/UnicaenAuthTest/Authentication/Storage/ChainTest.php +++ b/tests/UnicaenAuthTest/Authentication/Storage/ChainTest.php @@ -9,11 +9,19 @@ use UnicaenAuth\Authentication\Storage\Chain; * * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> */ -class ChainTest extends \PHPUnit\Framework\TestCase +class ChainTest extends \PHPUnit_Framework_TestCase { + /** + * @var Chain + */ protected $storage; + protected $innerStorage; protected $eventManager; + + /** + * @var \UnicaenAuth\Authentication\Storage\ChainEvent|\PHPUnit_Framework_MockObject_MockObject + */ protected $event; /** @@ -23,9 +31,9 @@ class ChainTest extends \PHPUnit\Framework\TestCase protected function setUp() { $this->storage = new Chain(); - $this->innerStorage = $this->getMock('Zend\Authentication\Storage\Session', ['isEmpty', 'read', 'write', 'clear']); - $this->eventManager = $this->getMock('Zend\EventManager\EventManager', ['trigger']); - $this->event = $this->getMock('UnicaenAuth\Authentication\Storage\ChainEvent', ['getContents']); + $this->innerStorage = $this->createMock('Zend\Authentication\Storage\Session'/*, ['isEmpty', 'read', 'write', 'clear']*/); + $this->eventManager = $this->createMock('Zend\EventManager\EventManager'/*, ['trigger']*/); + $this->event = $this->createMock('UnicaenAuth\Authentication\Storage\ChainEvent'/*, ['getContents']*/); $this->storage->setStorage($this->innerStorage) ->setEventManager($this->eventManager) @@ -83,12 +91,18 @@ class ChainTest extends \PHPUnit\Framework\TestCase public function testCanWrite() { - $this->innerStorage->expects($this->once()) - ->method('write') - ->with(12); - $this->eventManager->expects($this->once()) - ->method('trigger') - ->with('write', $this->logicalAnd( + $this->innerStorage + ->expects($this->once()) + ->method('write') + ->with(12); + $this->event + ->expects($this->once()) + ->method('setParams') + ->with(['contents' => 12]); + $this->eventManager + ->expects($this->once()) + ->method('trigger') + ->with('write', $this->logicalAnd( $this->isInstanceOf('UnicaenAuth\Authentication\Storage\ChainEvent'), $this->attributeEqualTo('params', ['contents' => 12]))); $this->storage->write(12); diff --git a/tests/UnicaenAuthTest/Authentication/Storage/DbTest.php b/tests/UnicaenAuthTest/Authentication/Storage/DbTest.php index b082054ef71f4087e5e41ddce789c4f2a36d0d1a..607550481f4c5b0ff7a072c7b4133e0f75beb132 100644 --- a/tests/UnicaenAuthTest/Authentication/Storage/DbTest.php +++ b/tests/UnicaenAuthTest/Authentication/Storage/DbTest.php @@ -2,7 +2,7 @@ namespace UnicaenAuthTest\Authentication\Storage; use PDOException; -use PHPUnit\Framework\TestCase; +use PHPUnit_Framework_TestCase; use UnicaenAuth\Authentication\Storage\Db; use Zend\ServiceManager\Exception\ServiceNotFoundException; use Zend\ServiceManager\ServiceManager; @@ -14,7 +14,7 @@ use UnicaenAuth\Authentication\Storage\ChainEvent; * * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> */ -class DbTest extends TestCase +class DbTest extends PHPUnit_Framework_TestCase { protected $storage; protected $serviceManager; @@ -27,14 +27,14 @@ class DbTest extends TestCase */ protected function setUp() { - $this->serviceManager = $this->getMock('Zend\ServiceManager\ServiceManager', ['get']); - $this->innerStorage = $this->getMock('Zend\Authentication\Storage\Session', ['write', 'clear', 'read']); - $this->mapper = $this->getMock('ZfcUser\Mapper\User', ['findById', 'findByUsername']); + $this->serviceManager = $this->createMock('Zend\ServiceManager\ServiceManager'/*, ['get']*/); + $this->innerStorage = $this->createMock('Zend\Authentication\Storage\Session'/*, ['write', 'clear', 'read']*/); + $this->mapper = $this->createMock('ZfcUser\Mapper\User'/*, ['findById', 'findByUsername']*/); $this->event = new ChainEvent(); $this->storage = new Db(); $this->storage->setMapper($this->mapper) - ->setServiceLocator($this->serviceManager) + ->setServiceManager($this->serviceManager) ->setStorage($this->innerStorage); } diff --git a/tests/UnicaenAuthTest/Authentication/Storage/LdapTest.php b/tests/UnicaenAuthTest/Authentication/Storage/LdapTest.php index 449b84748259bb6f6c58049fd8cb6b8c487e54c2..e8ce9a2df9a168877b056f1a976bdb11d8b19318 100644 --- a/tests/UnicaenAuthTest/Authentication/Storage/LdapTest.php +++ b/tests/UnicaenAuthTest/Authentication/Storage/LdapTest.php @@ -1,7 +1,7 @@ <?php namespace UnicaenAuthTest\Authentication\Storage; -use PHPUnit\Framework\TestCase; +use PHPUnit_Framework_TestCase; use UnicaenApp\Entity\Ldap\People; use UnicaenAuth\Entity\Ldap\People as AuthPeople; use UnicaenAppTest\Entity\Ldap\TestAsset\People as PeopleTestAsset; @@ -13,13 +13,25 @@ use UnicaenAuth\Authentication\Storage\ChainEvent; * * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> */ -class LdapTest extends TestCase +class LdapTest extends PHPUnit_Framework_TestCase { + /** + * @var Ldap + */ protected $storage; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\UnicaenApp\Mapper\Ldap\People + */ protected $mapper; + protected $serviceManager; protected $options; protected $event; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Zend\Authentication\Storage\Session + */ protected $innerStorage; /** @@ -29,14 +41,14 @@ class LdapTest extends TestCase protected function setUp() { $this->options = new \UnicaenAuth\Options\ModuleOptions(); - $this->serviceManager = $this->getMock('Zend\ServiceManager\ServiceManager', ['get']); - $this->innerStorage = $this->getMock('Zend\Authentication\Storage\Session', ['write', 'clear', 'read']); - $this->mapper = $this->getMock('UnicaenApp\Mapper\Ldap\People', ['findOneByUsername']); + $this->serviceManager = $this->createMock('Zend\ServiceManager\ServiceManager'/*, ['get']*/); + $this->innerStorage = $this->createMock('Zend\Authentication\Storage\Session'/*, ['write', 'clear', 'read']*/); + $this->mapper = $this->createMock('UnicaenApp\Mapper\Ldap\People'/*, ['findOneByUsername']*/); $this->event = new ChainEvent(); $this->storage = new Ldap(); $this->storage->setMapper($this->mapper) - ->setServiceLocator($this->serviceManager) + ->setServiceManager($this->serviceManager) ->setStorage($this->innerStorage); } @@ -111,25 +123,14 @@ class LdapTest extends TestCase $this->assertEquals(['ldap' => null], $this->event->getContents()); } - public function getException() - { - return [ - [new \Zend\Ldap\Exception\LdapException()], - [new \UnicaenApp\Exception()], - ]; - } - - /** - * @dataProvider getException - */ - public function testReadingReturnsNullIfFindByUsernameThrowsException($exception) + public function testReadingReturnsNullIfFindByUsernameThrowsException() { $this->innerStorage->expects($this->once()) ->method('read') ->will($this->returnValue(12)); $this->mapper->expects($this->once()) ->method('findOneByUsername') - ->will($this->throwException($exception)); + ->will($this->throwException(new \UnicaenApp\Exception\RuntimeException())); $this->storage->read($this->event); $this->assertEquals(['ldap' => null], $this->event->getContents()); diff --git a/tests/UnicaenAuthTest/Entity/Db/UserTest.php b/tests/UnicaenAuthTest/Entity/Db/UserTest.php index d5100379f08ad16d754df16b814f3ec68c05c073..a9efead6de0e3fcdc4f4b78a94f1c8d8f166ce8e 100644 --- a/tests/UnicaenAuthTest/Entity/Db/UserTest.php +++ b/tests/UnicaenAuthTest/Entity/Db/UserTest.php @@ -2,16 +2,20 @@ namespace UnicaenAuthTest\Entity\Db; +use Doctrine\Common\Collections\Collection; use UnicaenAuth\Entity\Db\User; -use PHPUnit\Framework\TestCase; +use PHPUnit_Framework_TestCase; /** * Description of UserTest * * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> */ -class UserTest extends TestCase +class UserTest extends PHPUnit_Framework_TestCase { + /** + * @var User + */ protected $user; protected function setUp() @@ -27,7 +31,8 @@ class UserTest extends TestCase public function testConstructorInitializeRoles() { - $this->assertEquals([], $this->user->getRoles()); + $this->assertInstanceOf(Collection::class, $this->user->getRoles()); + $this->assertEmpty($this->user->getRoles()); } public function testCanSetId() @@ -74,7 +79,7 @@ class UserTest extends TestCase ]); $this->user->addRole($roles[0]); $this->user->addRole($roles[1]); - $this->assertEquals($roles->getValues(), $this->user->getRoles()); + $this->assertEquals($roles->toArray(), $this->user->getRoles()->toArray()); } public function testCanGetObjectToString() diff --git a/tests/UnicaenAuthTest/Entity/Ldap/PeopleTest.php b/tests/UnicaenAuthTest/Entity/Ldap/PeopleTest.php index 089c94be4eed5956b99dc9f3d35a195e60d5d724..8ba2660519025d088507e5888d3e3e9b0644c4b8 100644 --- a/tests/UnicaenAuthTest/Entity/Ldap/PeopleTest.php +++ b/tests/UnicaenAuthTest/Entity/Ldap/PeopleTest.php @@ -10,7 +10,7 @@ use UnicaenAppTest\Entity\Ldap\TestAsset\People as PeopleTestAsset; * * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> */ -class PeopleTest extends \PHPUnit\Framework\TestCase +class PeopleTest extends \PHPUnit_Framework_TestCase { protected $entity; @@ -58,7 +58,7 @@ class PeopleTest extends \PHPUnit\Framework\TestCase public function testGetDisplayNameReturnsString() { - $this->assertIsString($this->entity->getDisplayName()); + $this->assertInternalType('string', $this->entity->getDisplayName()); $this->assertNotEmpty($this->entity->getDisplayName()); } @@ -72,7 +72,7 @@ class PeopleTest extends \PHPUnit\Framework\TestCase public function testGetEmailReturnsString() { - $this->assertIsString($this->entity->getEmail()); + $this->assertInternalType('string', $this->entity->getEmail()); $this->assertNotEmpty($this->entity->getEmail()); } diff --git a/tests/UnicaenAuthTest/Options/ModuleOptionsFactoryTest.php b/tests/UnicaenAuthTest/Options/ModuleOptionsFactoryTest.php index fbf6f9876e6d181600558bdcc0e7fc366336c054..a7fb433787f5d64781474848131bcdf2b146fb40 100644 --- a/tests/UnicaenAuthTest/Options/ModuleOptionsFactoryTest.php +++ b/tests/UnicaenAuthTest/Options/ModuleOptionsFactoryTest.php @@ -27,7 +27,7 @@ class ModuleOptionsFactoryTest extends BaseServiceFactoryTest ->with('Configuration') ->will($this->returnValue($config)); - $service = $this->factory->createService($this->serviceManager); + $service = $this->factory->__invoke($this->serviceManager, ''); $this->assertInstanceOf($this->serviceClass, $service); } @@ -50,7 +50,7 @@ class ModuleOptionsFactoryTest extends BaseServiceFactoryTest ->with('Configuration') ->will($this->returnValue($config)); - $service = $this->factory->createService($this->serviceManager); /* @var $service \UnicaenAuth\Options\ModuleOptions */ + $service = $this->factory->__invoke($this->serviceManager, ''); /* @var $service \UnicaenAuth\Options\ModuleOptions */ $this->assertInstanceOf($this->serviceClass, $service); $this->assertEquals('other', $service->getLoginRedirectRoute()); diff --git a/tests/UnicaenAuthTest/Options/ModuleOptionsTest.php b/tests/UnicaenAuthTest/Options/ModuleOptionsTest.php index 4fe771295c06647949c263054fa3553f20c28a09..7ad546568cd731ab7c517f213fd1fa777e49d3b9 100644 --- a/tests/UnicaenAuthTest/Options/ModuleOptionsTest.php +++ b/tests/UnicaenAuthTest/Options/ModuleOptionsTest.php @@ -1,7 +1,7 @@ <?php namespace UnicaenAuthTest\Options; -use PHPUnit\Framework\TestCase; +use PHPUnit_Framework_TestCase; use UnicaenAuth\Options\ModuleOptions; /** @@ -9,7 +9,7 @@ use UnicaenAuth\Options\ModuleOptions; * * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> */ -class ModuleOptionsTest extends TestCase +class ModuleOptionsTest extends PHPUnit_Framework_TestCase { protected $options; @@ -31,10 +31,10 @@ class ModuleOptionsTest extends TestCase { $options = new ModuleOptions(); - $this->assertIsArray($array = $options->getUsurpationAllowedUsernames()); + $this->assertInternalType('array', $array = $options->getUsurpationAllowedUsernames()); $this->assertEmpty($array); - $this->assertIsArray($array = $options->getCas()); + $this->assertInternalType('array', $array = $options->getCas()); $this->assertEmpty($array); $this->assertFalse($this->options->getSaveLdapUserInDatabase()); diff --git a/tests/UnicaenAuthTest/Provider/Identity/BaseServiceFactoryTest.php b/tests/UnicaenAuthTest/Provider/Identity/BaseServiceFactoryTest.php index 6dbfea96e02f2492d67d29e825751d89dc352a7b..481988bbccee6f7390766bf8a24b9939ec08563a 100644 --- a/tests/UnicaenAuthTest/Provider/Identity/BaseServiceFactoryTest.php +++ b/tests/UnicaenAuthTest/Provider/Identity/BaseServiceFactoryTest.php @@ -24,9 +24,9 @@ abstract class BaseServiceFactoryTest extends TestCase protected function setUp() { $this->factory = new $this->factoryClass(); - $this->serviceLocator = $this->getMock('Zend\ServiceManager\ServiceLocatorInterface', []); - $this->authService = $this->getMock('Zend\Authentication\AuthenticationService', []); - $this->userService = $this->getMock('ZfcUser\Service\User', ['getAuthService']); + $this->serviceLocator = $this->createMock('Zend\ServiceManager\ServiceLocatorInterface'/*, []*/); + $this->authService = $this->createMock('Zend\Authentication\AuthenticationService'/*, []*/); + $this->userService = $this->createMock('ZfcUser\Service\User'/*, ['getAuthService']*/); } public function testCanCreateService() @@ -43,7 +43,7 @@ abstract class BaseServiceFactoryTest extends TestCase ->method('get') ->will($this->returnValueMap($map)); - $service = $this->factory->createService($this->serviceLocator); + $service = $this->factory->__invoke($this->serviceLocator, ''); $this->assertInstanceOf($this->serviceClass, $service); $this->assertEquals('default', $service->getDefaultRole()); diff --git a/tests/UnicaenAuthTest/Provider/Identity/BaseTest.php b/tests/UnicaenAuthTest/Provider/Identity/BaseTest.php index f5d15fc166c4b2cbb272bfb2bbe239d19209b404..35c723c121372be5a7ecbf13c1986d535c7ef207 100644 --- a/tests/UnicaenAuthTest/Provider/Identity/BaseTest.php +++ b/tests/UnicaenAuthTest/Provider/Identity/BaseTest.php @@ -22,8 +22,8 @@ abstract class BaseTest extends TestCase */ protected function setUp() { - $this->serviceManager = $this->getMock('Zend\ServiceManager\ServiceManager', ['get']); - $this->authService = $this->getMock('Zend\Authentication\AuthenticationService', ['getIdentity']); + $this->serviceManager = $this->createMock('Zend\ServiceManager\ServiceManager'/*, ['get']*/); + $this->authService = $this->createMock('Zend\Authentication\AuthenticationService'/*, ['getIdentity']*/); $this->provider = new $this->providerClass($this->authService); } @@ -65,7 +65,7 @@ abstract class BaseTest extends TestCase { $event = new \UnicaenAuth\Provider\Identity\ChainEvent(); $roles = [new NamedRole('role id')]; - $provider = $this->getMock($this->providerClass, ['getIdentityRoles'], [$this->authService]); + $provider = $this->createMock($this->providerClass/*, ['getIdentityRoles'], [$this->authService]*/); $provider->expects($this->once()) ->method('getIdentityRoles') diff --git a/tests/UnicaenAuthTest/Provider/Identity/ChainServiceFactoryTest.php b/tests/UnicaenAuthTest/Provider/Identity/ChainServiceFactoryTest.php index 1b5d5c4603a18d7cfff6f5420686518bea97cb28..bc6c7bd64fbb72c574b2c669a7ade9fb5ea85a2c 100644 --- a/tests/UnicaenAuthTest/Provider/Identity/ChainServiceFactoryTest.php +++ b/tests/UnicaenAuthTest/Provider/Identity/ChainServiceFactoryTest.php @@ -24,9 +24,9 @@ class ChainServiceFactoryTest extends TestCase protected function setUp() { $this->factory = new ChainServiceFactory(); - $this->serviceLocator = $this->getMock('Zend\ServiceManager\ServiceLocatorInterface', []); - $this->ldapProvider = $this->getMock('UnicaenAuth\Provider\Identity\Ldap', $this->events, [], '', false); - $this->dbProvider = $this->getMock('UnicaenAuth\Provider\Identity\Db', $this->events, [], '', false); + $this->serviceLocator = $this->createMock('Zend\ServiceManager\ServiceLocatorInterface'/*, []*/); + $this->ldapProvider = $this->createMock('UnicaenAuth\Provider\Identity\Ldap'/**//*, $this->events, [], '', false*/); + $this->dbProvider = $this->createMock('UnicaenAuth\Provider\Identity\Db'/*, $this->events, [], '', false*/); } public function testCanCreateService() @@ -35,7 +35,7 @@ class ChainServiceFactoryTest extends TestCase ->method('get') ->will($this->onConsecutiveCalls($this->dbProvider, $this->ldapProvider)); - $service = $this->factory->createService($this->serviceLocator); + $service = $this->factory->__invoke($this->serviceLocator, ''); $this->assertInstanceOf('UnicaenAuth\Provider\Identity\Chain', $service); diff --git a/tests/UnicaenAuthTest/Provider/Identity/ChainTest.php b/tests/UnicaenAuthTest/Provider/Identity/ChainTest.php index 61ba53f2813f31efaf58a94fcc8ad9048a17d03e..7f22930dd0e778cf096be506a8b14a3edc47dc23 100644 --- a/tests/UnicaenAuthTest/Provider/Identity/ChainTest.php +++ b/tests/UnicaenAuthTest/Provider/Identity/ChainTest.php @@ -26,13 +26,13 @@ class ChainTest extends TestCase */ protected function setUp() { - $this->authorize = $this->getMock('BjyAuthorize\Service\Authorize', ['getAcl'], [], '', false); - $this->serviceManager = $this->getMock('Zend\ServiceManager\ServiceManager', ['get']); - $this->authService = $this->getMock('Zend\Authentication\AuthenticationService', ['getIdentity']); + $this->authorize = $this->createMock('BjyAuthorize\Service\Authorize'/*, ['getAcl'], [], '', false*/); + $this->serviceManager = $this->createMock('Zend\ServiceManager\ServiceManager'/*, ['get']*/); + $this->authService = $this->createMock('Zend\Authentication\AuthenticationService'/*, ['getIdentity']*/); $this->provider = new Chain($this->authService); - $this->eventManager = $this->getMock('Zend\EventManager\EventManager', ['trigger']); - $this->event = $this->getMock('UnicaenAuth\Provider\Identity\ChainEvent', ['getRoles']); - $this->acl = $this->getMock('Zend\Permissions\Acl\Acl', ['hasRole', 'getRole']); + $this->eventManager = $this->createMock('Zend\EventManager\EventManager'/*, ['trigger']*/); + $this->event = $this->createMock('UnicaenAuth\Provider\Identity\ChainEvent'/*, ['getRoles']*/); + $this->acl = $this->createMock('Zend\Permissions\Acl\Acl'/*, ['hasRole', 'getRole']*/); $this->authorize->expects($this->any()) ->method('getAcl') diff --git a/tests/UnicaenAuthTest/Provider/Identity/DbTest.php b/tests/UnicaenAuthTest/Provider/Identity/DbTest.php index 2390ed464ab131b174e81564484c1ef2dd4dfd67..b4a28d20f1daa1a5fee5fe00262bb6fcf090c07c 100644 --- a/tests/UnicaenAuthTest/Provider/Identity/DbTest.php +++ b/tests/UnicaenAuthTest/Provider/Identity/DbTest.php @@ -15,7 +15,7 @@ class DbTest extends BaseTest $role = new \UnicaenAuth\Entity\Db\Role(); $role->setRoleId('role id'); - $identity1 = $this->getMock('UnicaenAuth\Entity\Db\User', ['getRoles', 'getUsername']); + $identity1 = $this->createMock('UnicaenAuth\Entity\Db\User'/*, ['getRoles', 'getUsername']*/); $identity1->expects($this->once()) ->method('getRoles') ->will($this->returnValue([$role])); @@ -28,7 +28,7 @@ class DbTest extends BaseTest $role2 = new \UnicaenAuth\Entity\Db\Role(); $role2->setRoleId('role id 2'); - $identity2 = $this->getMock('UnicaenAuth\Entity\Db\User', ['getRoles', 'getUsername']); + $identity2 = $this->createMock('UnicaenAuth\Entity\Db\User'/*, ['getRoles', 'getUsername']*/); $identity2->expects($this->once()) ->method('getRoles') ->will($this->returnValue([$role])); diff --git a/tests/UnicaenAuthTest/Provider/Identity/LdapTest.php b/tests/UnicaenAuthTest/Provider/Identity/LdapTest.php index 13983418ae26c4da0c4b52167cd8fd0fdf7481af..c7da678f1cc218283c876d2bc09c2cbc41566cd7 100644 --- a/tests/UnicaenAuthTest/Provider/Identity/LdapTest.php +++ b/tests/UnicaenAuthTest/Provider/Identity/LdapTest.php @@ -19,12 +19,12 @@ class LdapTest extends BaseTest { parent::setUp(); - $this->mapper = $this->getMock('UnicaenApp\Mapper\Ldap\Db', ['findOneByDn']); + $this->mapper = $this->createMock('UnicaenApp\Mapper\Ldap\Db'/*, ['findOneByDn']*/); } public function provideAuthServiceIdentity() { - $identity1 = $this->getMock('UnicaenAuth\Entity\Ldap\People', ['getRoles', 'getUsername']); + $identity1 = $this->createMock('UnicaenAuth\Entity\Ldap\People'/*, ['getRoles', 'getUsername']*/); $identity1->expects($this->once()) ->method('getRoles') ->will($this->returnValue(['cn=admin_reseau,ou=groups,dc=unicaen,dc=fr'])); @@ -34,7 +34,7 @@ class LdapTest extends BaseTest $expectedRoles1 = ['cn=admin_reseau,ou=groups,dc=unicaen,dc=fr', 'username1']; - $identity2 = $this->getMock('UnicaenAuth\Entity\Ldap\People', ['getRoles', 'getUsername']); + $identity2 = $this->createMock('UnicaenAuth\Entity\Ldap\People'/*, ['getRoles', 'getUsername']*/); $identity2->expects($this->once()) ->method('getRoles') ->will($this->returnValue(['cn=admin_reseau,ou=groups,dc=unicaen,dc=fr'])); diff --git a/tests/UnicaenAuthTest/Provider/Role/BaseServiceFactoryTest.php b/tests/UnicaenAuthTest/Provider/Role/BaseServiceFactoryTest.php index 11435df23380cf5e1e2a31767d7465fdc3952979..f60d335680ae75b1b2d82b8cd9837189d6056a26 100644 --- a/tests/UnicaenAuthTest/Provider/Role/BaseServiceFactoryTest.php +++ b/tests/UnicaenAuthTest/Provider/Role/BaseServiceFactoryTest.php @@ -23,6 +23,6 @@ abstract class BaseServiceFactoryTest extends TestCase protected function setUp() { $this->factory = new $this->factoryClass(); - $this->serviceLocator = $this->getMock('Zend\ServiceManager\ServiceLocatorInterface', []); + $this->serviceLocator = $this->createMock('Zend\ServiceManager\ServiceLocatorInterface'/*, []*/); } } \ No newline at end of file diff --git a/tests/UnicaenAuthTest/Provider/Role/ConfigServiceFactoryTest.php b/tests/UnicaenAuthTest/Provider/Role/ConfigServiceFactoryTest.php index 50738bb54d280c6306ea3b359426208f6dfc061b..8972ae1355a1a54da5acf11ece6c82f305edbeb3 100644 --- a/tests/UnicaenAuthTest/Provider/Role/ConfigServiceFactoryTest.php +++ b/tests/UnicaenAuthTest/Provider/Role/ConfigServiceFactoryTest.php @@ -21,7 +21,7 @@ class ConfigServiceFactoryTest extends BaseServiceFactoryTest { parent::setUp(); - $this->mapper = $this->getMock('UnicaenApp\Mapper\Ldap\Group', []); + $this->mapper = $this->createMock('UnicaenApp\Mapper\Ldap\Group'/*, []*/); } public function provideInvalidOptions() @@ -45,7 +45,7 @@ class ConfigServiceFactoryTest extends BaseServiceFactoryTest ->with('BjyAuthorize\Config') ->will($this->returnValue($options)); - $this->factory->createService($this->serviceLocator); + $this->factory->__invoke($this->serviceLocator, ''); } public function testCanCreateService() @@ -63,7 +63,7 @@ class ConfigServiceFactoryTest extends BaseServiceFactoryTest ->method('get') ->will($this->returnValueMap($map)); - $service = $this->factory->createService($this->serviceLocator); + $service = $this->factory->__invoke($this->serviceLocator, ''); $this->assertInstanceOf('UnicaenAuth\Provider\Role\Config', $service); } diff --git a/tests/UnicaenAuthTest/Provider/Role/ConfigTest.php b/tests/UnicaenAuthTest/Provider/Role/ConfigTest.php index 0b019efb886ebb81ea360d9ca25a96a4271b044e..1da8ac9c767de1da331658e05003e006c4e958bf 100644 --- a/tests/UnicaenAuthTest/Provider/Role/ConfigTest.php +++ b/tests/UnicaenAuthTest/Provider/Role/ConfigTest.php @@ -17,7 +17,7 @@ class ConfigTest extends TestCase protected function setUp() { - $this->mapper = $this->getMock('UnicaenApp\Mapper\Ldap\Group', ['findOneByDn']); + $this->mapper = $this->createMock('UnicaenApp\Mapper\Ldap\Group'/*, ['findOneByDn']*/); } public function testLoadingRolesWithoutLdapDnCreatesNamedRoles() diff --git a/tests/UnicaenAuthTest/Provider/Role/DbServiceFactoryTest.php b/tests/UnicaenAuthTest/Provider/Role/DbServiceFactoryTest.php index 051a31944e6e51ff891558e40b6efa4042367adc..a9c99b88bc273ffc40a3c228bd78139da7d6434d 100644 --- a/tests/UnicaenAuthTest/Provider/Role/DbServiceFactoryTest.php +++ b/tests/UnicaenAuthTest/Provider/Role/DbServiceFactoryTest.php @@ -35,7 +35,7 @@ class DbServiceFactoryTest extends BaseServiceFactoryTest ->with('BjyAuthorize\Config') ->will($this->returnValue($options)); - $this->factory->createService($this->serviceLocator); + $this->factory->__invoke($this->serviceLocator, ''); } public function testCanCreateService() @@ -52,7 +52,7 @@ class DbServiceFactoryTest extends BaseServiceFactoryTest $objectManager = $this->getMockForAbstractClass('Doctrine\Common\Persistence\ObjectManager', ['getRepository']); $objectManager->expects($this->once()) ->method('getRepository') - ->will($this->returnValue($this->getMock('Doctrine\Common\Persistence\ObjectRepository', []))); + ->will($this->returnValue($this->createMock('Doctrine\Common\Persistence\ObjectRepository'/*, []*/))); $map = [ ['BjyAuthorize\Config', $options], @@ -62,7 +62,7 @@ class DbServiceFactoryTest extends BaseServiceFactoryTest ->method('get') ->will($this->returnValueMap($map)); - $service = $this->factory->createService($this->serviceLocator); + $service = $this->factory->__invoke($this->serviceLocator, ''); $this->assertInstanceOf('UnicaenAuth\Provider\Role\DbRole', $service); } diff --git a/tests/UnicaenAuthTest/Provider/Role/DbTest.php b/tests/UnicaenAuthTest/Provider/Role/DbTest.php index 63a020694e2d0a542b19674f48e7ae254cb94ad2..2be58dda2227a9c4c779cf10449ca63fa7ae10ca 100644 --- a/tests/UnicaenAuthTest/Provider/Role/DbTest.php +++ b/tests/UnicaenAuthTest/Provider/Role/DbTest.php @@ -18,7 +18,7 @@ class DbTest extends TestCase protected function setUp() { - $this->objectRepository = $this->getMock('Doctrine\Common\Persistence\ObjectRepository', []); + $this->objectRepository = $this->createMock('Doctrine\Common\Persistence\ObjectRepository'/*, []*/); $this->provider = new DbRole($this->objectRepository); } diff --git a/tests/UnicaenAuthTest/Service/UserTest.php b/tests/UnicaenAuthTest/Service/UserTest.php index 7df3d1ecc00c272a3a17444f9132b5c77e48cd6f..2b4a57f00782e3407f8b18d4052bd7e1eee73bb7 100644 --- a/tests/UnicaenAuthTest/Service/UserTest.php +++ b/tests/UnicaenAuthTest/Service/UserTest.php @@ -1,7 +1,7 @@ <?php namespace UnicaenAuthTest\Service; -use PHPUnit\Framework\TestCase; +use PHPUnit_Framework_TestCase; use UnicaenApp\Entity\Ldap\People as LdapPeopleEntity; use UnicaenAppTest\Entity\Ldap\TestAsset\People as LdapPeopleTestAsset; use UnicaenAuth\Service\User; @@ -12,9 +12,13 @@ use ZfcUser\Authentication\Adapter\AdapterChainEvent; * * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> */ -class UserTest extends TestCase +class UserTest extends PHPUnit_Framework_TestCase { + /** + * @var User + */ protected $service; + protected $authModuleOptions; protected $zfcMapper; protected $mapper; @@ -27,11 +31,11 @@ class UserTest extends TestCase // 'usurpation_allowed_usernames' => array('usurpateur'), ]); - $this->zfcMapper = $zfcMapper = $this->getMock('ZfcUser\Mapper\User', ['findByUsername', 'insert', 'update']); + $this->zfcMapper = $zfcMapper = $this->createMock('ZfcUser\Mapper\User'/*, ['findByUsername', 'insert', 'update']*/); - $this->mapper = $mapper = $this->getMock('UnicaenApp\Mapper\Ldap\People', ['findOneByUsername']); + $this->mapper = $mapper = $this->createMock('UnicaenApp\Mapper\Ldap\People'/*, ['findOneByUsername']*/); - $serviceManager = $this->getMock('Zend\ServiceManager\ServiceManager', ['get']); + $serviceManager = $this->createMock('Zend\ServiceManager\ServiceManager'/*, ['get']*/); $serviceManager->expects($this->any()) ->method('get') ->will($this->returnCallback(function($serviceName) use ($authModuleOptions, $zfcMapper, $mapper) { @@ -98,7 +102,7 @@ class UserTest extends TestCase } /** - * @expectedException \UnicaenApp\Exception + * @expectedException \UnicaenApp\Exception\RuntimeException */ public function testEntryPointThrowsExceptionIfUnexpectedNonEmptyIdentitySpecifiedInEvent() { @@ -116,7 +120,7 @@ class UserTest extends TestCase } /** - * @expectedException \UnicaenApp\Exception + * @expectedException \UnicaenApp\Exception\RuntimeException */ public function testEntryPointThrowsExceptionIfPDOExceptionThrownDuringFetch() { @@ -170,7 +174,7 @@ class UserTest extends TestCase } /** - * @expectedException \UnicaenApp\Exception + * @expectedException \UnicaenApp\Exception\RuntimeException */ public function testEntryPointThrowsExceptionIfPDOExceptionThrownDuringSave() { diff --git a/tests/UnicaenAuthTest/View/Helper/AppConnectionTest.php b/tests/UnicaenAuthTest/View/Helper/AppConnectionTest.php index f8d45dd4c5813222580e4458e96fc2e9f58853d0..49c574b584b0bae7073bdc430f12b7715facf38a 100644 --- a/tests/UnicaenAuthTest/View/Helper/AppConnectionTest.php +++ b/tests/UnicaenAuthTest/View/Helper/AppConnectionTest.php @@ -25,7 +25,7 @@ class AppConnectionTest extends AbstractTest { parent::setUp(); - $this->renderer = $this->getMock('Zend\View\Renderer\PhpRenderer', ['plugin']); + $this->renderer = $this->createMock('Zend\View\Renderer\PhpRenderer'/*, ['plugin']*/); $this->helper->setView($this->renderer); } @@ -33,7 +33,7 @@ class AppConnectionTest extends AbstractTest protected function getUserCurrentHelper() { if (null === $this->userCurrentHelper) { - $this->userCurrentHelper = $this->getMock('UnicaenAuth\View\Helper\UserCurrent', ['__toString']); + $this->userCurrentHelper = $this->createMock('UnicaenAuth\View\Helper\UserCurrent'/*, ['__toString']*/); $this->userCurrentHelper ->expects($this->any()) ->method('__toString') @@ -45,7 +45,7 @@ class AppConnectionTest extends AbstractTest protected function getUserConnectionHelper() { if (null === $this->userConnectionHelper) { - $this->userConnectionHelper = $this->getMock('UnicaenAuth\View\Helper\UserConnection', ['__toString']); + $this->userConnectionHelper = $this->createMock('UnicaenAuth\View\Helper\UserConnection'/*, ['__toString']*/); $this->userConnectionHelper ->expects($this->any()) ->method('__toString') diff --git a/tests/UnicaenAuthTest/View/Helper/UserAbstractTest.php b/tests/UnicaenAuthTest/View/Helper/UserAbstractTest.php index 5e72ace5d1f847ebef2fb6556a9f1d9bfba11683..80f089e223016cecc4db2d6a5664c09611e808d0 100644 --- a/tests/UnicaenAuthTest/View/Helper/UserAbstractTest.php +++ b/tests/UnicaenAuthTest/View/Helper/UserAbstractTest.php @@ -1,7 +1,7 @@ <?php namespace UnicaenAuthTest\View\Helper; -use PHPUnit\Framework\TestCase; +use PHPUnit_Framework_TestCase; use UnicaenAuth\View\Helper\UserAbstract; /** @@ -10,7 +10,7 @@ use UnicaenAuth\View\Helper\UserAbstract; * @property UserAbstract $helper Description * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> */ -class UserAbstractTest extends TestCase +class UserAbstractTest extends PHPUnit_Framework_TestCase { protected $helper; protected $authService; @@ -21,7 +21,7 @@ class UserAbstractTest extends TestCase */ protected function setUp() { - $this->authService = $this->getMock('Zend\Authentication\AuthenticationService', ['hasIdentity', 'getIdentity']); + $this->authService = $this->createMock('Zend\Authentication\AuthenticationService'/*, ['hasIdentity', 'getIdentity']*/); $this->helper = $this->getMockForAbstractClass('UnicaenAuth\View\Helper\UserAbstract'); $this->helper->setAuthService($this->authService); diff --git a/tests/UnicaenAuthTest/View/Helper/UserConnectionFactoryTest.php b/tests/UnicaenAuthTest/View/Helper/UserConnectionFactoryTest.php index e63059c6222ebf6a1307b2e41b5b6eb830ba7b57..6bc518a1e0a22fe9783a05fda17b703043b63df5 100644 --- a/tests/UnicaenAuthTest/View/Helper/UserConnectionFactoryTest.php +++ b/tests/UnicaenAuthTest/View/Helper/UserConnectionFactoryTest.php @@ -16,14 +16,14 @@ class UserConnectionFactoryTest extends BaseServiceFactoryTest public function testCanCreateService() { - $authService = $this->getMock('Zend\Authentication\AuthenticationService', []); + $authService = $this->createMock('Zend\Authentication\AuthenticationService'); $this->serviceManager->expects($this->once()) ->method('get') ->with('zfcuser_auth_service') ->will($this->returnValue($authService)); - $service = $this->factory->createService($this->pluginManager); + $service = $this->factory->__invoke($this->serviceManager, ''); $this->assertInstanceOf($this->serviceClass, $service); } diff --git a/tests/UnicaenAuthTest/View/Helper/UserConnectionTest.php b/tests/UnicaenAuthTest/View/Helper/UserConnectionTest.php index 777a87f750c8811cf40a88e6e9d50fdfb7491452..9683566755a1e3e090206299e15c647a0751c812 100644 --- a/tests/UnicaenAuthTest/View/Helper/UserConnectionTest.php +++ b/tests/UnicaenAuthTest/View/Helper/UserConnectionTest.php @@ -26,15 +26,15 @@ class UserConnectionTest extends AbstractTest { parent::setUp(); - $this->urlHelper = $this->getMock('Zend\View\Helper\Url', ['__invoke']); + $this->urlHelper = $this->createMock('Zend\View\Helper\Url'/*, ['__invoke']*/); - $this->renderer = $this->getMock('Zend\View\Renderer\PhpRenderer', ['plugin']); + $this->renderer = $this->createMock('Zend\View\Renderer\PhpRenderer'/*, ['plugin']*/); $this->renderer->expects($this->any()) ->method('plugin') ->with('url') ->will($this->returnValue($this->urlHelper)); - $this->authService = $this->getMock('Zend\Authentication\AuthenticationService', ['hasIdentity', 'getIdentity']); + $this->authService = $this->createMock('Zend\Authentication\AuthenticationService'/*, ['hasIdentity', 'getIdentity']*/); $this->helper->setAuthService($this->authService) ->setView($this->renderer) diff --git a/tests/UnicaenAuthTest/View/Helper/UserCurrentFactoryTest.php b/tests/UnicaenAuthTest/View/Helper/UserCurrentFactoryTest.php index 6ec97961302d36ce4554357050940d47576d346c..c7690ffbef66a6f8304cfa3e245b88d1c4ee0b10 100644 --- a/tests/UnicaenAuthTest/View/Helper/UserCurrentFactoryTest.php +++ b/tests/UnicaenAuthTest/View/Helper/UserCurrentFactoryTest.php @@ -16,14 +16,14 @@ class UserCurrentFactoryTest extends BaseServiceFactoryTest public function testCanCreateService() { - $authService = $this->getMock('Zend\Authentication\AuthenticationService', []); + $authService = $this->createMock('Zend\Authentication\AuthenticationService'); $this->serviceManager->expects($this->once()) ->method('get') ->with('zfcuser_auth_service') ->will($this->returnValue($authService)); - $service = $this->factory->createService($this->pluginManager); + $service = $this->factory->__invoke($this->serviceManager, ''); $this->assertInstanceOf($this->serviceClass, $service); } diff --git a/tests/UnicaenAuthTest/View/Helper/UserCurrentTest.php b/tests/UnicaenAuthTest/View/Helper/UserCurrentTest.php index 6815ce774393c1ec2d80029bb7d04f93f2a660e6..7b01e0b1aece455ad61d64685a9d69146d299a1d 100644 --- a/tests/UnicaenAuthTest/View/Helper/UserCurrentTest.php +++ b/tests/UnicaenAuthTest/View/Helper/UserCurrentTest.php @@ -1,9 +1,18 @@ <?php + namespace UnicaenAuthTest\View\Helper; +use BjyAuthorize\Acl\Role; +use PHPUnit_Framework_MockObject_MockObject; use UnicaenAppTest\View\Helper\TestAsset\ArrayTranslatorLoader; +use UnicaenAuth\Service\UserContext; use UnicaenAuth\View\Helper\UserCurrent; +use UnicaenAuth\View\Helper\UserInfo; +use UnicaenAuth\View\Helper\UserProfile; +use UnicaenAuth\View\Helper\UserStatus; use Zend\I18n\Translator\Translator; +use Zend\View\Helper\InlineScript; +use Zend\View\Renderer\PhpRenderer; /** * Description of UserCurrentTest @@ -13,12 +22,22 @@ use Zend\I18n\Translator\Translator; */ class UserCurrentTest extends AbstractTest { - protected $helperClass = 'UnicaenAuth\View\Helper\UserCurrent'; + protected $helperClass = UserCurrent::class; + + /** + * @var PhpRenderer|PHPUnit_Framework_MockObject_MockObject + */ protected $renderer; - protected $authService; + + /** + * @var UserContext|PHPUnit_Framework_MockObject_MockObject + */ + protected $userContext; + protected $userStatusHelper; protected $userProfileHelper; protected $userInfoHelper; + protected $inlineScriptHelper; /** * Sets up the fixture, for example, open a network connection. @@ -28,10 +47,10 @@ class UserCurrentTest extends AbstractTest { parent::setUp(); - $this->userStatusHelper = $userStatusHelper = $this->getMock('UnicaenAuth\View\Helper\UserStatus', ['__invoke']); - $this->userProfileHelper = $userProfileHelper = $this->getMock('UnicaenAuth\View\Helper\UserProfile', ['__toString']); - $this->userInfoHelper = $userInfoHelper = $this->getMock('UnicaenAuth\View\Helper\UserInfo', ['__invoke']); - $this->inlineScriptHelper = $inlineScriptHelper = $this->getMock('Zend\View\Helper\InlineScript', ['__invoke']); + $this->userStatusHelper = $userStatusHelper = $this->createMock(UserStatus::class/*, ['__invoke']*/); + $this->userProfileHelper = $userProfileHelper = $this->createMock(UserProfile::class/*, ['__toString']*/); + $this->userInfoHelper = $userInfoHelper = $this->createMock(UserInfo::class/*, ['__invoke']*/); + $this->inlineScriptHelper = $inlineScriptHelper = $this->createMock(InlineScript::class/*, ['__invoke']*/); $this->userStatusHelper ->expects($this->any()) @@ -50,7 +69,7 @@ class UserCurrentTest extends AbstractTest ->method('__invoke') ->will($this->returnValue('InlineScript Helper Markup')); - $this->renderer = $this->getMock('Zend\View\Renderer\PhpRenderer', ['plugin']); + $this->renderer = $this->createMock(PhpRenderer::class/*, ['plugin']*/); $this->renderer->expects($this->any()) ->method('plugin') ->will($this->returnCallback(function ($helper) use ($userStatusHelper, $userProfileHelper, $userInfoHelper, $inlineScriptHelper) { @@ -69,17 +88,18 @@ class UserCurrentTest extends AbstractTest return null; })); - $this->authService = $this->getMock('Zend\Authentication\AuthenticationService', ['hasIdentity', 'getIdentity']); + $this->userContext = $this->createMock(UserContext::class/*, ['hasIdentity', 'getIdentity']*/); - $this->helper->setAuthService($this->authService) - ->setView($this->renderer) - ->setTranslator(new Translator()); + $this->helper + ->setUserContext($this->userContext) + ->setTranslator(new Translator()) + ->setView($this->renderer); } - public function testCanConstructWithAuthService() + public function testCanConstructWithUserContextService() { - $helper = new UserCurrent($this->authService); - $this->assertSame($this->authService, $helper->getAuthService()); + $helper = new UserCurrent($this->userContext); + $this->assertSame($this->userContext, $helper->getUserContext()); } public function testEntryPointReturnsSelfInstance() @@ -95,34 +115,35 @@ class UserCurrentTest extends AbstractTest public function testCanRenderIfNoIdentityAvailable() { - $this->authService->expects($this->any()) - ->method('hasIdentity') - ->will($this->returnValue(false)); + $this->userContext->expects($this->any()) + ->method('getIdentity') + ->willReturn(false); - $markup = (string) $this->helper; + $markup = $this->helper->__toString(); $this->assertEquals($this->getExpected('user_current/logged-out.phtml'), $markup); // traduction $this->helper->setTranslator($this->_getTranslator()); - $markup = (string) $this->helper; + $markup = $this->helper->__toString(); $this->assertEquals($this->getExpected('user_current/logged-out-translated.phtml'), $markup); } public function testCanRenderLogoutLinkIfIdentityAvailable() { - $this->authService->expects($this->any()) - ->method('hasIdentity') - ->will($this->returnValue(true)); - $this->authService->expects($this->any()) + $this->userContext + ->expects($this->once()) + ->method('getSelectedIdentityRole') + ->willReturn($role = new Role('role id')); + $this->userContext->expects($this->once()) ->method('getIdentity') - ->will($this->returnValue($identity = 'Auth Service Identity')); + ->willReturn($identity = 'Auth Service Identity'); - $markup = (string) $this->helper; + $markup = $this->helper->__toString(); $this->assertEquals($this->getExpected('user_current/logged-in.phtml'), $markup); // traduction $this->helper->setTranslator($this->_getTranslator()); - $markup = (string) $this->helper; + $markup = $this->helper->__toString(); $this->assertEquals($this->getExpected('user_current/logged-in-translated.phtml'), $markup); } diff --git a/tests/UnicaenAuthTest/View/Helper/UserInfoFactoryTest.php b/tests/UnicaenAuthTest/View/Helper/UserInfoFactoryTest.php index 9e8edfe85a46bcbb3ec40d4e50e8a61a02270cd6..887ae0b9ad3648d5a9b86d57fe1ac16923302715 100644 --- a/tests/UnicaenAuthTest/View/Helper/UserInfoFactoryTest.php +++ b/tests/UnicaenAuthTest/View/Helper/UserInfoFactoryTest.php @@ -16,8 +16,8 @@ class UserInfoFactoryTest extends BaseServiceFactoryTest public function testCanCreateService() { - $authService = $this->getMock('Zend\Authentication\AuthenticationService', []); - $mapper = $this->getMock('UnicaenApp\Mapper\Ldap\Structure', []); + $authService = $this->createMock('Zend\Authentication\AuthenticationService'); + $mapper = $this->createMock('UnicaenApp\Mapper\Ldap\Structure'); $this->serviceManager->expects($this->exactly(2)) ->method('get') @@ -25,7 +25,7 @@ class UserInfoFactoryTest extends BaseServiceFactoryTest ['zfcuser_auth_service', $authService], ['ldap_structure_mapper', $mapper]])); - $service = $this->factory->createService($this->pluginManager); + $service = $this->factory->__invoke($this->serviceManager, ''); $this->assertInstanceOf($this->serviceClass, $service); $this->assertSame($mapper, $service->getMapperStructure()); diff --git a/tests/UnicaenAuthTest/View/Helper/UserInfoTest.php b/tests/UnicaenAuthTest/View/Helper/UserInfoTest.php index f91f80d6d63624fcc927c0c02c9d64adad2510f8..5ddc757fcc3d2982a711215fec59ec9fbf9c3209 100644 --- a/tests/UnicaenAuthTest/View/Helper/UserInfoTest.php +++ b/tests/UnicaenAuthTest/View/Helper/UserInfoTest.php @@ -26,10 +26,10 @@ class UserInfoTest extends AbstractTest { parent::setUp(); - $this->authService = $this->getMock('Zend\Authentication\AuthenticationService', ['hasIdentity', 'getIdentity']); + $this->authService = $this->createMock('Zend\Authentication\AuthenticationService'/*, ['hasIdentity', 'getIdentity']*/); - $this->mapperStructure = $this->getMock('UnicaenApp\Mapper\Ldap\Structure', - ['findOneByDn', 'findOnePathByCodeStructure', 'findAllPathByCodeStructure', 'findOneByCodeEntite']); + $this->mapperStructure = $this->createMock('UnicaenApp\Mapper\Ldap\Structure'/*, + ['findOneByDn', 'findOnePathByCodeStructure', 'findAllPathByCodeStructure', 'findOneByCodeEntite']*/); $this->helper->setMapperStructure($this->mapperStructure) ->setAuthService($this->authService) @@ -158,12 +158,12 @@ class UserInfoTest extends AbstractTest $expectedScript, $expectedScriptTranslated) { - $identity = $this->getMock( - 'UnicaenApp\Entity\Ldap\People', + $identity = $this->createMock( + 'UnicaenApp\Entity\Ldap\People'/*, ['getAffectationsAdmin', 'getAffectationsRecherche', 'getFonctionsStructurelles'], [], '', - false); + false*/); $identity->expects($this->any()) ->method('getAffectationsAdmin') ->will($this->returnValue($affectationsAdmin)); diff --git a/tests/UnicaenAuthTest/View/Helper/UserProfileFactoryTest.php b/tests/UnicaenAuthTest/View/Helper/UserProfileFactoryTest.php index 307be516b275899b533ad6c62df9bdb1a7d1ab61..049ba254da7e19d01ff913dfd0d5f0d1c4a81f9b 100644 --- a/tests/UnicaenAuthTest/View/Helper/UserProfileFactoryTest.php +++ b/tests/UnicaenAuthTest/View/Helper/UserProfileFactoryTest.php @@ -16,8 +16,8 @@ class UserProfileFactoryTest extends BaseServiceFactoryTest public function testCanCreateService() { - $authService = $this->getMock('Zend\Authentication\AuthenticationService', []); - $authorize = $this->getMock('BjyAuthorize\Service\Authorize', ['getIdentityProvider'], [], '', false); + $authService = $this->createMock('Zend\Authentication\AuthenticationService'); + $authorize = $this->createMock('BjyAuthorize\Service\Authorize'/*, ['getIdentityProvider'], [], '', false*/); $identityProvider = $this->getMockForAbstractClass('BjyAuthorize\Provider\Identity\ProviderInterface', []); $authorize->expects($this->once()) @@ -30,9 +30,8 @@ class UserProfileFactoryTest extends BaseServiceFactoryTest ['zfcuser_auth_service', $authService], ['BjyAuthorize\Service\Authorize', $authorize]])); - $service = $this->factory->createService($this->pluginManager); + $service = $this->factory->__invoke($this->serviceManager, ''); $this->assertInstanceOf($this->serviceClass, $service); - $this->assertSame($identityProvider, $service->getIdentityProvider()); } } \ No newline at end of file diff --git a/tests/UnicaenAuthTest/View/Helper/UserStatusFactoryTest.php b/tests/UnicaenAuthTest/View/Helper/UserStatusFactoryTest.php index 49615373eb8df5680898a514c17c3176ec062418..a1b53d6f1843a97fbe47ac2c424906d9f9d9aa8b 100644 --- a/tests/UnicaenAuthTest/View/Helper/UserStatusFactoryTest.php +++ b/tests/UnicaenAuthTest/View/Helper/UserStatusFactoryTest.php @@ -16,14 +16,14 @@ class UserStatusFactoryTest extends BaseServiceFactoryTest public function testCanCreateService() { - $authService = $this->getMock('Zend\Authentication\AuthenticationService', []); + $authService = $this->createMock('Zend\Authentication\AuthenticationService'); $this->serviceManager->expects($this->once()) ->method('get') ->with('zfcuser_auth_service') ->will($this->returnValue($authService)); - $service = $this->factory->createService($this->pluginManager); + $service = $this->factory->__invoke($this->serviceManager, ''); $this->assertInstanceOf($this->serviceClass, $service); } diff --git a/tests/UnicaenAuthTest/View/Helper/UserStatusTest.php b/tests/UnicaenAuthTest/View/Helper/UserStatusTest.php index 3cec962f1dea7d96a0c4f8651e24937422456363..3e2757e96be8a8bed8069a3bcf07de7ee0958b08 100644 --- a/tests/UnicaenAuthTest/View/Helper/UserStatusTest.php +++ b/tests/UnicaenAuthTest/View/Helper/UserStatusTest.php @@ -1,9 +1,9 @@ <?php + namespace UnicaenAuthTest\View\Helper; -use UnicaenApp\Entity\Ldap\People as LdapPeopleEntity; -use UnicaenAppTest\Entity\Ldap\TestAsset\People as LdapPeopleTestAsset; use UnicaenAppTest\View\Helper\TestAsset\ArrayTranslatorLoader; +use UnicaenAuth\Service\UserContext; use UnicaenAuth\View\Helper\UserStatus; use Zend\I18n\Translator\Translator; @@ -15,6 +15,11 @@ use Zend\I18n\Translator\Translator; */ class UserStatusTest extends AbstractTest { + /** + * @var UserContext|\PHPUnit_Framework_MockObject_MockObject + */ + protected $userContext; + protected $helperClass = 'UnicaenAuth\View\Helper\UserStatus'; /** @@ -25,9 +30,9 @@ class UserStatusTest extends AbstractTest { parent::setUp(); - $this->authService = $this->getMock('Zend\Authentication\AuthenticationService', ['hasIdentity', 'getIdentity']); + $this->userContext = $this->createMock(UserContext::class/*, ['hasIdentity', 'getIdentity']*/); - $userConnectionHelper = $this->getMock('UnicaenAuth\View\Helper\UserConnection', ['__toString']); + $userConnectionHelper = $this->createMock('UnicaenAuth\View\Helper\UserConnection'/*, ['__toString']*/); $userConnectionHelper->expects($this->any()) ->method('__toString') ->will($this->returnValue('UserConnection Helper Markup')); @@ -35,7 +40,7 @@ class UserStatusTest extends AbstractTest $this->helper->getView()->getHelperPluginManager()->setService('userConnection', $userConnectionHelper); $this->helper->setDisplayConnectionLink() - ->setAuthService($this->authService); + ->setUserContext($this->userContext); } public function testEntryPointReturnsSelfInstance() @@ -51,7 +56,7 @@ class UserStatusTest extends AbstractTest public function testRenderingWithoutConnectionLinkReturnsNoneIfNoIdentityAvailable() { - $this->authService->expects($this->any()) + $this->userContext->expects($this->any()) ->method('hasIdentity') ->will($this->returnValue(false)); @@ -106,10 +111,10 @@ class UserStatusTest extends AbstractTest $identity, $expectedScriptWithoutLink) { - $this->authService->expects($this->any()) + $this->userContext->expects($this->any()) ->method('hasIdentity') ->will($this->returnValue(true)); - $this->authService->expects($this->any()) + $this->userContext->expects($this->any()) ->method('getIdentity') ->will($this->returnValue($identity)); @@ -121,7 +126,7 @@ class UserStatusTest extends AbstractTest public function testRenderingWithConnectionLinkReturnsNoneIfNoIdentityAvailable() { - $this->authService->expects($this->any()) + $this->userContext->expects($this->any()) ->method('hasIdentity') ->will($this->returnValue(false)); @@ -147,10 +152,10 @@ class UserStatusTest extends AbstractTest $expectedScriptWithoutLink, $expectedScriptWithLink) { - $this->authService->expects($this->any()) + $this->userContext->expects($this->any()) ->method('hasIdentity') ->will($this->returnValue(true)); - $this->authService->expects($this->any()) + $this->userContext->expects($this->any()) ->method('getIdentity') ->will($this->returnValue($identity)); diff --git a/tests/phpunit.xml b/tests/phpunit.xml new file mode 100644 index 0000000000000000000000000000000000000000..5532f7db65bd66b955cdb1641b399fc7e92f1071 --- /dev/null +++ b/tests/phpunit.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<phpunit bootstrap="./Bootstrap.php" colors="true"> + <testsuites> + <testsuite name="unit"> + <directory>./UnicaenAuthTest</directory> + </testsuite> + <testsuite name="functional"> + <directory>./functional</directory> + </testsuite> + </testsuites> + + <logging> + <!--<log type="junit" target="/tmp/phpunit/logs/junit.xml" />--> + <!--<log type="coverage-clover" target="/tmp/phpunit/logs/clover.xml" />--> + <!--<log type="coverage-html" target="/tmp/phpunit/coverage" />--> + </logging> + + <filter> + <whitelist processUncoveredFilesFromWhitelist="true"> + <directory suffix=".php">../src</directory> + </whitelist> + </filter> + + <!-- + <groups> + <exclude> + <group>disable</group> + <group>integration</group> + <group>integration-sqlserver</group> + </exclude> + </groups> + --> + + <php> + <!-- Integration Test Variables --> + <const name="HOST" value="localhost"/> + <const name="PORT" value="4444"/> + <const name="BROWSER_URL" value="http://localhost/snortlog/"/> <!-- '/' requis à la fin! --> + <const name="CAS_URL" value="https://cas.unicaen.fr/"/> <!-- '/' requis à la fin! --> + <const name="USERNAME" value="21009539"/> + <const name="PASSWORD" value="UCBN2010"/> + </php> + +</phpunit>