1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Queryr\Serialization; |
4
|
|
|
|
5
|
|
|
use DataValues\NumberValue; |
6
|
|
|
use DataValues\StringValue; |
7
|
|
|
use Queryr\Resources\SimpleItem; |
8
|
|
|
use Queryr\Resources\SimpleStatement; |
9
|
|
|
use Queryr\Serialization\SerializerFactory; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @covers Queryr\Serialization\SimpleItemSerializer |
13
|
|
|
* |
14
|
|
|
* @licence GNU GPL v2+ |
15
|
|
|
* @author Jeroen De Dauw < [email protected] > |
16
|
|
|
*/ |
17
|
|
|
class SimpleItemSerializerTest extends \PHPUnit_Framework_TestCase { |
18
|
|
|
|
19
|
|
|
public function testGivenNonItem_exceptionIsThrown() { |
20
|
|
|
$serializer = ( new SerializerFactory() )->newSimpleItemSerializer(); |
21
|
|
|
|
22
|
|
|
$this->setExpectedException( 'Serializers\Exceptions\UnsupportedObjectException' ); |
|
|
|
|
23
|
|
|
$serializer->serialize( null ); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
private function newSimpleItem() { |
27
|
|
|
$item = new SimpleItem(); |
28
|
|
|
|
29
|
|
|
$item->ids = [ |
|
|
|
|
30
|
|
|
'wikidata' => 'Q1337', |
31
|
|
|
'en.wikipedia' => 'Kitten', |
32
|
|
|
'de.wikipedia' => 'Katzen', |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
$item->label = 'kittens'; |
36
|
|
|
$item->description = 'lots of kittens'; |
37
|
|
|
$item->aliases = [ 'cats' ]; |
38
|
|
|
|
39
|
|
|
$item->statements = [ |
40
|
|
|
SimpleStatement::newInstance() |
41
|
|
|
->withPropertyName( 'fluffiness' ) |
42
|
|
|
->withType( 'number' ) |
43
|
|
|
->withValues( [ new NumberValue( 9001 ) ] ), |
44
|
|
|
|
45
|
|
|
SimpleStatement::newInstance() |
46
|
|
|
->withPropertyName( 'awesome' ) |
47
|
|
|
->withType( 'string' ) |
48
|
|
|
->withValues( [ new StringValue( 'Jeroen' ), new StringValue( 'Abraham' ) ] ), |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
return $item; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testSerializationWithValueForOneProperty() { |
55
|
|
|
$serializer = ( new SerializerFactory() )->newSimpleItemSerializer(); |
56
|
|
|
$serialized = $serializer->serialize( $this->newSimpleItem() ); |
57
|
|
|
|
58
|
|
|
$expected = [ |
59
|
|
|
'id' => [ |
60
|
|
|
'wikidata' => 'Q1337', |
61
|
|
|
'en.wikipedia' => 'Kitten', |
62
|
|
|
'de.wikipedia' => 'Katzen', |
63
|
|
|
], |
64
|
|
|
|
65
|
|
|
'label' => 'kittens', |
66
|
|
|
'description' => 'lots of kittens', |
67
|
|
|
'aliases' => [ 'cats' ], |
68
|
|
|
|
69
|
|
|
'data' => [ |
70
|
|
|
'fluffiness' => [ |
71
|
|
|
'value' => 9001, |
72
|
|
|
'type' => 'number' |
73
|
|
|
], |
74
|
|
|
'awesome' => [ |
75
|
|
|
'value' => 'Jeroen', |
76
|
|
|
'values' => [ 'Jeroen', 'Abraham' ], |
77
|
|
|
'type' => 'string' |
78
|
|
|
], |
79
|
|
|
] |
80
|
|
|
]; |
81
|
|
|
|
82
|
|
|
$this->assertEquals( $expected, $serialized ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.