testGivenNonItem_exceptionIsThrown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Tests\Queryr\Serialization;
4
5
use Queryr\Resources\SimpleProperty;
6
use Queryr\Serialization\SerializerFactory;
7
8
/**
9
 * @covers Queryr\Serialization\SimplePropertySerializer
10
 *
11
 * @licence GNU GPL v2+
12
 * @author Jeroen De Dauw < [email protected] >
13
 */
14
class SimplePropertySerializerTest extends \PHPUnit_Framework_TestCase {
15
16
	public function testGivenNonItem_exceptionIsThrown() {
17
		$serializer = ( new SerializerFactory() )->newSimplePropertySerializer();
18
19
		$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...
20
		$serializer->serialize( null );
21
	}
22
23
	private function newSimpleProperty() {
24
		$property = new SimpleProperty();
25
26
		$property->ids = [
0 ignored issues
show
Documentation Bug introduced by
It seems like array('wikidata' => 'Q1337') of type array<string,string,{"wikidata":"string"}> is incompatible with the declared type array<integer,string> of property $ids.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
27
			'wikidata' => 'Q1337',
28
		];
29
30
		$property->label = 'kittens';
31
		$property->description = 'lots of kittens';
32
		$property->aliases = [ 'cats' ];
33
34
		$property->type = 'awesome';
35
36
		return $property;
37
	}
38
39
	public function testSerializationWithValueForOneProperty() {
40
		$serializer = ( new SerializerFactory() )->newSimplePropertySerializer();
41
		$serialized = $serializer->serialize( $this->newSimpleProperty() );
42
43
		$expected = [
44
			'id' => [
45
				'wikidata' => 'Q1337',
46
			],
47
48
			'label' => 'kittens',
49
			'description' => 'lots of kittens',
50
			'aliases' => [ 'cats' ],
51
52
			'type' => 'awesome',
53
		];
54
55
		$this->assertEquals( $expected, $serialized );
56
	}
57
58
}
59