Completed
Push — master ( 5ef7c5...85134e )
by no
03:30
created

ClaimsTest::testDuplicateClaims()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 9.4285
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
3
namespace Wikibase\DataModel\Tests\Claim;
4
5
use InvalidArgumentException;
6
use ReflectionClass;
7
use Wikibase\DataModel\Claim\Claims;
8
use Wikibase\DataModel\Entity\PropertyId;
9
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
10
use Wikibase\DataModel\Snak\PropertySomeValueSnak;
11
use Wikibase\DataModel\Snak\Snak;
12
use Wikibase\DataModel\Statement\Statement;
13
use Wikibase\DataModel\Statement\StatementList;
14
15
/**
16
 * @covers Wikibase\DataModel\Claim\Claims
17
 *
18
 * @since 0.1
19
 *
20
 * @group Wikibase
21
 * @group WikibaseDataModel
22
 * @group WikibaseClaim
23
 *
24
 * @licence GNU GPL v2+
25
 * @author Daniel Kinzler
26
 */
27
class ClaimsTest extends \PHPUnit_Framework_TestCase {
28
29
	private $guidCounter = 0;
30
31
	private function makeStatement( Snak $mainSnak, $guid = null ) {
32
		if ( $guid === null ) {
33
			$this->guidCounter++;
34
			$guid = 'TEST$statement-' . $this->guidCounter;
35
		}
36
37
		$claim = new Statement( $mainSnak );
38
		$claim->setGuid( $guid );
39
40
		return $claim;
41
	}
42
43
	public function testArrayObjectNotConstructedFromObject() {
44
		$statement1 = $this->makeStatement( new PropertyNoValueSnak( 1 ) );
45
		$statement2 = $this->makeStatement( new PropertyNoValueSnak( 2 ) );
46
47
		$statementList = new StatementList();
48
		$statementList->addStatement( $statement1 );
49
50
		$claims = new Claims( $statementList );
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Claim\Claims has been deprecated with message: since 1.0, use StatementList and associated classes instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
51
		// According to the documentation append() "cannot be called when the ArrayObject was
52
		// constructed from an object." This test makes sure it was not constructed from an object.
53
		$claims->append( $statement2 );
54
55
		$this->assertSame( 2, $claims->count() );
56
	}
57
58
	/**
59
	 * @dataProvider constructorErrorProvider
60
	 */
61
	public function testConstructorError() {
62
		$this->setExpectedException( 'InvalidArgumentException' );
63
64
		$class = new ReflectionClass( 'Wikibase\DataModel\Claim\Claims' );
65
		$class->newInstanceArgs( func_get_args() );
66
	}
67
68
	public function constructorErrorProvider() {
69
		return array(
70
			array( 17 ),
71
			array( array( 'foo' ) ),
72
		);
73
	}
74
75
	public function testHasClaimWithGuid() {
76
		$claims = new Claims();
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Claim\Claims has been deprecated with message: since 1.0, use StatementList and associated classes instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
77
		$statement1 = $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P15' ) ) );
78
		$statement2 = $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P16' ) ) );
79
80
		$this->assertFalse( $claims->hasClaimWithGuid( $statement1->getGuid() ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim...ims::hasClaimWithGuid() has been deprecated with message: since 1.0, use StatementList::getFirstStatementByGuid() 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...
81
		$this->assertFalse( $claims->hasClaimWithGuid( $statement2->getGuid() ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim...ims::hasClaimWithGuid() has been deprecated with message: since 1.0, use StatementList::getFirstStatementByGuid() 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...
82
83
		$claims->addClaim( $statement1 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::addClaim() has been deprecated with message: since 1.0, use StatementList::addStatement() 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...
84
		$this->assertTrue( $claims->hasClaimWithGuid( $statement1->getGuid() ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim...ims::hasClaimWithGuid() has been deprecated with message: since 1.0, use StatementList::getFirstStatementByGuid() 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...
85
		$this->assertFalse( $claims->hasClaimWithGuid( $statement2->getGuid() ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim...ims::hasClaimWithGuid() has been deprecated with message: since 1.0, use StatementList::getFirstStatementByGuid() 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...
86
87
		$claims->addClaim( $statement2 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::addClaim() has been deprecated with message: since 1.0, use StatementList::addStatement() 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...
88
		$this->assertTrue( $claims->hasClaimWithGuid( $statement1->getGuid() ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim...ims::hasClaimWithGuid() has been deprecated with message: since 1.0, use StatementList::getFirstStatementByGuid() 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...
89
		$this->assertTrue( $claims->hasClaimWithGuid( $statement2->getGuid() ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim...ims::hasClaimWithGuid() has been deprecated with message: since 1.0, use StatementList::getFirstStatementByGuid() 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...
90
	}
91
92
	public function testRemoveClaimWithGuid() {
93
		$claims = new Claims();
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Claim\Claims has been deprecated with message: since 1.0, use StatementList and associated classes instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
94
		$statement1 = $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P15' ) ) );
95
		$statement2 = $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P16' ) ) );
96
97
		$claims->addClaim( $statement1 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::addClaim() has been deprecated with message: since 1.0, use StatementList::addStatement() 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...
98
		$claims->addClaim( $statement2 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::addClaim() has been deprecated with message: since 1.0, use StatementList::addStatement() 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...
99
		$this->assertSame( 2, $claims->count() );
100
101
		$claims->removeClaimWithGuid( $statement1->getGuid() );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim...::removeClaimWithGuid() has been deprecated with message: since 1.0, should not be needed any more.

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...
102
		$this->assertSame( 1, $claims->count() );
103
104
		$claims->removeClaimWithGuid( $statement2->getGuid() );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim...::removeClaimWithGuid() has been deprecated with message: since 1.0, should not be needed any more.

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...
105
		$this->assertSame( 0, $claims->count() );
106
	}
107
108
	public function testOffsetUnset() {
109
		$claims = new Claims();
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Claim\Claims has been deprecated with message: since 1.0, use StatementList and associated classes instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
110
		$statement1 = $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P15' ) ) );
111
		$statement2 = $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P16' ) ) );
112
113
		$claims->addClaim( $statement1 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::addClaim() has been deprecated with message: since 1.0, use StatementList::addStatement() 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...
114
		$claims->addClaim( $statement2 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::addClaim() has been deprecated with message: since 1.0, use StatementList::addStatement() 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...
115
		$this->assertSame( 2, $claims->count() );
116
117
		$claims->offsetUnset( $statement1->getGuid() );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::offsetUnset() has been deprecated with message: since 1.0, should never be called.

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...
118
		$this->assertSame( 1, $claims->count() );
119
120
		$claims->offsetUnset( $statement2->getGuid() );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::offsetUnset() has been deprecated with message: since 1.0, should never be called.

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...
121
		$this->assertSame( 0, $claims->count() );
122
	}
123
124
	public function testGetClaimWithGuid() {
125
		$claims = new Claims();
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Claim\Claims has been deprecated with message: since 1.0, use StatementList and associated classes instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
126
		$statement1 = $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P15' ) ) );
127
		$statement2 = $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P16' ) ) );
128
129
		$claims->addClaim( $statement1 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::addClaim() has been deprecated with message: since 1.0, use StatementList::addStatement() 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...
130
		$this->assertSame( $statement1, $claims->getClaimWithGuid( $statement1->getGuid() ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim...ims::getClaimWithGuid() has been deprecated with message: since 1.0, use StatementList::getFirstStatementByGuid() 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...
131
		$this->assertNull( $claims->getClaimWithGuid( $statement2->getGuid() ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim...ims::getClaimWithGuid() has been deprecated with message: since 1.0, use StatementList::getFirstStatementByGuid() 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...
132
133
		$claims->addClaim( $statement2 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::addClaim() has been deprecated with message: since 1.0, use StatementList::addStatement() 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...
134
		$this->assertSame( $statement1, $claims->getClaimWithGuid( $statement1->getGuid() ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim...ims::getClaimWithGuid() has been deprecated with message: since 1.0, use StatementList::getFirstStatementByGuid() 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...
135
		$this->assertSame( $statement2, $claims->getClaimWithGuid( $statement2->getGuid() ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim...ims::getClaimWithGuid() has been deprecated with message: since 1.0, use StatementList::getFirstStatementByGuid() 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...
136
	}
137
138
	public function testOffsetGet() {
139
		$claims = new Claims();
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Claim\Claims has been deprecated with message: since 1.0, use StatementList and associated classes instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
140
		$statement1 = $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P15' ) ) );
141
		$statement2 = $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P16' ) ) );
142
143
		$claims->addClaim( $statement1 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::addClaim() has been deprecated with message: since 1.0, use StatementList::addStatement() 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...
144
		$this->assertSame( $statement1, $claims->offsetGet( $statement1->getGuid() ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::offsetGet() has been deprecated with message: since 1.0, should never be called.

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...
145
146
		$claims->addClaim( $statement2 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::addClaim() has been deprecated with message: since 1.0, use StatementList::addStatement() 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...
147
		$this->assertSame( $statement1, $claims->offsetGet( $statement1->getGuid() ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::offsetGet() has been deprecated with message: since 1.0, should never be called.

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...
148
		$this->assertSame( $statement2, $claims->offsetGet( $statement2->getGuid() ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::offsetGet() has been deprecated with message: since 1.0, should never be called.

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...
149
	}
150
151
	public function testAddClaim() {
152
		$claims = new Claims();
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Claim\Claims has been deprecated with message: since 1.0, use StatementList and associated classes instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
153
		$statement1 = $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P15' ) ) );
154
		$statement2 = $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P16' ) ) );
155
156
		$claims->addClaim( $statement1 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::addClaim() has been deprecated with message: since 1.0, use StatementList::addStatement() 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...
157
		$claims->addClaim( $statement2 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::addClaim() has been deprecated with message: since 1.0, use StatementList::addStatement() 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...
158
159
		$this->assertSame( 2, $claims->count() );
160
		$this->assertEquals( $statement1, $claims[$statement1->getGuid()] );
161
		$this->assertEquals( $statement2, $claims[$statement2->getGuid()] );
162
163
		$claims->addClaim( $statement1 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::addClaim() has been deprecated with message: since 1.0, use StatementList::addStatement() 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...
164
		$claims->addClaim( $statement2 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::addClaim() has been deprecated with message: since 1.0, use StatementList::addStatement() 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...
165
166
		$this->assertSame( 2, $claims->count() );
167
168
		$this->assertNotNull( $claims->getClaimWithGuid( $statement1->getGuid() ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim...ims::getClaimWithGuid() has been deprecated with message: since 1.0, use StatementList::getFirstStatementByGuid() 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...
169
		$this->assertNotNull( $claims->getClaimWithGuid( $statement2->getGuid() ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim...ims::getClaimWithGuid() has been deprecated with message: since 1.0, use StatementList::getFirstStatementByGuid() 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...
170
171
		$this->assertSame( array(
172
			'TEST$STATEMENT-1' => $statement1,
173
			'TEST$STATEMENT-2' => $statement2,
174
		), $claims->getArrayCopy() );
175
	}
176
177
	/**
178
	 * @expectedException InvalidArgumentException
179
	 */
180
	public function testAddClaimWithIndexFails() {
181
		$claims = new Claims();
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Claim\Claims has been deprecated with message: since 1.0, use StatementList and associated classes instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
182
		$statement = new Statement( new PropertyNoValueSnak( 42 ) );
183
		$claims->addClaim( $statement, 0 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::addClaim() has been deprecated with message: since 1.0, use StatementList::addStatement() 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...
Unused Code introduced by
The call to Claims::addClaim() has too many arguments starting with 0.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
184
	}
185
186
	public function testAppend() {
187
		$claims = new Claims();
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Claim\Claims has been deprecated with message: since 1.0, use StatementList and associated classes instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
188
		$statement1 = $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P15' ) ) );
189
		$statement2 = $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P16' ) ) );
190
191
		$claims->append( $statement1 );
192
		$claims->append( $statement2 );
193
194
		$this->assertSame( 2, $claims->count() );
195
		$this->assertEquals( $statement1, $claims[$statement1->getGuid()] );
196
		$this->assertEquals( $statement2, $claims[$statement2->getGuid()] );
197
198
		$claims->append( $statement1 );
199
		$claims->append( $statement2 );
200
201
		$this->assertSame( 2, $claims->count() );
202
	}
203
204
	public function testAppendOperator() {
205
		$claims = new Claims();
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Claim\Claims has been deprecated with message: since 1.0, use StatementList and associated classes instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
206
		$statement1 = $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P15' ) ) );
207
		$statement2 = $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P16' ) ) );
208
209
		$claims[] = $statement1;
210
		$claims[] = $statement2;
211
212
		$this->assertSame( 2, $claims->count() );
213
		$this->assertEquals( $statement1, $claims[$statement1->getGuid()] );
214
		$this->assertEquals( $statement2, $claims[$statement2->getGuid()] );
215
216
		$claims[] = $statement1;
217
		$claims[] = $statement2;
218
219
		$this->assertSame( 2, $claims->count() );
220
	}
221
222
	/**
223
	 * @expectedException InvalidArgumentException
224
	 */
225
	public function testAppendWithNonClaimFails() {
226
		$claims = new Claims();
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Claim\Claims has been deprecated with message: since 1.0, use StatementList and associated classes instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
227
		$claims->append( 'bad' );
228
	}
229
230
	public function testOffsetSet() {
231
		$claims = new Claims();
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Claim\Claims has been deprecated with message: since 1.0, use StatementList and associated classes instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
232
		$statement1 = $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P15' ) ) );
233
		$statement2 = $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P16' ) ) );
234
235
		$claims->offsetSet( $statement1->getGuid(), $statement1 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::offsetSet() has been deprecated with message: since 1.0, should never be called.

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...
236
		$claims->offsetSet( $statement2->getGuid(), $statement2 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::offsetSet() has been deprecated with message: since 1.0, should never be called.

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...
237
238
		$this->assertSame( 2, $claims->count() );
239
		$this->assertEquals( $statement1, $claims[$statement1->getGuid()] );
240
		$this->assertEquals( $statement2, $claims[$statement2->getGuid()] );
241
242
		$claims->offsetSet( $statement1->getGuid(), $statement1 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::offsetSet() has been deprecated with message: since 1.0, should never be called.

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...
243
		$claims->offsetSet( $statement2->getGuid(), $statement2 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::offsetSet() has been deprecated with message: since 1.0, should never be called.

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...
244
245
		$this->assertSame( 2, $claims->count() );
246
247
		$this->setExpectedException( 'InvalidArgumentException' );
248
		$claims->offsetSet( 'spam', $statement1 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::offsetSet() has been deprecated with message: since 1.0, should never be called.

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...
249
	}
250
251
	public function testOffsetSetOperator() {
252
		$claims = new Claims();
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Claim\Claims has been deprecated with message: since 1.0, use StatementList and associated classes instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
253
		$statement1 = $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P15' ) ) );
254
		$statement2 = $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P16' ) ) );
255
256
		$claims[$statement1->getGuid()] = $statement1;
257
		$claims[$statement2->getGuid()] = $statement2;
258
259
		$this->assertSame( 2, $claims->count() );
260
		$this->assertEquals( $statement1, $claims[$statement1->getGuid()] );
261
		$this->assertEquals( $statement2, $claims[$statement2->getGuid()] );
262
263
		$claims[$statement1->getGuid()] = $statement1;
264
		$claims[$statement2->getGuid()] = $statement2;
265
266
		$this->assertSame( 2, $claims->count() );
267
	}
268
269
	public function testGuidNormalization() {
270
		$claims = new Claims();
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Claim\Claims has been deprecated with message: since 1.0, use StatementList and associated classes instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
271
		$statement1 = $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P15' ) ) );
272
		$statement2 = $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P16' ) ) );
273
274
		$claim1LowerGuid = strtolower( $statement1->getGuid() );
275
		$claim2UpperGuid = strtoupper( $statement2->getGuid() );
276
277
		$claims->addClaim( $statement1 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::addClaim() has been deprecated with message: since 1.0, use StatementList::addStatement() 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...
278
		$claims->addClaim( $statement2 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::addClaim() has been deprecated with message: since 1.0, use StatementList::addStatement() 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...
279
		$this->assertSame( 2, $claims->count() );
280
281
		$this->assertEquals( $statement1, $claims->getClaimWithGuid( $claim1LowerGuid ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim...ims::getClaimWithGuid() has been deprecated with message: since 1.0, use StatementList::getFirstStatementByGuid() 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...
282
		$this->assertEquals( $statement2, $claims->getClaimWithGuid( $claim2UpperGuid ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim...ims::getClaimWithGuid() has been deprecated with message: since 1.0, use StatementList::getFirstStatementByGuid() 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...
283
284
		$this->assertEquals( $statement1, $claims->offsetGet( $claim1LowerGuid ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::offsetGet() has been deprecated with message: since 1.0, should never be called.

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...
285
		$this->assertEquals( $statement2, $claims->offsetGet( $claim2UpperGuid ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::offsetGet() has been deprecated with message: since 1.0, should never be called.

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...
286
287
		$this->assertEquals( $statement1, $claims[$claim1LowerGuid] );
288
		$this->assertEquals( $statement2, $claims[$claim2UpperGuid] );
289
290
		$claims = new Claims();
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Claim\Claims has been deprecated with message: since 1.0, use StatementList and associated classes instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
291
		$claims->offsetSet( strtoupper( $claim1LowerGuid ), $statement1 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::offsetSet() has been deprecated with message: since 1.0, should never be called.

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...
292
		$claims->offsetSet( strtolower( $claim2UpperGuid ), $statement2 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::offsetSet() has been deprecated with message: since 1.0, should never be called.

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...
293
		$this->assertSame( 2, $claims->count() );
294
295
		$this->assertEquals( $statement1, $claims->getClaimWithGuid( $claim1LowerGuid ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim...ims::getClaimWithGuid() has been deprecated with message: since 1.0, use StatementList::getFirstStatementByGuid() 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...
296
		$this->assertEquals( $statement2, $claims->getClaimWithGuid( $claim2UpperGuid ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim...ims::getClaimWithGuid() has been deprecated with message: since 1.0, use StatementList::getFirstStatementByGuid() 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...
297
	}
298
299
	/**
300
	 * Attempts to add Claims with no GUID set will fail.
301
	 */
302
	public function testNoGuidFailure() {
303
		$statement = new Statement( new PropertyNoValueSnak( 42 ) );
304
		$list = new Claims();
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Claim\Claims has been deprecated with message: since 1.0, use StatementList and associated classes instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
305
306
		$this->setExpectedException( 'InvalidArgumentException' );
307
		$list->addClaim( $statement );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::addClaim() has been deprecated with message: since 1.0, use StatementList::addStatement() 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...
308
	}
309
310
	public function testDuplicateClaims() {
311
		$statement1 = $this->makeStatement( new PropertyNoValueSnak( 42 ) );
312
		$statement2 = $this->makeStatement( new PropertyNoValueSnak( 42 ) );
313
314
		$list = new Claims();
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Claim\Claims has been deprecated with message: since 1.0, use StatementList and associated classes instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
315
		$list->addClaim( $statement1 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::addClaim() has been deprecated with message: since 1.0, use StatementList::addStatement() 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...
316
		$list->addClaim( $statement2 );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim\Claims::addClaim() has been deprecated with message: since 1.0, use StatementList::addStatement() 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...
317
318
		$this->assertEquals( 2, $list->count(), 'Adding two duplicates to an empty list should result in a count of two' );
319
320
		$this->assertEquals( $statement1, $list->getClaimWithGuid( $statement1->getGuid() ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim...ims::getClaimWithGuid() has been deprecated with message: since 1.0, use StatementList::getFirstStatementByGuid() 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...
321
		$this->assertEquals( $statement2, $list->getClaimWithGuid( $statement2->getGuid() ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim...ims::getClaimWithGuid() has been deprecated with message: since 1.0, use StatementList::getFirstStatementByGuid() 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...
322
323
		$list->removeClaimWithGuid( $statement2->getGuid() );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim...::removeClaimWithGuid() has been deprecated with message: since 1.0, should not be needed any more.

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...
324
325
		$this->assertNotNull( $list->getClaimWithGuid( $statement1->getGuid() ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim...ims::getClaimWithGuid() has been deprecated with message: since 1.0, use StatementList::getFirstStatementByGuid() 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...
326
		$this->assertNull( $list->getClaimWithGuid( $statement2->getGuid() ) );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Claim...ims::getClaimWithGuid() has been deprecated with message: since 1.0, use StatementList::getFirstStatementByGuid() 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...
327
	}
328
329
	public function testIterator() {
330
		$expected = array(
331
			'GUID1' => $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P42' ) ), 'guid1' ),
332
			'GUID2' => $this->makeStatement( new PropertySomeValueSnak( new PropertyId( 'P42' ) ), 'guid2' ),
333
			'GUID3' => $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P23' ) ), 'guid3' ),
334
			'GUID4' => $this->makeStatement( new PropertyNoValueSnak( new PropertyId( 'P9000' ) ), 'guid4' ),
335
		);
336
337
		$claims = new Claims( $expected );
0 ignored issues
show
Deprecated Code introduced by
The class Wikibase\DataModel\Claim\Claims has been deprecated with message: since 1.0, use StatementList and associated classes instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
338
		$actual = iterator_to_array( $claims->getIterator() );
339
340
		$this->assertSame( $expected, $actual );
341
	}
342
343
}
344