testSerializationForDe()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
namespace Tests\Queryr\Resources\Builders;
4
5
use Queryr\Resources\Builders\SimplePropertyBuilder;
6
use Queryr\Resources\SimpleProperty;
7
use Wikibase\DataModel\Entity\Property;
8
use Wikibase\DataModel\Term\Fingerprint;
9
10
/**
11
 * @covers Queryr\Resources\Builders\SimplePropertyBuilder
12
 *
13
 * @licence GNU GPL v2+
14
 * @author Jeroen De Dauw < [email protected] >
15
 */
16
class SimplePropertyBuilderTest extends \PHPUnit_Framework_TestCase {
17
18
	private function newProperty() {
19
		$property = Property::newFromType( 'kittens' );
20
21
		$property->setId( 1337 );
22
23
		$property->setFingerprint( $this->newFingerprint() );
24
25
		return $property;
26
	}
27
28
	private function newFingerprint() {
29
		$fingerprint = new Fingerprint();
30
31
		$fingerprint->setLabel( 'en', 'foo' );
32
		$fingerprint->setLabel( 'de', 'bar' );
33
		$fingerprint->setLabel( 'nl', 'baz' );
34
35
		$fingerprint->setDescription( 'de', 'de description' );
36
37
		$fingerprint->setAliasGroup( 'en', [ 'first en alias', 'second en alias' ] );
38
		$fingerprint->setAliasGroup( 'de', [ 'first de alias', 'second de alias' ] );
39
40
		return $fingerprint;
41
	}
42
43
	public function testSerializationForDe() {
44
		$simpleProperty = $this->buildNewSimplePropertyForLanguage( 'de' );
45
46
		$expected = new SimpleProperty();
47
		$expected->ids = [
0 ignored issues
show
Documentation Bug introduced by
It seems like array('wikidata' => 'P1337') 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...
48
			'wikidata' => 'P1337',
49
		];
50
51
		$expected->label = 'bar';
52
		$expected->description = 'de description';
53
		$expected->aliases = [ 'first de alias', 'second de alias' ];
54
55
		$expected->type = 'kittens';
56
57
		$this->assertEquals( $expected, $simpleProperty );
58
	}
59
60
	private function buildNewSimplePropertyForLanguage( $languageCode ) {
61
		$labelLookup = $this->getMock( 'Queryr\Resources\Builders\ResourceLabelLookup' );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0; use createMock() or getMockBuilder() 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...
62
63
		$labelLookup->expects( $this->any() )
64
			->method( 'getLabelByIdAndLanguage' )
65
			->will( $this->returnValue( 'awesome label' ) );
66
67
		$propertyBuilder = new SimplePropertyBuilder( $languageCode );
68
69
		return $propertyBuilder->buildFromProperty( $this->newProperty() );
70
	}
71
72
	public function testSerializationForEn() {
73
		$simpleProperty = $this->buildNewSimplePropertyForLanguage( 'en' );
74
75
		$expected = new SimpleProperty();
76
		$expected->ids = [
0 ignored issues
show
Documentation Bug introduced by
It seems like array('wikidata' => 'P1337') 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...
77
			'wikidata' => 'P1337',
78
		];
79
80
		$expected->label = 'foo';
81
		$expected->aliases = [ 'first en alias', 'second en alias' ];
82
83
		$expected->type = 'kittens';
84
85
		$this->assertEquals( $expected, $simpleProperty );
86
	}
87
88
	public function testSerializationForNl() {
89
		$simpleProperty = $this->buildNewSimplePropertyForLanguage( 'nl' );
90
91
		$expected = new SimpleProperty();
92
		$expected->ids = [
0 ignored issues
show
Documentation Bug introduced by
It seems like array('wikidata' => 'P1337') 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...
93
			'wikidata' => 'P1337',
94
		];
95
96
		$expected->label = 'baz';
97
98
		$expected->type = 'kittens';
99
100
		$this->assertEquals( $expected, $simpleProperty );
101
	}
102
103
}
104