Completed
Pull Request — master (#53)
by Julien
02:22
created

Collection::testExtraProperties()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

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