CampaignDeleteHandlerTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 53
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testApiEndpoint() 0 6 1
A getCampaignDeleteHandlerMock() 0 12 1
A testCampaignDoesntExist() 0 7 1
A testCampaignDeleteSuccessful() 0 5 1
A testCampaignAlreadyDeleted() 0 7 1
1
<?php
2
/**
3
 * File: CampaignDeleteHandlerTest.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\CampaignDeleteHandler;
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 CampaignDeleteHandlerTest
19
 *
20
 * @package MSlwk\FreshMail\Test\Campaign
21
 */
22
class CampaignDeleteHandlerTest 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 getCampaignDeleteHandlerMock($sendRequestReturnValue)
31
    {
32
        $campaignDeleteHandler = $this->getMockBuilder('\MSlwk\FreshMail\Handler\Campaign\CampaignDeleteHandler')
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
        $campaignDeleteHandler = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder('\MSlwk\FreshMail\Handler\Campaign\CampaignDeleteHandler')

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
        $campaignDeleteHandler->expects($this->once())
38
            ->method('sendRequest')
39
            ->will($this->returnValue($sendRequestReturnValue));
40
41
        return $campaignDeleteHandler;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $campaignDeleteHandler 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 testCampaignDeleteSuccessful()
45
    {
46
        $campaignDeleteHandler = $this->getCampaignDeleteHandlerMock('{"status":"OK"}');
47
        $returnValue = $campaignDeleteHandler->deleteCampaign('id_hash');
48
        self::assertNull($returnValue);
49
    }
50
51
    public function testApiEndpoint()
52
    {
53
        $accountCreateHandler = new CampaignDeleteHandler(new ErrorHandler(), '', '');
54
        $expectedApiEndpoint = '/rest/campaigns/delete';
55
        $returnedApiEndpoint = $this->getApiEndpoint($accountCreateHandler);
56
        self::assertEquals($expectedApiEndpoint, $returnedApiEndpoint);
57
    }
58
59
    public function testCampaignDoesntExist()
60
    {
61
        $campaignDeleteHandler = $this->getCampaignDeleteHandlerMock(
62
            '{"errors":[{ "message":"Requested campaign doesnt exist", "code":"1724" }], "status":"errors"}'
63
        );
64
        $this->expectException(FreshMailCampaignException::class);
65
        $campaignDeleteHandler->deleteCampaign('id_hash');
66
    }
67
68
    public function testCampaignAlreadyDeleted()
69
    {
70
        $campaignDeleteHandler = $this->getCampaignDeleteHandlerMock(
71
            '{"errors":[{ "message":"Campaign cant be deleted", "code":"1798" }], "status":"errors"}'
72
        );
73
        $this->expectException(FreshMailCampaignException::class);
74
        $campaignDeleteHandler->deleteCampaign('id_hash');
75
    }
76
}
77