minor #13482 Implemented check on interface implementation (jaytaph)

This PR was squashed before being merged into the 2.7 branch (closes #13482).

Discussion
----------

Implemented check on interface implementation

| Q             | A
| ------------- | ---
| Bug fix?      | Yes
| New feature?  | No
| BC breaks?    | No
| Deprecations? | No
| Tests pass?   | Yes
| Fixed tickets | #13480
| License       | MIT
| Doc PR        |

Commits
-------

2a79ace Implemented check on interface implementation
This commit is contained in:
Fabien Potencier 2015-03-26 13:47:28 +01:00
commit 1ba939f2e6
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.');
}
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->eraseCredentials = (bool) $eraseCredentials;
}

View File

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