1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Queryr\Serialization; |
4
|
|
|
|
5
|
|
|
use Queryr\Resources\ItemList; |
6
|
|
|
use Queryr\Resources\ItemListElement; |
7
|
|
|
use Queryr\Serialization\SerializerFactory; |
8
|
|
|
use Wikibase\DataModel\Entity\ItemId; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @covers Queryr\Serialization\ItemListSerializer |
12
|
|
|
* |
13
|
|
|
* @licence GNU GPL v2+ |
14
|
|
|
* @author Jeroen De Dauw < [email protected] > |
15
|
|
|
*/ |
16
|
|
|
class ItemListSerializerTest extends \PHPUnit_Framework_TestCase { |
17
|
|
|
|
18
|
|
|
public function testGivenNonItem_exceptionIsThrown() { |
19
|
|
|
$serializer = ( new SerializerFactory() )->newItemListSerializer(); |
20
|
|
|
|
21
|
|
|
$this->setExpectedException( 'Serializers\Exceptions\UnsupportedObjectException' ); |
|
|
|
|
22
|
|
|
$serializer->serialize( null ); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testSerialize() { |
26
|
|
|
$input = new ItemList( [ |
27
|
|
|
( new ItemListElement() ) |
28
|
|
|
->setItemId( new ItemId( 'Q1' ) ) |
29
|
|
|
->setLastUpdate( '2014-08-16T19:52:04Z' ) |
30
|
|
|
->setWikidataPageUrl( 'http://www.wikidata.org/entity/Q1' ) |
31
|
|
|
->setQueryrApiUrl( 'http://api.queryr.com/items/Q1' ), |
32
|
|
|
|
33
|
|
|
( new ItemListElement() ) |
34
|
|
|
->setItemId( new ItemId( 'Q2' ) ) |
35
|
|
|
->setLastUpdate( '2014-05-30T16:31:27Z' ) |
36
|
|
|
->setWikidataPageUrl( 'http://www.wikidata.org/entity/Q2' ) |
37
|
|
|
->setQueryrApiUrl( 'http://api.queryr.com/items/Q2' ) |
38
|
|
|
->setLabel( 'kittens' ) |
39
|
|
|
->setWikipediaPageUrl( 'foo' ) |
40
|
|
|
] ); |
41
|
|
|
|
42
|
|
|
$expected = [ |
43
|
|
|
[ |
44
|
|
|
'id' => 'Q1', |
45
|
|
|
'updated_at' => '2014-08-16T19:52:04Z', |
46
|
|
|
'url' => 'http://api.queryr.com/items/Q1', |
47
|
|
|
'wikidata_url' => 'http://www.wikidata.org/entity/Q1', |
48
|
|
|
], |
49
|
|
|
[ |
50
|
|
|
'id' => 'Q2', |
51
|
|
|
'label' => 'kittens', |
52
|
|
|
'updated_at' => '2014-05-30T16:31:27Z', |
53
|
|
|
'url' => 'http://api.queryr.com/items/Q2', |
54
|
|
|
'wikidata_url' => 'http://www.wikidata.org/entity/Q2', |
55
|
|
|
'wikipedia_url' => 'foo', |
56
|
|
|
] |
57
|
|
|
]; |
58
|
|
|
|
59
|
|
|
$output = ( new SerializerFactory() )->newItemListSerializer()->serialize( $input ); |
60
|
|
|
|
61
|
|
|
$this->assertEquals( $expected, $output ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
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.