Passed
Push — Facets ( b72148...68bbc0 )
by Daniel
07:49 queued 03:58
created

SnakTest::testListFacets()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Wikibase\DataModel\Tests\Snak;
4
5
use DataValues\NumberValue;
6
use DataValues\StringValue;
7
use Wikibase\DataModel\Entity\PropertyId;
8
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
9
use Wikibase\DataModel\Snak\PropertySomeValueSnak;
10
use Wikibase\DataModel\Snak\PropertyValueSnak;
11
use Wikibase\DataModel\Snak\Snak;
12
use Wikibase\DataModel\Tests\Facet\FacetContainerContractTester;
13
14
/**
15
 * @covers Wikibase\DataModel\Snak\PropertyNoValueSnak
16
 * @covers Wikibase\DataModel\Snak\PropertySomeValueSnak
17
 * @covers Wikibase\DataModel\Snak\PropertyValueSnak
18
 * @covers Wikibase\DataModel\Snak\Snak
19
 * @uses Wikibase\DataModel\Snak\SnakObject
20
 * @uses DataValues\NumberValue
21
 * @uses DataValues\StringValue
22
 * @uses Wikibase\DataModel\Entity\EntityId
23
 * @uses Wikibase\DataModel\Entity\PropertyId
24
 *
25
 * @group Wikibase
26
 * @group WikibaseDataModel
27
 * @group WikibaseSnak
28
 *
29
 * @licence GNU GPL v2+
30
 * @author Jeroen De Dauw < [email protected] >
31
 */
32
class SnakTest extends \PHPUnit_Framework_TestCase {
33
34
	public function snakProvider() {
35
		$snaks = array();
36
37
		$id42 = new PropertyId( 'p42' );
38
39
		$snaks[] = new PropertyNoValueSnak( $id42 );
40
41
		$snaks[] = new PropertySomeValueSnak( $id42 );
42
43
		$values = array();
44
45
		$values[] = new StringValue( 'Ohi there!' );
46
		$values[] = new NumberValue( 42 );
47
48
		foreach ( $values as $value ) {
49
			$snaks[] = new PropertyValueSnak( $id42, $value );
50
		}
51
52
		$argLists = array();
53
54
		foreach ( $snaks as $snak ) {
55
			$argLists[] = array( $snak );
56
		}
57
58
		return $argLists;
59
	}
60
61
	/**
62
	 * @dataProvider snakProvider
63
	 * @param Snak $snak
64
	 */
65
	public function testGetType( Snak $snak ) {
66
		$this->assertInternalType( 'string', $snak->getType() );
67
	}
68
69
	/**
70
	 * @dataProvider snakProvider
71
	 * @param Snak $snak
72
	 */
73
	public function testGetPropertyId( Snak $snak ) {
74
		$this->assertInstanceOf( 'Wikibase\DataModel\Entity\EntityId', $snak->getPropertyId() );
75
	}
76
77
	/**
78
	 * @dataProvider snakProvider
79
	 * @param Snak $snak
80
	 */
81
	public function testSerialize( Snak $snak ) {
82
		$serialization = serialize( $snak );
83
		$this->assertInternalType( 'string', $serialization );
84
85
		$newInstance = unserialize( $serialization );
86
		$this->assertInstanceOf( get_class( $snak ), $newInstance );
87
88
		$this->assertEquals( $snak, $newInstance );
89
		$this->assertEquals( $snak->getPropertyId(), $newInstance->getPropertyId() );
90
		$this->assertEquals( $snak->getType(), $newInstance->getType() );
91
	}
92
93
	/**
94
	 * @dataProvider snakProvider
95
	 * @param Snak $snak
96
	 */
97
	public function testGetHash( Snak $snak ) {
98
		$hash = $snak->getHash();
99
		$this->assertInternalType( 'string', $hash );
100
		$this->assertEquals( $hash, $snak->getHash() );
101
	}
102
103
	/**
104
	 * @dataProvider snakProvider
105
	 * @param Snak $snak
106
	 */
107
	public function testEquals( Snak $snak ) {
108
		$this->assertTrue( $snak->equals( $snak ) );
109
		$this->assertFalse( $snak->equals( '~=[,,_,,]:3' ) );
110
	}
111
112
	public function testEqualsMoar() {
113
		$id42 = new PropertyId( 'p42' );
114
115
		$snak = new PropertyNoValueSnak( $id42 );
116
117
		$this->assertFalse( $snak->equals( new PropertySomeValueSnak( $id42 ) ) );
118
119
		$this->assertFalse( $snak->equals( new PropertyValueSnak(
120
			$id42,
121
			new StringValue( 'Ohi there!' )
122
		) ) );
123
124
		$id43 = new PropertyId( 'p43' );
125
126
		$this->assertFalse( $snak->equals( new PropertyNoValueSnak( $id43 ) ) );
127
	}
128
129
	/**
130
	 * @dataProvider snakProvider
131
	 * @param Snak $snak
132
	 */
133
	public function testHasFacet( Snak $snak ) {
134
		$tester = new FacetContainerContractTester();
135
136
		$tester->testHasFacet( $snak );
0 ignored issues
show
Documentation introduced by
$snak is of type object<Wikibase\DataModel\Snak\Snak>, but the function expects a object<Wikibase\DataModel\Facet\FacetContainer>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
137
	}
138
139
	/**
140
	 * @dataProvider snakProvider
141
	 * @param Snak $snak
142
	 */
143
	public function testListFacets( Snak $snak ) {
144
		$tester = new FacetContainerContractTester();
145
146
		$tester->testListFacets( $snak );
0 ignored issues
show
Documentation introduced by
$snak is of type object<Wikibase\DataModel\Snak\Snak>, but the function expects a object<Wikibase\DataModel\Facet\FacetContainer>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
147
	}
148
149
	/**
150
	 * @dataProvider snakProvider
151
	 * @param Snak $snak
152
	 */
153
	public function testGetFacet( Snak $snak ) {
154
		$tester = new FacetContainerContractTester();
155
156
		$tester->testGetFacet( $snak );
0 ignored issues
show
Documentation introduced by
$snak is of type object<Wikibase\DataModel\Snak\Snak>, but the function expects a object<Wikibase\DataModel\Facet\FacetContainer>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
157
	}
158
159
	/**
160
	 * @dataProvider snakProvider
161
	 * @param Snak $snak
162
	 */
163
	public function testAddFacet( Snak $snak ) {
164
		$tester = new FacetContainerContractTester();
165
166
		$tester->testAddFacet( $snak );
0 ignored issues
show
Documentation introduced by
$snak is of type object<Wikibase\DataModel\Snak\Snak>, but the function expects a object<Wikibase\DataModel\Facet\FacetContainer>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
167
	}
168
169
}
170