1
|
|
|
<?php |
2
|
|
|
namespace Mezon\Service\Tests; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Class ServiceClientTests |
6
|
|
|
* |
7
|
|
|
* @package ServiceClient |
8
|
|
|
* @subpackage ServiceClientTests |
9
|
|
|
* @author Dodonov A.A. |
10
|
|
|
* @version v.1.0 (2019/08/17) |
11
|
|
|
* @copyright Copyright (c) 2019, aeon.org |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Common unit tests for ServiceClient and all derived client classes |
16
|
|
|
* |
17
|
|
|
* @author Dodonov A.A. |
18
|
|
|
* @group baseTests |
19
|
|
|
*/ |
20
|
|
|
class ServiceClientTests extends TestCase |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Client class name |
25
|
|
|
*/ |
26
|
|
|
protected $clientClassName = ''; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Existing user's login |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $existingLogin = ''; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Constructor |
37
|
|
|
* |
38
|
|
|
* @param string $existingLogin |
39
|
|
|
*/ |
40
|
|
|
public function __construct(string $existingLogin) |
41
|
|
|
{ |
42
|
|
|
parent::__construct(); |
43
|
|
|
|
44
|
|
|
$this->existingLogin = $existingLogin; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Method creates client object |
49
|
|
|
* |
50
|
|
|
* @param string $password |
51
|
|
|
*/ |
52
|
|
|
protected function constructClient(string $password = 'root'): object |
53
|
|
|
{ |
54
|
|
|
return new $this->clientClassName($this->existingLogin, $password); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Testing API connection |
59
|
|
|
*/ |
60
|
|
|
public function testValidConnect(): void |
61
|
|
|
{ |
62
|
|
|
$client = $this->constructClient(); |
63
|
|
|
|
64
|
|
|
$this->assertNotEquals($client->getToken(), false, 'Connection failed'); |
65
|
|
|
$this->assertEquals($client->getStoredLogin(), $this->existingLogin, 'Login was not saved'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Testing invalid API connection |
70
|
|
|
*/ |
71
|
|
|
public function testInValidConnect(): void |
72
|
|
|
{ |
73
|
|
|
$this->expectException(\Exception::class); |
74
|
|
|
$this->constructClient('1234567'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Testing setting valid token |
79
|
|
|
*/ |
80
|
|
|
public function testSetValidToken(): void |
81
|
|
|
{ |
82
|
|
|
$client = $this->constructClient(); |
83
|
|
|
|
84
|
|
|
$newClient = new $this->clientClassName(); |
85
|
|
|
$newClient->setToken($client->getToken()); |
86
|
|
|
|
87
|
|
|
$this->assertNotEquals($newClient->getToken(), false, 'Token was not set(1)'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Testing setting valid token and login |
92
|
|
|
*/ |
93
|
|
|
public function testSetValidTokenAndLogin(): void |
94
|
|
|
{ |
95
|
|
|
$client = $this->constructClient(); |
96
|
|
|
|
97
|
|
|
$newClient = new $this->clientClassName(); |
98
|
|
|
$newClient->setToken($client->getToken(), '[email protected]'); |
99
|
|
|
|
100
|
|
|
$this->assertNotEquals($newClient->getToken(), false, 'Token was not set(2)'); |
101
|
|
|
$this->assertNotEquals($newClient->getStoredLogin(), false, 'Login was not saved'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Testing setting invalid token |
106
|
|
|
*/ |
107
|
|
|
public function testSetInValidToken(): void |
108
|
|
|
{ |
109
|
|
|
$client = new $this->clientClassName(); |
110
|
|
|
|
111
|
|
|
$this->expectException(\Exception::class); |
112
|
|
|
$client->setToken('unexistingtoken'); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Testing loginAs method |
117
|
|
|
*/ |
118
|
|
|
public function testLoginAs(): void |
119
|
|
|
{ |
120
|
|
|
$client = $this->constructClient(); |
121
|
|
|
|
122
|
|
|
$client->loginAs($this->existingLogin); |
123
|
|
|
|
124
|
|
|
$this->addToAssertionCount(1); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Testing loginAs method with failed call |
129
|
|
|
*/ |
130
|
|
|
public function testFailedLoginAs(): void |
131
|
|
|
{ |
132
|
|
|
$client = $this->constructClient(); |
133
|
|
|
|
134
|
|
|
$this->expectException(\Exception::class); |
135
|
|
|
$client->loginAs('[email protected]', 'login'); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths