diff --git a/.gitignore b/.gitignore index 0315e54..bef7b9a 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ vendor/* #ignoring NetBeans project files /nbproject .phpunit.result.cache +/build diff --git a/build/.gitignore b/build/.gitignore deleted file mode 100644 index 6d8e8bf..0000000 --- a/build/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -* -!logs -!.gitignore -!coverage-checker.php \ No newline at end of file diff --git a/build/logs/.gitignore b/build/logs/.gitignore deleted file mode 100644 index c96a04f..0000000 --- a/build/logs/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore \ No newline at end of file diff --git a/composer.json b/composer.json index 1d9dec3..5b9830b 100644 --- a/composer.json +++ b/composer.json @@ -78,6 +78,7 @@ "cs-check": "phpcs", "cs-fix": "phpcbf", "test": "phpunit --colors=always", - "test-coverage": "phpunit --colors=always --coverage-clover clover.xml" + "test-coverage": "phpunit --colors=always --coverage-clover clover.xml", + "test-coverage-html": "phpunit --coverage-html ./build/html" } } diff --git a/src/Authentication/Adapter/AdapterChain.php b/src/Authentication/Adapter/AdapterChain.php index a4c250e..9feaad6 100644 --- a/src/Authentication/Adapter/AdapterChain.php +++ b/src/Authentication/Adapter/AdapterChain.php @@ -105,6 +105,9 @@ public function resetAdapters() } } } + $event = $this->getEvent(); + $event->setName('reset'); + $this->getEventManager()->triggerEvent($event); return $this; } diff --git a/src/Authentication/Adapter/AdapterChainServiceFactory.php b/src/Authentication/Adapter/AdapterChainServiceFactory.php index a473e14..cdeae6a 100644 --- a/src/Authentication/Adapter/AdapterChainServiceFactory.php +++ b/src/Authentication/Adapter/AdapterChainServiceFactory.php @@ -27,6 +27,10 @@ public function __invoke(ContainerInterface $serviceLocator, $requestedName, arr if (is_callable(array($adapter, 'logout'))) { $chain->getEventManager()->attach('logout', array($adapter, 'logout'), $priority); } + + if (is_callable(array($adapter, 'reset'))) { + $chain->getEventManager()->attach('reset', array($adapter, 'reset'), $priority); + } } return $chain; diff --git a/src/Authentication/Adapter/Db.php b/src/Authentication/Adapter/Db.php index a566ff2..a872bde 100644 --- a/src/Authentication/Adapter/Db.php +++ b/src/Authentication/Adapter/Db.php @@ -43,6 +43,17 @@ public function logout(AdapterChainEvent $e) $this->getStorage()->clear(); } + /** + * Called when authentication adapter is reset + * @param AdapterChainEvent $e + * + */ + public function reset(AdapterChainEvent $e): void + { + $this->getStorage()->clear(); + } + + /** * @param AdapterChainEvent $e * @return bool diff --git a/tests/Authentication/Adapter/DbTest.php b/tests/Authentication/Adapter/DbTest.php index dd40307..2b169f0 100644 --- a/tests/Authentication/Adapter/DbTest.php +++ b/tests/Authentication/Adapter/DbTest.php @@ -86,6 +86,16 @@ public function testLogout() $this->db->logout($this->authEvent); } + /** + * @covers \LmcUser\Authentication\Adapter\Db::reset + */ + public function testReset() + { + $this->storage->expects($this->once()) + ->method('clear'); + $this->db->reset($this->authEvent); + } + /** * @covers \LmcUser\Authentication\Adapter\Db::Authenticate */