Skip to content

Commit

Permalink
Add getIdentity and hasIdentity to Authenticator.
Browse files Browse the repository at this point in the history
Based on and supercedes #24. Thanks, @radicaldrew!
  • Loading branch information
jeremykendall committed Jan 18, 2016
1 parent 53d80c4 commit 353aad9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/JeremyKendall/Slim/Auth/Authenticator.php
Expand Up @@ -59,4 +59,24 @@ public function logout()
{
$this->auth->clearIdentity();
}

/**
* Returns true if and only if an identity is available.
*
* @return bool
*/
public function hasIdentity()
{
return $this->auth->hasIdentity();
}

/**
* Returns the authenticated identity or null if no identity is available.
*
* @return mixed|null
*/
public function getIdentity()
{
return $this->auth->getIdentity();
}
}
16 changes: 16 additions & 0 deletions tests/JeremyKendall/Slim/Auth/Tests/AuthenticatorTest.php
Expand Up @@ -86,6 +86,22 @@ public function testLogout()
$this->authenticator->logout();
}

public function testHasIdentityProxiesToAuthenticationService()
{
$this->auth->expects($this->once())
->method('hasIdentity');

$this->authenticator->hasIdentity();
}

public function testGetIdentityProxiesToAuthenticationService()
{
$this->auth->expects($this->once())
->method('getIdentity');

$this->authenticator->getIdentity();
}

private function getFailureResult()
{
return new Result(Result::FAILURE, array(), array('FAILZORS'));
Expand Down

0 comments on commit 353aad9

Please sign in to comment.