1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* File: ListCreateHandlerTest.php |
4
|
|
|
* |
5
|
|
|
* @author Maciej Sławik <[email protected]> |
6
|
|
|
* Github: https://github.com/maciejslawik |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace MSlwk\FreshMail\Test\Lists; |
10
|
|
|
|
11
|
|
|
use MSlwk\FreshMail\Handler\Lists\ListCreateHandler; |
12
|
|
|
use MSlwk\FreshMail\Tests\BaseTest; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use MSlwk\FreshMail\Error\ErrorHandler; |
15
|
|
|
use MSlwk\FreshMail\Exception\Lists\FreshMailListException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class ListCreateHandlerTest |
19
|
|
|
* |
20
|
|
|
* @package MSlwk\FreshMail\Test\Lists |
21
|
|
|
*/ |
22
|
|
|
class ListCreateHandlerTest extends TestCase |
23
|
|
|
{ |
24
|
|
|
use BaseTest; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param $sendRequestReturnValue |
28
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject |
|
|
|
|
29
|
|
|
*/ |
30
|
|
|
public function getListCreateHandlerMock($sendRequestReturnValue) |
31
|
|
|
{ |
32
|
|
|
$listCreateHandler = $this->getMockBuilder('\MSlwk\FreshMail\Handler\Lists\ListCreateHandler') |
|
|
|
|
33
|
|
|
->setConstructorArgs([new ErrorHandler(), '', '']) |
34
|
|
|
->setMethods(['sendRequest']) |
35
|
|
|
->getMock(); |
36
|
|
|
|
37
|
|
|
$listCreateHandler->expects($this->once()) |
38
|
|
|
->method('sendRequest') |
39
|
|
|
->will($this->returnValue($sendRequestReturnValue)); |
40
|
|
|
|
41
|
|
|
return $listCreateHandler; |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testListCreatedSuccessfully() |
45
|
|
|
{ |
46
|
|
|
$expectedCustomFields = (object)['ssfas' => '4124rfd']; |
47
|
|
|
$expectedHash = 'gvrheg'; |
48
|
|
|
$listCreateHandler = $this->getListCreateHandlerMock( |
49
|
|
|
'{"status":"OK","hash":"' |
50
|
|
|
. $expectedHash . '","custom_fields":' |
51
|
|
|
. json_encode($expectedCustomFields) . '}' |
52
|
|
|
); |
53
|
|
|
$returnedData = $listCreateHandler->createSubscriberList('Test', 'Test'); |
54
|
|
|
self::assertEquals($expectedCustomFields, $returnedData->custom_fields); |
55
|
|
|
self::assertEquals($expectedHash, $returnedData->hash); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testApiEndpoint() |
59
|
|
|
{ |
60
|
|
|
$listCreateHandler = new ListCreateHandler(new ErrorHandler(), '', ''); |
61
|
|
|
$expectedApiEndpoint = '/rest/subscribers_list/create'; |
62
|
|
|
$returnedApiEndpoint = $this->getApiEndpoint($listCreateHandler); |
63
|
|
|
self::assertEquals($expectedApiEndpoint, $returnedApiEndpoint); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testEmptyName() |
67
|
|
|
{ |
68
|
|
|
$listCreateHandler = $this->getListCreateHandlerMock( |
69
|
|
|
'{"errors":[{ "message":"Empty list name", "code":"1601" }], "status":"errors"}' |
70
|
|
|
); |
71
|
|
|
$this->expectException(FreshMailListException::class); |
72
|
|
|
$listCreateHandler->createSubscriberList('Test', 'Test'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testListCreationFailer() |
76
|
|
|
{ |
77
|
|
|
$listCreateHandler = $this->getListCreateHandlerMock( |
78
|
|
|
'{"errors":[{ "message":"List couldnt be created", "code":"1602" }], "status":"errors"}' |
79
|
|
|
); |
80
|
|
|
$this->expectException(FreshMailListException::class); |
81
|
|
|
$listCreateHandler->createSubscriberList('Test', 'Test'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testIncorrectCustomFields() |
85
|
|
|
{ |
86
|
|
|
$listCreateHandler = $this->getListCreateHandlerMock( |
87
|
|
|
'{"errors":[{ "message":"Custom fields incorrect", "code":"1603" }], "status":"errors"}' |
88
|
|
|
); |
89
|
|
|
$this->expectException(FreshMailListException::class); |
90
|
|
|
$listCreateHandler->createSubscriberList('Test', 'Test'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function testIncorrectTag() |
94
|
|
|
{ |
95
|
|
|
$listCreateHandler = $this->getListCreateHandlerMock( |
96
|
|
|
'{"errors":[{ "message":"Incorrect tag", "code":"1604" }], "status":"errors"}' |
97
|
|
|
); |
98
|
|
|
$this->expectException(FreshMailListException::class); |
99
|
|
|
$listCreateHandler->createSubscriberList('Test', 'Test'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function testIncorrectFieldType() |
103
|
|
|
{ |
104
|
|
|
$listCreateHandler = $this->getListCreateHandlerMock( |
105
|
|
|
'{"errors":[{ "message":"Incorrect field type", "code":"1605" }], "status":"errors"}' |
106
|
|
|
); |
107
|
|
|
$this->expectException(FreshMailListException::class); |
108
|
|
|
$listCreateHandler->createSubscriberList('Test', 'Test'); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
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