|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace EllipseSynergie\ApiResponse\Tests\Serializer; |
|
4
|
|
|
|
|
5
|
|
|
use EllipseSynergie\ApiResponse\Serializer\Serializer; |
|
6
|
|
|
use PHPUnit_Framework_TestCase; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class SerializerTest |
|
10
|
|
|
* @package EllipseSynergie\ApiResponse\Tests\Serializer |
|
11
|
|
|
* @author Maxime Beaudoin <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class SerializerTest extends PHPUnit_Framework_TestCase |
|
14
|
|
|
{ |
|
15
|
|
View Code Duplication |
public function testCollectionWithDefaultResourceKey() |
|
16
|
|
|
{ |
|
17
|
|
|
$data = ['foo']; |
|
18
|
|
|
$serializer = new Serializer(); |
|
19
|
|
|
$result = $serializer->collection(null, $data); |
|
20
|
|
|
|
|
21
|
|
|
$this->assertSame(['data' => $data], $result); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
View Code Duplication |
public function testCollectionWithCustomResourceKey() |
|
25
|
|
|
{ |
|
26
|
|
|
$data = ['foo']; |
|
27
|
|
|
$serializer = new Serializer(); |
|
28
|
|
|
$result = $serializer->collection('custom', $data); |
|
29
|
|
|
|
|
30
|
|
|
$this->assertSame(['custom' => $data], $result); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
View Code Duplication |
public function testCollectionWithOptionalResourceKey() |
|
34
|
|
|
{ |
|
35
|
|
|
$data = ['foo']; |
|
36
|
|
|
$serializer = new OptionalKeySerializer(); |
|
37
|
|
|
$result = $serializer->collection(null, $data); |
|
38
|
|
|
|
|
39
|
|
|
$this->assertSame($data, $result); |
|
40
|
|
|
|
|
41
|
|
|
$result = $serializer->collection('optional', $data); |
|
42
|
|
|
|
|
43
|
|
|
$this->assertSame(['optional' => $data], $result); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
View Code Duplication |
public function testItemWithDefaultResourceKey() |
|
47
|
|
|
{ |
|
48
|
|
|
$data = ['foo']; |
|
49
|
|
|
$serializer = new Serializer(); |
|
50
|
|
|
$result = $serializer->item(null, $data); |
|
51
|
|
|
|
|
52
|
|
|
$this->assertSame(['data' => $data], $result); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
View Code Duplication |
public function testItemWithCustomResourceKey() |
|
56
|
|
|
{ |
|
57
|
|
|
$data = ['foo']; |
|
58
|
|
|
$serializer = new Serializer(); |
|
59
|
|
|
$result = $serializer->collection('custom', $data); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertSame(['custom' => $data], $result); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
View Code Duplication |
public function testItemWithOptionalResourceKey() |
|
65
|
|
|
{ |
|
66
|
|
|
$data = ['foo']; |
|
67
|
|
|
$serializer = new OptionalKeySerializer(); |
|
68
|
|
|
$result = $serializer->item(null, $data); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertSame($data, $result); |
|
71
|
|
|
|
|
72
|
|
|
$result = $serializer->item('optional', $data); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertSame(['optional' => $data], $result); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|