1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Queryr\Serialization; |
4
|
|
|
|
5
|
|
|
use Queryr\Resources\PropertyList; |
6
|
|
|
use Queryr\Resources\PropertyListElement; |
7
|
|
|
use Queryr\Serialization\SerializerFactory; |
8
|
|
|
use Wikibase\DataModel\Entity\PropertyId; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @covers Queryr\Serialization\PropertyListSerializer |
12
|
|
|
* |
13
|
|
|
* @licence GNU GPL v2+ |
14
|
|
|
* @author Jeroen De Dauw < [email protected] > |
15
|
|
|
*/ |
16
|
|
|
class PropertyListSerializerTest extends \PHPUnit_Framework_TestCase { |
17
|
|
|
|
18
|
|
|
public function testGivenNonItem_exceptionIsThrown() { |
19
|
|
|
$serializer = ( new SerializerFactory() )->newPropertyListSerializer(); |
20
|
|
|
|
21
|
|
|
$this->setExpectedException( 'Serializers\Exceptions\UnsupportedObjectException' ); |
|
|
|
|
22
|
|
|
$serializer->serialize( null ); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testSerialize() { |
26
|
|
|
$input = new PropertyList( [ |
27
|
|
|
new PropertyListElement( |
28
|
|
|
new PropertyId( 'P1' ), |
29
|
|
|
'number', |
30
|
|
|
'http://www.wikidata.org/entity/P1', |
31
|
|
|
'http://api.queryr.com/properties/P1' |
32
|
|
|
), |
33
|
|
|
new PropertyListElement( |
34
|
|
|
new PropertyId( 'P2' ), |
35
|
|
|
'string', |
36
|
|
|
'http://www.wikidata.org/entity/P2', |
37
|
|
|
'http://api.queryr.com/properties/P2' |
38
|
|
|
) |
39
|
|
|
] ); |
40
|
|
|
|
41
|
|
|
$expected = [ |
42
|
|
|
[ |
43
|
|
|
'id' => 'P1', |
44
|
|
|
'type' => 'number', |
45
|
|
|
'url' => 'http://api.queryr.com/properties/P1', |
46
|
|
|
'wikidata_url' => 'http://www.wikidata.org/entity/P1', |
47
|
|
|
], |
48
|
|
|
[ |
49
|
|
|
'id' => 'P2', |
50
|
|
|
'type' => 'string', |
51
|
|
|
'url' => 'http://api.queryr.com/properties/P2', |
52
|
|
|
'wikidata_url' => 'http://www.wikidata.org/entity/P2', |
53
|
|
|
] |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
$output = ( new SerializerFactory() )->newPropertyListSerializer()->serialize( $input ); |
57
|
|
|
|
58
|
|
|
$this->assertSame( $expected, $output ); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
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.