testSubscriberDoesntExist()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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

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
        $subscriberEditHandler->expects($this->once())
38
            ->method('sendRequest')
39
            ->will($this->returnValue($sendRequestReturnValue));
40
41
        return $subscriberEditHandler;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $subscriberEditHandler 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 testSubscriberEditedSuccessfully()
45
    {
46
        $subscriberEditHandler = $this->getSubscriberEditHandlerMock('{"status":"OK"}');
47
        self::assertNull($subscriberEditHandler->editSubscriber('Test', 'Test'));
48
    }
49
50
    public function testApiEndpoint()
51
    {
52
        $subscriberEditHandler = new SubscriberEditHandler(new ErrorHandler(), '', '');
53
        $expectedApiEndpoint = '/rest/subscriber/edit';
54
        $returnedApiEndpoint = $this->getApiEndpoint($subscriberEditHandler);
55
        self::assertEquals($expectedApiEndpoint, $returnedApiEndpoint);
56
    }
57
58
    public function testSubscriberDoesntExist()
59
    {
60
        $subscriberEditHandler = $this->getSubscriberEditHandlerMock(
61
            '{"errors":[{ "message":"The subscriber doesnt exist", "code":"1331" }], "status":"errors"}'
62
        );
63
        $this->expectException(FreshMailSubscriberException::class);
64
        $subscriberEditHandler->editSubscriber('Test', 'Test');
65
    }
66
67
    public function testIncorrectList()
68
    {
69
        $subscriberEditHandler = $this->getSubscriberEditHandlerMock(
70
            '{"errors":[{ "message":"The subscriber list doesnt exist", "code":"1302" }], "status":"errors"}'
71
        );
72
        $this->expectException(FreshMailSubscriberException::class);
73
        $subscriberEditHandler->editSubscriber('Test', 'Test');
74
    }
75
76
    public function testIncorrectStatus()
77
    {
78
        $subscriberEditHandler = $this->getSubscriberEditHandlerMock(
79
            '{"errors":[{ "message":"Incorrect subscriber status", "code":"1305" }], "status":"errors"}'
80
        );
81
        $this->expectException(FreshMailSubscriberException::class);
82
        $subscriberEditHandler->editSubscriber('Test', 'Test');
83
    }
84
}
85