1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* File: AccountCreateHandlerTest.php |
4
|
|
|
* |
5
|
|
|
* @author Maciej Sławik <[email protected]> |
6
|
|
|
* Github: https://github.com/maciejslawik |
7
|
|
|
*/ |
8
|
|
|
namespace MSlwk\FreshMail\Test\Account; |
9
|
|
|
|
10
|
|
|
use MSlwk\FreshMail\Handler\Account\AccountCreateHandler; |
11
|
|
|
use MSlwk\FreshMail\Tests\BaseTest; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
use MSlwk\FreshMail\Error\ErrorHandler; |
14
|
|
|
use MSlwk\FreshMail\Exception\Account\FreshMailAccountException; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class AccountCreateHandlerTest |
18
|
|
|
* |
19
|
|
|
* @package MSlwk\FreshMail\Test\Account |
20
|
|
|
*/ |
21
|
|
|
class AccountCreateHandlerTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
use BaseTest; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param $sendRequestReturnValue |
27
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject |
|
|
|
|
28
|
|
|
*/ |
29
|
|
|
public function getAccountCreateHandlerMock($sendRequestReturnValue) |
30
|
|
|
{ |
31
|
|
|
$accountCreateHandler = $this->getMockBuilder('\MSlwk\FreshMail\Handler\Account\AccountCreateHandler') |
|
|
|
|
32
|
|
|
->setConstructorArgs([new ErrorHandler(), '', '']) |
33
|
|
|
->setMethods(['sendRequest']) |
34
|
|
|
->getMock(); |
35
|
|
|
|
36
|
|
|
$accountCreateHandler->expects($this->once()) |
37
|
|
|
->method('sendRequest') |
38
|
|
|
->will($this->returnValue($sendRequestReturnValue)); |
39
|
|
|
|
40
|
|
|
return $accountCreateHandler; |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testAccountCreatedSuccessfully() |
44
|
|
|
{ |
45
|
|
|
$expectedHash = '412rfefewf'; |
46
|
|
|
$expectedApiKey = '123dfvdnajklqnvad3'; |
47
|
|
|
$expectedApiSecret = 'fgvewqg234t312tgbvfb'; |
48
|
|
|
$accountCreateHandler = $this->getAccountCreateHandlerMock( |
49
|
|
|
'{"status":"OK", "data": {"hash":"' |
50
|
|
|
. $expectedHash . '","api_key":"' |
51
|
|
|
. $expectedApiKey . '","api_secret":"' |
52
|
|
|
. $expectedApiSecret . '"}}' |
53
|
|
|
); |
54
|
|
|
$returnData = $accountCreateHandler->registerNewAccount('Test', 'Test', 'Test', 'Test', '987654321'); |
55
|
|
|
self::assertEquals($expectedHash, $returnData->hash); |
56
|
|
|
self::assertEquals($expectedApiKey, $returnData->api_key); |
57
|
|
|
self::assertEquals($expectedApiSecret, $returnData->api_secret); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testApiEndpoint() |
61
|
|
|
{ |
62
|
|
|
$accountCreateHandler = new AccountCreateHandler(new ErrorHandler(), '', ''); |
63
|
|
|
$expectedApiEndpoint = '/rest/account/create'; |
64
|
|
|
$returnedApiEndpoint = $this->getApiEndpoint($accountCreateHandler); |
65
|
|
|
self::assertEquals($expectedApiEndpoint, $returnedApiEndpoint); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testEmptyLogin() |
69
|
|
|
{ |
70
|
|
|
$accountCreateHandler = $this->getAccountCreateHandlerMock( |
71
|
|
|
'{"errors":[{ "message":"Empty login", "code":"1501" }], "status":"errors"}' |
72
|
|
|
); |
73
|
|
|
$this->expectException(FreshMailAccountException::class); |
74
|
|
|
$accountCreateHandler->registerNewAccount('Test', 'Test', 'Test', 'Test', '987654321'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testIncorrectLogin() |
78
|
|
|
{ |
79
|
|
|
$accountCreateHandler = $this->getAccountCreateHandlerMock( |
80
|
|
|
'{"errors":[{ "message":"Incorrect login", "code":"1502" }], "status":"errors"}' |
81
|
|
|
); |
82
|
|
|
$this->expectException(FreshMailAccountException::class); |
83
|
|
|
$accountCreateHandler->registerNewAccount('Test', 'Test', 'Test', 'Test', '987654321'); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testLoginAlreadyExists() |
87
|
|
|
{ |
88
|
|
|
$accountCreateHandler = $this->getAccountCreateHandlerMock( |
89
|
|
|
'{"errors":[{ "message":"Login already exists", "code":"1503" }], "status":"errors"}' |
90
|
|
|
); |
91
|
|
|
$this->expectException(FreshMailAccountException::class); |
92
|
|
|
$accountCreateHandler->registerNewAccount('Test', 'Test', 'Test', 'Test', '987654321'); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function testEmptyPassword() |
96
|
|
|
{ |
97
|
|
|
$accountCreateHandler = $this->getAccountCreateHandlerMock( |
98
|
|
|
'{"errors":[{ "message":"Empty password", "code":"1504" }], "status":"errors"}' |
99
|
|
|
); |
100
|
|
|
$this->expectException(FreshMailAccountException::class); |
101
|
|
|
$accountCreateHandler->registerNewAccount('Test', 'Test', 'Test', 'Test', '987654321'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function testPasswordTooWeak() |
105
|
|
|
{ |
106
|
|
|
$accountCreateHandler = $this->getAccountCreateHandlerMock( |
107
|
|
|
'{"errors":[{ "message":"Password too weak", "code":"1505" }], "status":"errors"}' |
108
|
|
|
); |
109
|
|
|
$this->expectException(FreshMailAccountException::class); |
110
|
|
|
$accountCreateHandler->registerNewAccount('Test', 'Test', 'Test', 'Test', '987654321'); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function testEmptyFirstname() |
114
|
|
|
{ |
115
|
|
|
$accountCreateHandler = $this->getAccountCreateHandlerMock( |
116
|
|
|
'{"errors":[{ "message":"Empty firstname", "code":"1506" }], "status":"errors"}' |
117
|
|
|
); |
118
|
|
|
$this->expectException(FreshMailAccountException::class); |
119
|
|
|
$accountCreateHandler->registerNewAccount('Test', 'Test', 'Test', 'Test', '987654321'); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function testEmptyLastname() |
123
|
|
|
{ |
124
|
|
|
$accountCreateHandler = $this->getAccountCreateHandlerMock( |
125
|
|
|
'{"errors":[{ "message":"Empty lastname", "code":"1507" }], "status":"errors"}' |
126
|
|
|
); |
127
|
|
|
$this->expectException(FreshMailAccountException::class); |
128
|
|
|
$accountCreateHandler->registerNewAccount('Test', 'Test', 'Test', 'Test', '987654321'); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function testEmptyPhone() |
132
|
|
|
{ |
133
|
|
|
$accountCreateHandler = $this->getAccountCreateHandlerMock( |
134
|
|
|
'{"errors":[{ "message":"Empty phone number", "code":"1509" }], "status":"errors"}' |
135
|
|
|
); |
136
|
|
|
$this->expectException(FreshMailAccountException::class); |
137
|
|
|
$accountCreateHandler->registerNewAccount('Test', 'Test', 'Test', 'Test', '987654321'); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function testErrorOccurred() |
141
|
|
|
{ |
142
|
|
|
$accountCreateHandler = $this->getAccountCreateHandlerMock( |
143
|
|
|
'{"errors":[{ "message":"An error occurred", "code":"1510" }], "status":"errors"}' |
144
|
|
|
); |
145
|
|
|
$this->expectException(FreshMailAccountException::class); |
146
|
|
|
$accountCreateHandler->registerNewAccount('Test', 'Test', 'Test', 'Test', '987654321'); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function testAccountNotCreated() |
150
|
|
|
{ |
151
|
|
|
$accountCreateHandler = $this->getAccountCreateHandlerMock( |
152
|
|
|
'{"errors":[{ "message":"Account was not created", "code":"1511" }], "status":"errors"}' |
153
|
|
|
); |
154
|
|
|
$this->expectException(FreshMailAccountException::class); |
155
|
|
|
$accountCreateHandler->registerNewAccount('Test', 'Test', 'Test', 'Test', '987654321'); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function testAccountNotAssignedToApplication() |
159
|
|
|
{ |
160
|
|
|
$accountCreateHandler = $this->getAccountCreateHandlerMock( |
161
|
|
|
'{"errors":[{ "message":"Account couldnt be assigned to application", "code":"1512" }], "status":"errors"}' |
162
|
|
|
); |
163
|
|
|
$this->expectException(FreshMailAccountException::class); |
164
|
|
|
$accountCreateHandler->registerNewAccount('Test', 'Test', 'Test', 'Test', '987654321'); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function testAccountCreationAccessDenied() |
168
|
|
|
{ |
169
|
|
|
$accountCreateHandler = $this->getAccountCreateHandlerMock( |
170
|
|
|
'{"errors":[{ "message":"Account creation access denied", "code":"1513" }], "status":"errors"}' |
171
|
|
|
); |
172
|
|
|
$this->expectException(FreshMailAccountException::class); |
173
|
|
|
$accountCreateHandler->registerNewAccount('Test', 'Test', 'Test', 'Test', '987654321'); |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|
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