Implemented check on interface implementation

This commit is contained in:
Joshua Thijssen 2015-01-21 14:17:42 +01:00 committed by Fabien Potencier
parent 3d174a4058
commit 2a79ace826
2 changed files with 16 additions and 0 deletions

View File

@ -48,6 +48,12 @@ class AuthenticationProviderManager implements AuthenticationManagerInterface
throw new \InvalidArgumentException('You must at least add one authentication provider.'); throw new \InvalidArgumentException('You must at least add one authentication provider.');
} }
foreach ($providers as $provider) {
if (!$provider instanceof AuthenticationProviderInterface) {
throw new \InvalidArgumentException(sprintf('Provider "%s" must implement the AuthenticationProviderInterface.', get_class($provider)));
}
}
$this->providers = $providers; $this->providers = $providers;
$this->eraseCredentials = (bool) $eraseCredentials; $this->eraseCredentials = (bool) $eraseCredentials;
} }

View File

@ -27,6 +27,16 @@ class AuthenticationProviderManagerTest extends \PHPUnit_Framework_TestCase
new AuthenticationProviderManager(array()); new AuthenticationProviderManager(array());
} }
/**
* @expectedException \InvalidArgumentException
*/
public function testAuthenticateWithProvidersWithIncorrectInterface()
{
new AuthenticationProviderManager(array(
new \stdClass(),
));
}
public function testAuthenticateWhenNoProviderSupportsToken() public function testAuthenticateWhenNoProviderSupportsToken()
{ {
$manager = new AuthenticationProviderManager(array( $manager = new AuthenticationProviderManager(array(