Collection   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testExtraProperties() 0 28 1
A testCreateCollection() 0 16 1
A testCreateCollectionWithNoData() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Mapado\RestClientSdk\Tests\Units\Collection;
6
7
use atoum;
8
9
/**
10
 * Collection
11
 *
12
 * @uses   \atoum
13
 *
14
 * @author Florent Clerc <[email protected]>
15
 */
16
class Collection extends atoum
17
{
18
    /**
19
     * testCreateCollection
20
     */
21
    public function testCreateCollection()
22
    {
23
        $json = json_decode(file_get_contents(__DIR__ . '/../../data/ticketing.list.json'), true);
24
25
        $this
26
            ->given($collection = new \Mapado\RestClientSdk\Collection\Collection($json['hydra:member']))
27
28
            ->then
29
            ->object($collection)
30
            ->isInstanceOf('Mapado\RestClientSdk\Collection\Collection')
31
            ->isInstanceOf('\Traversable')
32
            ->hasSize(6)
33
            ->and
34
            ->integer($collection->getTotalItems())->isEqualTo(6)
35
            ->and
36
            ->array($collection->toArray())->isEqualTo($json['hydra:member'])
37
            ;
38
    }
39
40
    public function testCreateCollectionWithNoData()
41
    {
42
        $this
43
            ->given($collection = new \Mapado\RestClientSdk\Collection\Collection())
44
45
            ->then
46
            ->object($collection)
47
            ->isInstanceOf('Mapado\RestClientSdk\Collection\Collection')
48
            ->hasSize(0)
49
        ;
50
    }
51
52
    public function testExtraProperties()
53
    {
54
        $json = json_decode(file_get_contents(__DIR__ . '/../../data/ticketing.list.json'), true);
55
56
        $extraProperties = ['foo' => 'bar', 'baz' => 'baz'];
57
        $this
58
            ->given($this->newTestedInstance(
59
                $json['hydra:member'],
60
                $extraProperties
61
            ))
62
            ->object($this->testedInstance)
63
                ->isInstanceOf('Mapado\RestClientSdk\Collection\Collection')
64
                ->isInstanceOf('\Traversable')
65
                ->hasSize(6)
66
            ->and
67
                ->integer($this->testedInstance->getTotalItems())->isEqualTo(6)
68
            ->and
69
                ->array($this->testedInstance->toArray())->isEqualTo($json['hydra:member'])
70
71
            ->and
72
                ->array($this->testedInstance->getExtraProperties())
73
                    ->isEqualTo($extraProperties)
74
75
                ->string($this->testedInstance->getExtraProperty('foo'))
76
                    ->isEqualTo('bar')
77
78
                ->variable($this->testedInstance->getExtraProperty('foobarbaz'))
79
                    ->isNull()
80
        ;
81
    }
82
}
83