1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* File: SubscriberGetHandlerTest.php |
4
|
|
|
* |
5
|
|
|
* @author Maciej Sławik <[email protected]> |
6
|
|
|
* Github: https://github.com/maciejslawik |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace MSlwk\FreshMail\Test\Subscriber; |
10
|
|
|
|
11
|
|
|
use MSlwk\FreshMail\Handler\Subscriber\SubscriberGetHandler; |
12
|
|
|
use MSlwk\FreshMail\Tests\BaseTest; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use MSlwk\FreshMail\Error\ErrorHandler; |
15
|
|
|
use MSlwk\FreshMail\Exception\Subscriber\FreshMailSubscriberException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class SubscriberGetHandlerTest |
19
|
|
|
* |
20
|
|
|
* @package MSlwk\FreshMail\Test\Subscriber |
21
|
|
|
*/ |
22
|
|
|
class SubscriberGetHandlerTest extends TestCase |
23
|
|
|
{ |
24
|
|
|
use BaseTest; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param $sendRequestReturnValue |
28
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject |
|
|
|
|
29
|
|
|
*/ |
30
|
|
|
public function getSubscriberGetHandlerMock($sendRequestReturnValue) |
31
|
|
|
{ |
32
|
|
|
$subscriberGetHandler = $this->getMockBuilder('\MSlwk\FreshMail\Handler\Subscriber\SubscriberGetHandler') |
|
|
|
|
33
|
|
|
->setConstructorArgs([new ErrorHandler(), '', '']) |
34
|
|
|
->setMethods(['sendRequest']) |
35
|
|
|
->getMock(); |
36
|
|
|
|
37
|
|
|
$subscriberGetHandler->expects($this->once()) |
38
|
|
|
->method('sendRequest') |
39
|
|
|
->will($this->returnValue($sendRequestReturnValue)); |
40
|
|
|
|
41
|
|
|
return $subscriberGetHandler; |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testSubscriberPulledSuccessfully() |
45
|
|
|
{ |
46
|
|
|
$expectedEmail = '15fewdg13f'; |
47
|
|
|
$expectedState = 2; |
48
|
|
|
$expectedCustomFields = (object)['ssfas' => '4124rfd']; |
49
|
|
|
$expectedHash = 'gvrheg'; |
50
|
|
|
$subscriberGetHandler = $this->getSubscriberGetHandlerMock( |
51
|
|
|
'{"status":"OK","data":{"email":"' |
52
|
|
|
. $expectedEmail . '","state":' |
53
|
|
|
. $expectedState . ',"custom_fields":' |
54
|
|
|
. json_encode($expectedCustomFields) . ',"id_hash":"' |
55
|
|
|
. $expectedHash . '"}}' |
56
|
|
|
); |
57
|
|
|
$returnedData = $subscriberGetHandler->getSubscriber('Test', 'Test'); |
58
|
|
|
self::assertEquals($expectedEmail, $returnedData->email); |
59
|
|
|
self::assertEquals($expectedState, $returnedData->state); |
60
|
|
|
self::assertEquals($expectedCustomFields, $returnedData->custom_fields); |
61
|
|
|
self::assertEquals($expectedHash, $returnedData->id_hash); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testApiEndpoint() |
65
|
|
|
{ |
66
|
|
|
$subscriberGetHandler = new SubscriberGetHandler(new ErrorHandler(), '', ''); |
67
|
|
|
$expectedApiEndpoint = '/rest/subscriber/get'; |
68
|
|
|
$returnedApiEndpoint = $this->getApiEndpoint($subscriberGetHandler); |
69
|
|
|
self::assertEquals($expectedApiEndpoint, $returnedApiEndpoint); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testIncorrectEmail() |
73
|
|
|
{ |
74
|
|
|
$subscriberGetHandler = $this->getSubscriberGetHandlerMock( |
75
|
|
|
'{"errors":[{ "message":"Incorrect email", "code":"1311" }], "status":"errors"}' |
76
|
|
|
); |
77
|
|
|
$this->expectException(FreshMailSubscriberException::class); |
78
|
|
|
$subscriberGetHandler->getSubscriber('Test', 'Test'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testListDoesntExist() |
82
|
|
|
{ |
83
|
|
|
$subscriberGetHandler = $this->getSubscriberGetHandlerMock( |
84
|
|
|
'{"errors":[{ "message":"The subscription list doesnt exist", "code":"1312" }], "status":"errors"}' |
85
|
|
|
); |
86
|
|
|
$this->expectException(FreshMailSubscriberException::class); |
87
|
|
|
$subscriberGetHandler->getSubscriber('Test', 'Test'); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
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