diff --git a/spec/Authentication/BasicAuthSpec.php b/spec/Authentication/BasicAuthSpec.php index 3729191..79aabaf 100644 --- a/spec/Authentication/BasicAuthSpec.php +++ b/spec/Authentication/BasicAuthSpec.php @@ -24,25 +24,11 @@ function it_has_a_username() $this->getUsername()->shouldReturn('john.doe'); } - function it_accepts_a_username() - { - $this->setUsername('jane.doe'); - - $this->getUsername()->shouldReturn('jane.doe'); - } - function it_has_a_password() { $this->getPassword()->shouldReturn('secret'); } - function it_accepts_a_password() - { - $this->setPassword('very_secret'); - - $this->getPassword()->shouldReturn('very_secret'); - } - function it_authenticates_a_request(RequestInterface $request, RequestInterface $newRequest) { $request->withHeader('Authorization', 'Basic '.base64_encode('john.doe:secret'))->willReturn($newRequest); diff --git a/spec/Authentication/BearerSpec.php b/spec/Authentication/BearerSpec.php index e3d2d88..b053bed 100644 --- a/spec/Authentication/BearerSpec.php +++ b/spec/Authentication/BearerSpec.php @@ -24,13 +24,6 @@ function it_has_a_token() $this->getToken()->shouldReturn('token'); } - function it_accepts_a_token() - { - $this->setToken('another_token'); - - $this->getToken()->shouldReturn('another_token'); - } - function it_authenticates_a_request(RequestInterface $request, RequestInterface $newRequest) { $request->withHeader('Authorization', 'Bearer token')->willReturn($newRequest); diff --git a/spec/Authentication/ChainSpec.php b/spec/Authentication/ChainSpec.php index f16938f..aa12747 100644 --- a/spec/Authentication/ChainSpec.php +++ b/spec/Authentication/ChainSpec.php @@ -24,36 +24,11 @@ function it_accepts_an_authentication_chain_in_the_constructor(Authentication $a $this->getAuthenticationChain()->shouldReturn($chain); } - function it_sets_the_authentication_chain(Authentication $auth1, Authentication $auth2) + function it_throws_an_exception_when_non_authentication_is_passed() { - // This SHOULD be replaced - $this->beConstructedWith([$auth1]); + $this->beConstructedWith(['authentication']); - $this->setAuthenticationChain([$auth2]); - - $this->getAuthenticationChain()->shouldReturn([$auth2]); - } - - function it_adds_an_authentication_method(Authentication $auth1, Authentication $auth2) - { - // This SHOULD NOT be replaced - $this->beConstructedWith([$auth1]); - - $this->addAuthentication($auth2); - - $this->getAuthenticationChain()->shouldReturn([$auth1, $auth2]); - } - - function it_clears_the_authentication_chain(Authentication $auth1, Authentication $auth2) - { - // This SHOULD be replaced - $this->beConstructedWith([$auth1]); - - $this->clearAuthenticationChain(); - - $this->addAuthentication($auth2); - - $this->getAuthenticationChain()->shouldReturn([$auth2]); + $this->shouldThrow('InvalidArgumentException')->duringInstantiation(); } function it_authenticates_a_request( diff --git a/spec/Authentication/MatchingSpec.php b/spec/Authentication/MatchingSpec.php index caefda6..33306d7 100644 --- a/spec/Authentication/MatchingSpec.php +++ b/spec/Authentication/MatchingSpec.php @@ -29,27 +29,11 @@ function it_has_an_authentication(Authentication $authentication) $this->getAuthentication()->shouldReturn($authentication); } - function it_accepts_an_authentication(Authentication $anotherAuthentication) - { - $this->setAuthentication($anotherAuthentication); - - $this->getAuthentication()->shouldReturn($anotherAuthentication); - } - function it_has_a_matcher() { $this->getMatcher()->shouldReturn($this->matcher); } - function it_accepts_a_matcher() - { - $matcher = function($request) { return false; }; - - $this->setMatcher($matcher); - - $this->getMatcher()->shouldReturn($matcher); - } - function it_authenticates_a_request(Authentication $authentication, RequestInterface $request, RequestInterface $newRequest) { $authentication->authenticate($request)->willReturn($newRequest); @@ -61,7 +45,7 @@ function it_does_not_authenticate_a_request(Authentication $authentication, Requ { $matcher = function($request) { return false; }; - $this->setMatcher($matcher); + $this->beConstructedWith($authentication, $matcher); $authentication->authenticate($request)->shouldNotBeCalled(); diff --git a/spec/Authentication/WsseSpec.php b/spec/Authentication/WsseSpec.php index 9d511da..4a68521 100644 --- a/spec/Authentication/WsseSpec.php +++ b/spec/Authentication/WsseSpec.php @@ -25,25 +25,11 @@ function it_has_a_username() $this->getUsername()->shouldReturn('john.doe'); } - function it_accepts_a_username() - { - $this->setUsername('jane.doe'); - - $this->getUsername()->shouldReturn('jane.doe'); - } - function it_has_a_password() { $this->getPassword()->shouldReturn('secret'); } - function it_accepts_a_password() - { - $this->setPassword('very_secret'); - - $this->getPassword()->shouldReturn('very_secret'); - } - function it_authenticates_a_request( RequestInterface $request, RequestInterface $newRequest, diff --git a/src/Authentication/Bearer.php b/src/Authentication/Bearer.php index fabcf4b..acd052a 100644 --- a/src/Authentication/Bearer.php +++ b/src/Authentication/Bearer.php @@ -35,16 +35,6 @@ public function getToken() return $this->token; } - /** - * Sets the token. - * - * @param string $token - */ - public function setToken($token) - { - $this->token = $token; - } - /** * {@inheritdoc} */ diff --git a/src/Authentication/Chain.php b/src/Authentication/Chain.php index e5899d1..eeb0745 100644 --- a/src/Authentication/Chain.php +++ b/src/Authentication/Chain.php @@ -22,19 +22,15 @@ final class Chain implements Authentication */ public function __construct(array $authenticationChain = []) { - $this->setAuthenticationChain($authenticationChain); - } + foreach ($authenticationChain as $authentication) { + if (!$authentication instanceof Authentication) { + throw new \InvalidArgumentException( + 'Members of the authentication chain must be of type Http\Message\Authentication' + ); + } + } - /** - * Adds an Authentication method to the chain. - * - * The order of authentication methods SHOULD NOT matter. - * - * @param Authentication $authentication - */ - public function addAuthentication(Authentication $authentication) - { - $this->authenticationChain[] = $authentication; + $this->authenticationChain = $authenticationChain; } /** @@ -47,28 +43,6 @@ public function getAuthenticationChain() return $this->authenticationChain; } - /** - * Replaces the current authentication chain. - * - * @param array $authenticationChain - */ - public function setAuthenticationChain(array $authenticationChain) - { - $this->clearAuthenticationChain(); - - foreach ($authenticationChain as $authentication) { - $this->addAuthentication($authentication); - } - } - - /** - * Clears the authentication chain. - */ - public function clearAuthenticationChain() - { - $this->authenticationChain = []; - } - /** * {@inheritdoc} */ diff --git a/src/Authentication/Matching.php b/src/Authentication/Matching.php index 9502a35..ff9bb9b 100644 --- a/src/Authentication/Matching.php +++ b/src/Authentication/Matching.php @@ -48,16 +48,6 @@ public function getAuthentication() return $this->authentication; } - /** - * Sets the authentication. - * - * @param Authentication $authentication - */ - public function setAuthentication(Authentication $authentication) - { - $this->authentication = $authentication; - } - /** * Returns the matcher. * @@ -68,16 +58,6 @@ public function getMatcher() return $this->matcher; } - /** - * Sets the matcher. - * - * @param callable $matcher - */ - public function setMatcher(callable $matcher) - { - $this->matcher = $matcher; - } - /** * {@inheritdoc} */ diff --git a/src/Authentication/UserPasswordPair.php b/src/Authentication/UserPasswordPair.php index 14f7cda..77113c2 100644 --- a/src/Authentication/UserPasswordPair.php +++ b/src/Authentication/UserPasswordPair.php @@ -29,16 +29,6 @@ public function getUsername() return $this->username; } - /** - * Sets the username. - * - * @param string $username - */ - public function setUsername($username) - { - $this->username = $username; - } - /** * Returns the password. * @@ -48,14 +38,4 @@ public function getPassword() { return $this->password; } - - /** - * Sets the password. - * - * @param string $password - */ - public function setPassword($password) - { - $this->password = $password; - } }