1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* File part of the Redmine User Provider bundle |
4
|
|
|
* |
5
|
|
|
* @category SymfonyBundle |
6
|
|
|
* @package GMaissa.RedmineUserProviderBundle |
7
|
|
|
* @author Guillaume Maïssa <[email protected]> |
8
|
|
|
* @copyright 2017 Guillaume Maïssa |
9
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace GMaissa\RedmineUserProviderBundle\Tester\Mock\ApiClient; |
13
|
|
|
|
14
|
|
|
use GMaissa\RedmineUserProviderBundle\ApiClient\RedmineApiClientInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Mock class for User provider testing |
18
|
|
|
*/ |
19
|
|
|
class RedmineApiClientMock implements RedmineApiClientInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private $connectedUser = false; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
private $url; |
30
|
|
|
|
31
|
|
|
private $usersData = [ |
32
|
|
|
'test' => [ |
33
|
|
|
'user' => [ |
34
|
|
|
'mail' => '[email protected]', |
35
|
|
|
'login' => 'test', |
36
|
|
|
'api_key' => 'api-key', |
37
|
|
|
'password' => 'test', |
38
|
|
|
'firstname' => 'Te', |
39
|
|
|
'lastname' => 'St' |
40
|
|
|
] |
41
|
|
|
], |
42
|
|
|
'test-unauthorized' => [ |
43
|
|
|
'user' => [ |
44
|
|
|
'mail' => '[email protected]', |
45
|
|
|
'login' => 'test-unauthorized', |
46
|
|
|
'api_key' => 'api-key2', |
47
|
|
|
'password' => 'test', |
48
|
|
|
'firstname' => 'Te', |
49
|
|
|
'lastname' => 'St 2' |
50
|
|
|
] |
51
|
|
|
] |
52
|
|
|
]; |
53
|
|
|
|
54
|
|
|
private $apiName; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
8 |
|
public function __construct(string $url) |
60
|
|
|
{ |
61
|
8 |
|
$this->url = $url; |
|
|
|
|
62
|
8 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Set the Redmine client Class |
66
|
|
|
* |
67
|
|
|
* @param string $clientClass |
68
|
|
|
*/ |
69
|
|
|
public function setClientClass(string $clientClass) |
70
|
|
|
{ |
71
|
|
|
// Do nothing |
72
|
|
|
unset($clientClass); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
*/ |
78
|
4 |
|
public function connect(string $login, string $password) |
79
|
|
|
{ |
80
|
4 |
|
if (isset($this->usersData[$login]) && $password == $this->usersData[$login]['user']['password']) { |
81
|
3 |
|
$this->connectedUser = $login; |
82
|
|
|
} else { |
83
|
1 |
|
throw new \Exception('Invalid credentials'); |
84
|
|
|
} |
85
|
3 |
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* {@inheritdoc} |
89
|
|
|
*/ |
90
|
3 |
|
public function api(string $apiName) |
91
|
|
|
{ |
92
|
3 |
|
if (!$this->connectedUser) { |
93
|
|
|
throw new \Exception('Connection to server not instantiated'); |
94
|
|
|
} |
95
|
3 |
|
$this->apiName = $apiName; |
96
|
|
|
|
97
|
3 |
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Retrieve current connected user |
102
|
|
|
* |
103
|
|
|
* @return mixed|null |
104
|
|
|
*/ |
105
|
3 |
|
public function getCurrentUser() |
106
|
|
|
{ |
107
|
3 |
|
return (isset($this->usersData[$this->connectedUser])) ? $this->usersData[$this->connectedUser] : null; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..