Failed Conditions
Pull Request — master (#25)
by Chad
02:50
created

DataContainerTest::basicUsage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 16
nc 1
nop 0
1
<?php
2
3
namespace Chadicus\Marvel\Api;
4
5
/**
6
 * @coversDefaultClass \Chadicus\Marvel\Api\DataContainer
7
 * @covers ::<private>
8
 * @covers ::__construct
9
 */
10
final class DataContainerTest extends \PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * Verifies basic behaviour of the DataContainer class
14
     *
15
     * @test
16
     * @covers ::getOffset
17
     * @covers ::getLimit
18
     * @covers ::getTotal
19
     * @covers ::getCount
20
     * @covers ::getResults
21
     *
22
     * @return void
23
     */
24
    public function basicUsage()
25
    {
26
        $data = [
27
            'offset' => 0,
28
            'limit' => 1,
29
            'total' => 1,
30
            'count' => 1,
31
            'results' => [['id' => 1, 'resourceURI' => Client::BASE_URL . 'characters/1']],
32
        ];
33
34
        $container = new DataContainer($data);
35
        $this->assertSame($data['offset'], $container->getOffset());
36
        $this->assertSame($data['limit'], $container->getLimit());
37
        $this->assertSame($data['total'], $container->getTotal());
38
        $this->assertSame($data['count'], $container->getCount());
39
        $this->assertSame(1, count($container->getResults()));
40
        $characters = $container->getResults();
41
        $this->assertInstanceOf('\Chadicus\Marvel\Api\Entities\Character', $characters[0]);
42
        $this->assertSame(1, $characters[0]->getId());
43
    }
44
45
    /**
46
     * Verifies behaviour of __construct when $input is empty.
47
     *
48
     * @test
49
     *
50
     * @return void
51
     */
52
    public function constructDefaults()
53
    {
54
        $container = new DataContainer([]);
55
        $this->assertSame(0, $container->getOffset());
56
        $this->assertSame(0, $container->getLimit());
57
        $this->assertSame(0, $container->getTotal());
58
        $this->assertSame(0, $container->getCount());
59
        $this->assertSame([], $container->getResults());
60
    }
61
62
    /**
63
     * Verifies behaviour of __construct when $input['results']['resourceURI'] is null.
64
     *
65
     * @test
66
     *
67
     * @return void
68
     */
69 View Code Duplication
    public function constructNullResourceURI()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
    {
71
        $container = new DataContainer(
72
            [
73
                'results' => [
74
                    [
75
                        'resourceURI' => null,
76
                    ],
77
                ],
78
            ]
79
        );
80
        $this->assertSame([], $container->getResults());
81
    }
82
83
    /**
84
     * Verifies behaviour of __construct when $input['results']['resourceURI'] does not match the regex pattern.
85
     *
86
     * @test
87
     *
88
     * @return void
89
     */
90 View Code Duplication
    public function constructInvalidResourceURI()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
91
    {
92
        $container = new DataContainer(
93
            [
94
                'results' => [
95
                    [
96
                        'resourceURI' => 'http://example.com',
97
                    ],
98
                ],
99
            ]
100
        );
101
        $this->assertSame([], $container->getResults());
102
    }
103
}
104