-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAuthServiceTestBase.php
More file actions
46 lines (42 loc) · 1.48 KB
/
AuthServiceTestBase.php
File metadata and controls
46 lines (42 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/**
* Definition of AuthServiceTestBase.php
*
* @copyright 2015-today Justso GmbH
* @author j.schirrmacher@justso.de
*/
namespace justso\justauth;
use justso\justapi\testutil\ServiceTestBase;
use justso\justapi\testutil\TestEnvironment;
/**
* Class AuthServiceTestBase
*/
class AuthServiceTestBase extends ServiceTestBase
{
/**
* @param TestEnvironment $env
* @param int $id
* @return \PHPUnit_FrameWork_MockObject_MockObject
*/
protected function getMockUser(TestEnvironment $env, $id)
{
$user = $this->mockInterface('\\justso\\justauth', 'UserInterface', $env);
$user->expects($this->any())->method('getId')->willReturn($id);
return $user;
}
/**
* @param TestEnvironment $env
* @param UserInterface $user
*/
protected function setAuthenticatedUser(TestEnvironment $env, UserInterface $user)
{
$authenticator = $this->createMock('\justso\justauth\Authenticator');
$authenticator->expects($this->any())->method('isAuth')->willReturn(true);
$authenticator->expects($this->any())->method('getUser')->willReturn($user);
$authenticator->expects($this->any())->method('getUserId')->willReturn($user->getId());
$info = ['errors' => [], 'userid' => $user->getId()];
$authenticator->expects($this->any())->method('getAuthInfo')->willReturn($info);
$env->setDICEntry('Authenticator', $authenticator);
$env->getSession()->setValue('user', $user);
}
}