ItemListSerializerTest::testSerialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 38
rs 9.312
c 0
b 0
f 0
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' );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

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.

Loading history...
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