CampaignCreateHandlerTest   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 155
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 71
c 1
b 0
f 0
dl 0
loc 155
rs 10
wmc 16

16 Methods

Rating   Name   Duplication   Size   Complexity  
A testApiEndpoint() 0 6 1
A getCampaignCreateHandlerMock() 0 12 1
A testIncorrectFromAddress() 0 7 1
A testNoParameters() 0 7 1
A testCampaignCreatedSuccessfully() 0 8 1
A testListNotFound() 0 7 1
A testIncorrectGroupHash() 0 7 1
A testIncorrectReplyTo() 0 7 1
A testIncorrectUrl() 0 7 1
A testNoClient() 0 7 1
A testIncorrectListHash() 0 7 1
A testEmptyCampaignName() 0 7 1
A testGroupNotFound() 0 7 1
A testIncorrectResignationUrl() 0 7 1
A testEmptyCampaignContent() 0 7 1
A testMissingSubscribtionList() 0 7 1
1
<?php
2
/**
3
 * File: CampaignCreateHandlerTest.php
4
 *
5
 * @author      Maciej Sławik <[email protected]>
6
 * Github:      https://github.com/maciejslawik
7
 */
8
9
namespace MSlwk\FreshMail\Test\Campaign;
10
11
use MSlwk\FreshMail\Handler\Campaign\CampaignCreateHandler;
12
use MSlwk\FreshMail\Tests\BaseTest;
13
use PHPUnit\Framework\TestCase;
14
use MSlwk\FreshMail\Error\ErrorHandler;
15
use MSlwk\FreshMail\Exception\Campaign\FreshMailCampaignException;
16
17
/**
18
 * Class CampaignCreateHandlerTest
19
 *
20
 * @package MSlwk\FreshMail\Test\Campaign
21
 */
22
class CampaignCreateHandlerTest extends TestCase
23
{
24
    use BaseTest;
25
26
    /**
27
     * @param $sendRequestReturnValue
28
     * @return \PHPUnit_Framework_MockObject_MockObject
0 ignored issues
show
Bug introduced by
The type PHPUnit_Framework_MockObject_MockObject was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
     */
30
    public function getCampaignCreateHandlerMock($sendRequestReturnValue)
31
    {
32
        $campaignCreateHandler = $this->getMockBuilder('\MSlwk\FreshMail\Handler\Campaign\CampaignCreateHandler')
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/pull/3687 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

32
        $campaignCreateHandler = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder('\MSlwk\FreshMail\Handler\Campaign\CampaignCreateHandler')

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
33
            ->setConstructorArgs([new ErrorHandler(), '', ''])
34
            ->setMethods(['sendRequest'])
35
            ->getMock();
36
37
        $campaignCreateHandler->expects($this->once())
38
            ->method('sendRequest')
39
            ->will($this->returnValue($sendRequestReturnValue));
40
41
        return $campaignCreateHandler;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $campaignCreateHandler returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the documented return type PHPUnit_Framework_MockObject_MockObject.
Loading history...
42
    }
43
44
    public function testCampaignCreatedSuccessfully()
45
    {
46
        $expectedHash = '412rfefewf';
47
        $campaignCreateHandler = $this->getCampaignCreateHandlerMock(
48
            '{"status":"OK", "data": {"hash":"' . $expectedHash . '"}}'
49
        );
50
        $returnedHash = $campaignCreateHandler->createCampaign('Test', '', 'Test');
51
        self::assertEquals($expectedHash, $returnedHash);
52
    }
53
54
    public function testApiEndpoint()
55
    {
56
        $accountCreateHandler = new CampaignCreateHandler(new ErrorHandler(), '', '');
57
        $expectedApiEndpoint = '/rest/campaigns/create';
58
        $returnedApiEndpoint = $this->getApiEndpoint($accountCreateHandler);
59
        self::assertEquals($expectedApiEndpoint, $returnedApiEndpoint);
60
    }
61
62
    public function testEmptyCampaignName()
63
    {
64
        $campaignCreateHandler = $this->getCampaignCreateHandlerMock(
65
            '{"errors":[{ "message":"Campaign name empty", "code":"1701" }], "status":"errors"}'
66
        );
67
        $this->expectException(FreshMailCampaignException::class);
68
        $campaignCreateHandler->createCampaign('Test');
69
    }
70
71
    public function testEmptyCampaignContent()
72
    {
73
        $campaignCreateHandler = $this->getCampaignCreateHandlerMock(
74
            '{"errors":[{ "message":"Campaign content empty", "code":"1702" }], "status":"errors"}'
75
        );
76
        $this->expectException(FreshMailCampaignException::class);
77
        $campaignCreateHandler->createCampaign('Test');
78
    }
79
80
    public function testIncorrectUrl()
81
    {
82
        $campaignCreateHandler = $this->getCampaignCreateHandlerMock(
83
            '{"errors":[{ "message":"Incorrect URL", "code":"1703" }], "status":"errors"}'
84
        );
85
        $this->expectException(FreshMailCampaignException::class);
86
        $campaignCreateHandler->createCampaign('Test');
87
    }
88
89
    public function testNoClient()
90
    {
91
        $campaignCreateHandler = $this->getCampaignCreateHandlerMock(
92
            '{"errors":[{ "message":"No client (internal error)", "code":"1704" }], "status":"errors"}'
93
        );
94
        $this->expectException(FreshMailCampaignException::class);
95
        $campaignCreateHandler->createCampaign('Test');
96
    }
97
98
    public function testNoParameters()
99
    {
100
        $campaignCreateHandler = $this->getCampaignCreateHandlerMock(
101
            '{"errors":[{ "message":"No parameters (internal error)", "code":"1705" }], "status":"errors"}'
102
        );
103
        $this->expectException(FreshMailCampaignException::class);
104
        $campaignCreateHandler->createCampaign('Test');
105
    }
106
107
    public function testIncorrectFromAddress()
108
    {
109
        $campaignCreateHandler = $this->getCampaignCreateHandlerMock(
110
            '{"errors":[{ "message":"Incorrect from_address email", "code":"1706" }], "status":"errors"}'
111
        );
112
        $this->expectException(FreshMailCampaignException::class);
113
        $campaignCreateHandler->createCampaign('Test');
114
    }
115
116
    public function testIncorrectReplyTo()
117
    {
118
        $campaignCreateHandler = $this->getCampaignCreateHandlerMock(
119
            '{"errors":[{ "message":"Incorrect reply_to email", "code":"1707" }], "status":"errors"}'
120
        );
121
        $this->expectException(FreshMailCampaignException::class);
122
        $campaignCreateHandler->createCampaign('Test');
123
    }
124
125
    public function testMissingSubscribtionList()
126
    {
127
        $campaignCreateHandler = $this->getCampaignCreateHandlerMock(
128
            '{"errors":[{ "message":"Missing subscription list and group", "code":"1708" }], "status":"errors"}'
129
        );
130
        $this->expectException(FreshMailCampaignException::class);
131
        $campaignCreateHandler->createCampaign('Test');
132
    }
133
134
    public function testIncorrectListHash()
135
    {
136
        $campaignCreateHandler = $this->getCampaignCreateHandlerMock(
137
            '{"errors":[{ "message":"At least one list hash is incorrect", "code":"1709" }], "status":"errors"}'
138
        );
139
        $this->expectException(FreshMailCampaignException::class);
140
        $campaignCreateHandler->createCampaign('Test');
141
    }
142
143
    public function testIncorrectGroupHash()
144
    {
145
        $campaignCreateHandler = $this->getCampaignCreateHandlerMock(
146
            '{"errors":[{ "message":"At least one group hash is incorrect", "code":"1710" }], "status":"errors"}'
147
        );
148
        $this->expectException(FreshMailCampaignException::class);
149
        $campaignCreateHandler->createCampaign('Test');
150
    }
151
152
    public function testListNotFound()
153
    {
154
        $campaignCreateHandler = $this->getCampaignCreateHandlerMock(
155
            '{"errors":[{ "message":"Subscribion list not found", "code":"1711" }], "status":"errors"}'
156
        );
157
        $this->expectException(FreshMailCampaignException::class);
158
        $campaignCreateHandler->createCampaign('Test');
159
    }
160
161
    public function testGroupNotFound()
162
    {
163
        $campaignCreateHandler = $this->getCampaignCreateHandlerMock(
164
            '{"errors":[{ "message":"Subscription group not found", "code":"1712" }], "status":"errors"}'
165
        );
166
        $this->expectException(FreshMailCampaignException::class);
167
        $campaignCreateHandler->createCampaign('Test');
168
    }
169
170
    public function testIncorrectResignationUrl()
171
    {
172
        $campaignCreateHandler = $this->getCampaignCreateHandlerMock(
173
            '{"errors":[{ "message":"Resignation link must be a valid URL", "code":"1713" }], "status":"errors"}'
174
        );
175
        $this->expectException(FreshMailCampaignException::class);
176
        $campaignCreateHandler->createCampaign('Test');
177
    }
178
179
180
}
181