Skip to content

Commit c7e864f

Browse files
authored
Merge pull request #30 from Saeven/feature/travis-change
Added method to helper, requireIdentity
2 parents 869b8bc + e0a78ca commit c7e864f

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

bundle/Spec/CirclicalUser/Controller/Plugin/AuthenticationPluginSpec.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Spec\CirclicalUser\Controller\Plugin;
44

5+
use CirclicalUser\Exception\UserRequiredException;
56
use CirclicalUser\Provider\UserInterface as User;
67
use CirclicalUser\Service\AccessService;
78
use CirclicalUser\Service\AuthenticationService;
@@ -49,4 +50,16 @@ public function it_creates_users($authenticationService, $newUser)
4950
$authenticationService->create($newUser, 'userA', '123')->shouldBeCalled();
5051
$this->create($newUser, 'userA', '123');
5152
}
53+
54+
public function it_fails_on_require_when_there_is_no_auth(AuthenticationService $authenticationService)
55+
{
56+
$authenticationService->getIdentity()->willReturn(null);
57+
$this->shouldThrow(UserRequiredException::class)->during('requireIdentity');
58+
}
59+
60+
public function it_succeeds_on_require_when_there_is_auth(AuthenticationService $authenticationService, User $user)
61+
{
62+
$authenticationService->getIdentity()->willReturn($user);
63+
$this->requireIdentity()->shouldBe($user);
64+
}
5265
}

phpspec.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ extensions:
1717
- src
1818
blacklist:
1919
- src/CirclicalUser/Mapper
20-
- src/CirclicalUser/Entity
2120
- src/CirclicalUser/Exception

src/CirclicalUser/Controller/Plugin/AuthenticationPlugin.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace CirclicalUser\Controller\Plugin;
44

5+
use CirclicalUser\Exception\UserRequiredException;
56
use CirclicalUser\Provider\UserInterface as User;
67
use CirclicalUser\Service\AccessService;
78
use CirclicalUser\Service\AuthenticationService;
@@ -47,6 +48,21 @@ public function getIdentity()
4748
return $this->authenticationService->getIdentity();
4849
}
4950

51+
/**
52+
* Get a user identity, or else!
53+
* @return User|null
54+
* @throws UserRequiredException
55+
*/
56+
public function requireIdentity()
57+
{
58+
$user = $this->authenticationService->getIdentity();
59+
if (!$user) {
60+
throw new UserRequiredException();
61+
}
62+
63+
return $user;
64+
}
65+
5066
/**
5167
* Clear identity and reset tokens
5268
*/

src/CirclicalUser/Mapper/UserResetTokenMapper.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,10 @@ public function invalidateUnusedTokens(AuthenticationRecordInterface $authentica
6969
->set('r.status', UserResetTokenInterface::STATUS_INVALID)
7070
->where('r.authentication = :authentication')
7171
->andWhere('r.status = :status_unused')
72-
->setParameters(
73-
[
74-
'authentication' => $authenticationRecord,
75-
'status_unused' => UserResetTokenInterface::STATUS_UNUSED,
76-
]
77-
)
72+
->setParameters([
73+
'authentication' => $authenticationRecord,
74+
'status_unused' => UserResetTokenInterface::STATUS_UNUSED,
75+
])
7876
->getQuery();
7977

8078
$query->execute();

0 commit comments

Comments
 (0)