|
1
|
|
|
<?php |
|
2
|
|
|
namespace Chadicus\Marvel\Api\Entities; |
|
3
|
|
|
|
|
4
|
|
|
use Chadicus\Marvel\Api\Client; |
|
5
|
|
|
use Chadicus\Marvel\Api\Assets\CharacterAdapter; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Unit tests for the Character class. |
|
9
|
|
|
* |
|
10
|
|
|
* @coversDefaultClass \Chadicus\Marvel\Api\Entities\Character |
|
11
|
|
|
* @covers ::<protected> |
|
12
|
|
|
*/ |
|
13
|
|
|
final class CharacterTest extends \PHPUnit_Framework_TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Verify properties are set properly. |
|
17
|
|
|
* |
|
18
|
|
|
* @test |
|
19
|
|
|
* |
|
20
|
|
|
* @return void |
|
21
|
|
|
*/ |
|
22
|
|
|
public function construct() |
|
23
|
|
|
{ |
|
24
|
|
|
$client = new Client('not under test', 'not under test', new CharacterAdapter()); |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
$now = new \DateTime(); |
|
27
|
|
|
|
|
28
|
|
|
$data = [ |
|
29
|
|
|
'id' => 1, |
|
30
|
|
|
'name' => 'a name', |
|
31
|
|
|
'description' => 'a description', |
|
32
|
|
|
'modified' => $now->format('r'), |
|
33
|
|
|
'resourceURI' => 'a resource uri', |
|
34
|
|
|
'urls' => [['type' => 'a type', 'url' => 'a url']], |
|
35
|
|
|
'thumbnail' => ['path' => 'a path', 'extension' => 'an extension'], |
|
36
|
|
|
'comics' => [ |
|
37
|
|
|
'available' => 2, |
|
38
|
|
|
'returned' => 1, |
|
39
|
|
|
'collectionURI' => 'a comics collection uri', |
|
40
|
|
|
'items' => [['resourceURI' => 'a comics resource uri', 'name' => 'a comics name']], |
|
41
|
|
|
], |
|
42
|
|
|
'stories' => [ |
|
43
|
|
|
'available' => 2, |
|
44
|
|
|
'returned' => 1, |
|
45
|
|
|
'collectionURI' => 'a stories collection uri', |
|
46
|
|
|
'items' => [['resourceURI' => 'a stories resource uri', 'name' => 'a stories name']], |
|
47
|
|
|
], |
|
48
|
|
|
'events' => [ |
|
49
|
|
|
'available' => 2, |
|
50
|
|
|
'returned' => 1, |
|
51
|
|
|
'collectionURI' => 'a events collection uri', |
|
52
|
|
|
'items' => [['resourceURI' => 'a events resource uri', 'name' => 'a events name']], |
|
53
|
|
|
], |
|
54
|
|
|
'series' => [ |
|
55
|
|
|
'available' => 2, |
|
56
|
|
|
'returned' => 1, |
|
57
|
|
|
'collectionURI' => 'a series collection uri', |
|
58
|
|
|
'items' => [['resourceURI' => 'a series resource uri', 'name' => 'a series name']], |
|
59
|
|
|
], |
|
60
|
|
|
]; |
|
61
|
|
|
|
|
62
|
|
|
$character = new Character($data); |
|
63
|
|
|
$this->assertSame(1, $character->getId()); |
|
|
|
|
|
|
64
|
|
|
$this->assertSame('a name', $character->getName()); |
|
|
|
|
|
|
65
|
|
|
$this->assertSame('a description', $character->getDescription()); |
|
|
|
|
|
|
66
|
|
|
$this->assertSame($now->getTimestamp(), $character->getModified()->getTimestamp()); |
|
|
|
|
|
|
67
|
|
|
$this->assertSame('a resource uri', $character->getResourceURI()); |
|
|
|
|
|
|
68
|
|
|
$this->assertSame(1, count($character->getUrls())); |
|
|
|
|
|
|
69
|
|
|
$this->assertSame('a type', $character->getUrls()[0]->getType()); |
|
|
|
|
|
|
70
|
|
|
$this->assertSame('a url', $character->getUrls()[0]->getUrl()); |
|
|
|
|
|
|
71
|
|
|
$this->assertSame('a path', $character->getThumbnail()->getPath()); |
|
|
|
|
|
|
72
|
|
|
$this->assertSame('an extension', $character->getThumbnail()->getExtension()); |
|
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
$this->assertSame(2, $character->getComics()->getAvailable()); |
|
|
|
|
|
|
75
|
|
|
$this->assertSame(1, $character->getComics()->getReturned()); |
|
|
|
|
|
|
76
|
|
|
$this->assertSame('a comics collection uri', $character->getComics()->getCollectionURI()); |
|
|
|
|
|
|
77
|
|
|
$this->assertSame(1, count($character->getComics()->getItems())); |
|
|
|
|
|
|
78
|
|
|
$this->assertSame('a comics resource uri', $character->getComics()->getItems()[0]->getResourceURI()); |
|
|
|
|
|
|
79
|
|
|
$this->assertSame('a comics name', $character->getComics()->getItems()[0]->getName()); |
|
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
$this->assertSame(2, $character->getStories()->getAvailable()); |
|
|
|
|
|
|
82
|
|
|
$this->assertSame(1, $character->getStories()->getReturned()); |
|
|
|
|
|
|
83
|
|
|
$this->assertSame(1, count($character->getStories()->getItems())); |
|
|
|
|
|
|
84
|
|
|
$this->assertSame('a stories resource uri', $character->getStories()->getItems()[0]->getResourceURI()); |
|
|
|
|
|
|
85
|
|
|
$this->assertSame('a stories name', $character->getStories()->getItems()[0]->getName()); |
|
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
$this->assertSame(2, $character->getEvents()->getAvailable()); |
|
|
|
|
|
|
88
|
|
|
$this->assertSame(1, $character->getEvents()->getReturned()); |
|
|
|
|
|
|
89
|
|
|
$this->assertSame('a events collection uri', $character->getEvents()->getCollectionURI()); |
|
|
|
|
|
|
90
|
|
|
$this->assertSame(1, count($character->getEvents()->getItems())); |
|
|
|
|
|
|
91
|
|
|
$this->assertSame('a events resource uri', $character->getEvents()->getItems()[0]->getResourceURI()); |
|
|
|
|
|
|
92
|
|
|
$this->assertSame('a events name', $character->getEvents()->getItems()[0]->getName()); |
|
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
$this->assertSame(2, $character->getSeries()->getAvailable()); |
|
|
|
|
|
|
95
|
|
|
$this->assertSame(1, $character->getSeries()->getReturned()); |
|
|
|
|
|
|
96
|
|
|
$this->assertSame('a series collection uri', $character->getSeries()->getCollectionURI()); |
|
|
|
|
|
|
97
|
|
|
$this->assertSame(1, count($character->getSeries()->getItems())); |
|
|
|
|
|
|
98
|
|
|
$this->assertSame('a series resource uri', $character->getSeries()->getItems()[0]->getResourceURI()); |
|
|
|
|
|
|
99
|
|
|
$this->assertSame('a series name', $character->getSeries()->getItems()[0]->getName()); |
|
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Verify basic behavior of findAll(). |
|
104
|
|
|
* |
|
105
|
|
|
* @test |
|
106
|
|
|
* @covers ::findAll |
|
107
|
|
|
* |
|
108
|
|
|
* @return void |
|
109
|
|
|
*/ |
|
110
|
|
|
public function findAll() |
|
111
|
|
|
{ |
|
112
|
|
|
$client = new Client('not under test', 'not under test', new CharacterAdapter()); |
|
113
|
|
|
$characters = Character::findAll($client); |
|
114
|
|
|
|
|
115
|
|
|
$this->assertSame(5, $characters->count()); |
|
116
|
|
|
foreach ($characters as $key => $character) { |
|
117
|
|
|
$this->assertSame($key, $character->getId()); |
|
118
|
|
|
$this->assertSame("a name for character {$key}", $character->getName()); |
|
119
|
|
|
$this->assertSame("a description for character {$key}", $character->getDescription()); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Verify query parameters are set properly with findAll(). |
|
125
|
|
|
* |
|
126
|
|
|
* @test |
|
127
|
|
|
* @covers ::findAll |
|
128
|
|
|
* |
|
129
|
|
|
* @return void |
|
130
|
|
|
*/ |
|
131
|
|
|
public function findAllParametersSetProperly() |
|
132
|
|
|
{ |
|
133
|
|
|
$now = new \DateTime(); |
|
134
|
|
|
$criteria = [ |
|
135
|
|
|
'name' => 'a name', |
|
136
|
|
|
'modifiedSince' => $now->format('r'), |
|
137
|
|
|
'comics' => [1,2,3], |
|
138
|
|
|
'series' => [2,4,6], |
|
139
|
|
|
'events' => [1,3,5], |
|
140
|
|
|
'stories' => [7,8,9], |
|
141
|
|
|
'orderBy' => 'name', |
|
142
|
|
|
]; |
|
143
|
|
|
$adapter = new CharacterAdapter(); |
|
144
|
|
|
$client = new Client('not under test', 'not under test', $adapter); |
|
145
|
|
|
$characters = Character::findAll($client, $criteria); |
|
146
|
|
|
|
|
147
|
|
|
$characters->next(); |
|
148
|
|
|
|
|
149
|
|
|
$expectedParameters = [ |
|
150
|
|
|
'name' => 'a name', |
|
151
|
|
|
'modifiedSince' => $now->format('c'), |
|
152
|
|
|
'comics' => '1,2,3', |
|
153
|
|
|
'series' => '2,4,6', |
|
154
|
|
|
'events' => '1,3,5', |
|
155
|
|
|
'stories' => '7,8,9', |
|
156
|
|
|
'orderBy' => 'name', |
|
157
|
|
|
]; |
|
158
|
|
|
|
|
159
|
|
|
foreach ($expectedParameters as $key => $value) { |
|
160
|
|
|
$this->assertSame($value, $adapter->parameters[$key]); |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.