getCampaignSendHandlerMock()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 12
rs 10
1
<?php
2
/**
3
 * File: CampaignSendHandlerTest.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\CampaignSendHandler;
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 CampaignSendHandlerTest
19
 *
20
 * @package MSlwk\FreshMail\Test\Campaign
21
 */
22
class CampaignSendHandlerTest 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 getCampaignSendHandlerMock($sendRequestReturnValue)
31
    {
32
        $campaignSendHandler = $this->getMockBuilder('\MSlwk\FreshMail\Handler\Campaign\CampaignSendHandler')
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
        $campaignSendHandler = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder('\MSlwk\FreshMail\Handler\Campaign\CampaignSendHandler')

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
        $campaignSendHandler->expects($this->once())
38
            ->method('sendRequest')
39
            ->will($this->returnValue($sendRequestReturnValue));
40
41
        return $campaignSendHandler;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $campaignSendHandler 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 testCampaignSuccessfullySent()
45
    {
46
        $campaignSendHandler = $this->getCampaignSendHandlerMock('{"status":"OK"}');
47
        $returnValue = $campaignSendHandler->sendCampaign('id_hash');
48
        self::assertNull($returnValue);
49
    }
50
51
    public function testApiEndpoint()
52
    {
53
        $accountCreateHandler = new CampaignSendHandler(new ErrorHandler(), '', '');
54
        $expectedApiEndpoint = '/rest/campaigns/send';
55
        $returnedApiEndpoint = $this->getApiEndpoint($accountCreateHandler);
56
        self::assertEquals($expectedApiEndpoint, $returnedApiEndpoint);
57
    }
58
59
    public function testIncorrectCampaignHash()
60
    {
61
        $campaignSendHandler = $this->getCampaignSendHandlerMock(
62
            '{"errors":[{ "message":"Incorrect campaign hash", "code":"1731" }], "status":"errors"}'
63
        );
64
        $this->expectException(FreshMailCampaignException::class);
65
        $campaignSendHandler->sendCampaign('id_hash');
66
    }
67
68
    public function testIncorrectSendDate()
69
    {
70
        $campaignSendHandler = $this->getCampaignSendHandlerMock(
71
            '{"errors":[{ "message":"Incorrect sending time", "code":"1732" }], "status":"errors"}'
72
        );
73
        $this->expectException(FreshMailCampaignException::class);
74
        $campaignSendHandler->sendCampaign('id_hash');
75
    }
76
77
    public function testSendDateIsPast()
78
    {
79
        $campaignSendHandler = $this->getCampaignSendHandlerMock(
80
            '{"errors":[{ "message":"Sending time is in the past", "code":"1733" }], "status":"errors"}'
81
        );
82
        $this->expectException(FreshMailCampaignException::class);
83
        $campaignSendHandler->sendCampaign('id_hash');
84
    }
85
86
    public function testCampaignDoesntExist()
87
    {
88
        $campaignSendHandler = $this->getCampaignSendHandlerMock(
89
            '{"errors":[{ "message":"Requested campaign doesnt exist", "code":"1734" }], "status":"errors"}'
90
        );
91
        $this->expectException(FreshMailCampaignException::class);
92
        $campaignSendHandler->sendCampaign('id_hash');
93
    }
94
95
    public function testCampaignNotReadyToSend()
96
    {
97
        $campaignSendHandler = $this->getCampaignSendHandlerMock(
98
            '{"errors":[{ "message":"Campaign not ready to send", "code":"1735" }], "status":"errors"}'
99
        );
100
        $this->expectException(FreshMailCampaignException::class);
101
        $campaignSendHandler->sendCampaign('id_hash');
102
    }
103
104
    public function testCampaignAleadySending()
105
    {
106
        $campaignSendHandler = $this->getCampaignSendHandlerMock(
107
            '{"errors":[{ "message":"The campaign is already set to send", "code":"1736" }], "status":"errors"}'
108
        );
109
        $this->expectException(FreshMailCampaignException::class);
110
        $campaignSendHandler->sendCampaign('id_hash');
111
    }
112
}
113