ListsGetHandlerTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testListsPulledSuccessfully() 0 23 1
A testApiEndpoint() 0 6 1
A getListsGetHandlerMock() 0 12 1
1
<?php
2
/**
3
 * File: ListsGetHandlerTest.php
4
 *
5
 * @author      Maciej Sławik <[email protected]>
6
 * Github:      https://github.com/maciejslawik
7
 */
8
9
namespace MSlwk\FreshMail\Test\Lists;
10
11
use MSlwk\FreshMail\Handler\Lists\ListsGetHandler;
12
use MSlwk\FreshMail\Tests\BaseTest;
13
use PHPUnit\Framework\TestCase;
14
use MSlwk\FreshMail\Error\ErrorHandler;
15
16
/**
17
 * Class ListsGetHandlerTest
18
 *
19
 * @package MSlwk\FreshMail\Test\Lists
20
 */
21
class ListsGetHandlerTest extends TestCase
22
{
23
    use BaseTest;
24
25
    /**
26
     * @param $sendRequestReturnValue
27
     * @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...
28
     */
29
    public function getListsGetHandlerMock($sendRequestReturnValue)
30
    {
31
        $listsGetHandler = $this->getMockBuilder('\MSlwk\FreshMail\Handler\Lists\ListsGetHandler')
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

31
        $listsGetHandler = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder('\MSlwk\FreshMail\Handler\Lists\ListsGetHandler')

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...
32
            ->setConstructorArgs([new ErrorHandler(), '', ''])
33
            ->setMethods(['sendRequest'])
34
            ->getMock();
35
36
        $listsGetHandler->expects($this->once())
37
            ->method('sendRequest')
38
            ->will($this->returnValue($sendRequestReturnValue));
39
40
        return $listsGetHandler;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $listsGetHandler returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the documented return type PHPUnit_Framework_MockObject_MockObject.
Loading history...
41
    }
42
43
    public function testListsPulledSuccessfully()
44
    {
45
        $expectedListsPulled = [
46
            (object) [
47
                'hash' => '4124521421',
48
                'name' => 'h4htrbg',
49
                'description' => '145r3fgrvfe',
50
                'creation_date' => '41253525teegf',
51
                'subscribers_number' => 2
52
            ],
53
            (object) [
54
                'hash' => 'vsdv',
55
                'name' => 'cbcsxb',
56
                'description' => 'czvczv',
57
                'creation_date' => 'byr6j5',
58
                'subscribers_number' => 5
59
            ],
60
        ];
61
        $listsGetHandler = $this->getListsGetHandlerMock(
62
            '{"status":"OK","lists":' . json_encode($expectedListsPulled) . '}'
63
        );
64
        $returnedData = $listsGetHandler->getSubscriberLists();
65
        self::assertEquals($expectedListsPulled, $returnedData);
66
    }
67
68
    public function testApiEndpoint()
69
    {
70
        $listCreateHandler = new ListsGetHandler(new ErrorHandler(), '', '');
71
        $expectedApiEndpoint = '/rest/subscribers_list/lists';
72
        $returnedApiEndpoint = $this->getApiEndpoint($listCreateHandler);
73
        self::assertEquals($expectedApiEndpoint, $returnedApiEndpoint);
74
    }
75
}
76