Skip to content

Commit 59061d5

Browse files
committed
Merge pull request #623 from wmde/splitFrom50
Add more regression tests for ReferenceList
2 parents 5138bbc + 5ee5b4b commit 59061d5

3 files changed

Lines changed: 38 additions & 28 deletions

File tree

RELEASE-NOTES.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
## Version 5.0.0 (alpha)
44

5-
* Removed `Claims` class (deprecated since 1.0)
6-
* Removed `getClaims` and `setClaims` from `Entity`, `Item` and `Property` (deprecated since 1.0)
7-
* Removed `HashableObjectStorage` class (deprecated since 4.4)
8-
* Removed `ReferenceList::removeDuplicates`
9-
* `ReferenceList` no longer derives from `SplObjectStorage`
10-
* Removed `attach`, `detach`, `contains`, `addAll`, `removeAll`,
11-
`removeAllExcept`, `getInfo`, `setInfo` and `getHash`
12-
* `ReferenceList` no longer implements `Iterator`
13-
* Removed `current`, `key`, `next`, `rewind` and `valid`
14-
* `ReferenceList` no longer implements `ArrayAccess`
15-
* Removed `offsetExists`, `offsetGet`, `offsetSet` and `offsetUnset`
16-
* `ReferenceList` still implements `Countable`, `Traversable` and `Serializable`
17-
* `ReferenceList` now implements `IteratorAggregate`
18-
* Method `getIterator` was added
19-
* `ReferenceList::addReference` now throws an `InvalidArgumentException` for negative indices
5+
* Removed `Claims` class (deprecated since 1.0).
6+
* Removed `getClaims` and `setClaims` methods from `Entity`, `Item` and `Property` (deprecated since
7+
1.0).
8+
* Removed `HashableObjectStorage` class (deprecated since 4.4).
9+
* `ReferenceList` no longer derives from `SplObjectStorage`.
10+
* Removed `addAll`, `attach`, `contains`, `detach`, `getHash`, `getInfo`, `removeAll`,
11+
`removeAllExcept` and `setInfo` methods.
12+
* `ReferenceList` no longer implements `ArrayAccess`.
13+
* Removed `offsetExists`, `offsetGet`, `offsetSet` and `offsetUnset` methods.
14+
* `ReferenceList` no longer implements `Iterator`.
15+
* Removed `current`, `key`, `next`, `rewind` and `valid` methods.
16+
* `ReferenceList` now implements `IteratorAggregate`.
17+
* Added `getIterator` method.
18+
* Removed `ReferenceList::removeDuplicates`.
19+
* `ReferenceList::addReference` now throws an `InvalidArgumentException` for negative indices.
2020
* `Entity` no longer implements `Comparable`
2121
* Added `EntityDocument::equals`
2222

src/Entity/EntityDocument.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
* Minimal interface for all objects that represent an entity.
99
* All entities have an EntityId and an entity type.
1010
*
11-
* @since 0.8.2, modified in 3.0
11+
* @since 0.8.2
1212
*
1313
* @licence GNU GPL v2+
1414
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
15+
* @author Bene* < benestar.wikimedia@gmail.com >
1516
*/
1617
interface EntityDocument {
1718

tests/unit/ReferenceListTest.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Hashable;
66
use InvalidArgumentException;
7+
use PHPUnit_Framework_TestCase;
78
use Wikibase\DataModel\Entity\PropertyId;
89
use Wikibase\DataModel\Reference;
910
use Wikibase\DataModel\ReferenceList;
@@ -21,7 +22,7 @@
2122
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
2223
* @author Thiemo Mättig
2324
*/
24-
class ReferenceListTest extends \PHPUnit_Framework_TestCase {
25+
class ReferenceListTest extends PHPUnit_Framework_TestCase {
2526

2627
public function instanceProvider() {
2728
$instances = array();
@@ -84,9 +85,20 @@ public function invalidConstructorArgumentsProvider() {
8485
);
8586
}
8687

88+
public function testGetIterator_isTraversable() {
89+
$references = new ReferenceList();
90+
$references->addNewReference( new PropertyNoValueSnak( 1 ) );
91+
$iterator = $references->getIterator();
92+
93+
$this->assertInstanceOf( 'Traversable', $iterator );
94+
$this->assertCount( 1, $iterator );
95+
foreach ( $references as $reference ) {
96+
$this->assertInstanceOf( 'Wikibase\DataModel\Reference', $reference );
97+
}
98+
}
99+
87100
/**
88101
* @dataProvider instanceProvider
89-
* @param ReferenceList $array
90102
*/
91103
public function testHasReferenceBeforeRemoveButNotAfter( ReferenceList $array ) {
92104
if ( $array->count() === 0 ) {
@@ -120,7 +132,6 @@ public function testGivenCloneOfReferenceInList_hasReferenceReturnsTrue() {
120132

121133
/**
122134
* @dataProvider instanceProvider
123-
* @param ReferenceList $array
124135
*/
125136
public function testRemoveReference( ReferenceList $array ) {
126137
$elementCount = count( $array );
@@ -225,7 +236,6 @@ public function testGivenEmptyReferenceAndIndex_addReferenceDoesNotAdd() {
225236

226237
/**
227238
* @dataProvider instanceProvider
228-
* @param ReferenceList $array
229239
*/
230240
public function testIndexOf( ReferenceList $array ) {
231241
$this->assertFalse( $array->indexOf( new Reference() ) );
@@ -248,7 +258,6 @@ public function testIndexOf_falseForMissingReferences() {
248258

249259
/**
250260
* @dataProvider instanceProvider
251-
* @param ReferenceList $array
252261
*/
253262
public function testEquals( ReferenceList $array ) {
254263
$this->assertTrue( $array->equals( $array ) );
@@ -257,24 +266,21 @@ public function testEquals( ReferenceList $array ) {
257266

258267
/**
259268
* @dataProvider instanceProvider
260-
* @param ReferenceList $array
261269
*/
262-
public function testGetHashReturnsString( ReferenceList $array ) {
270+
public function testGetValueHashReturnsString( ReferenceList $array ) {
263271
$this->assertInternalType( 'string', $array->getValueHash() );
264272
}
265273

266274
/**
267275
* @dataProvider instanceProvider
268-
* @param ReferenceList $array
269276
*/
270-
public function testGetHashValueIsTheSameForClone( ReferenceList $array ) {
277+
public function testGetValueHashIsTheSameForClone( ReferenceList $array ) {
271278
$copy = unserialize( serialize( $array ) );
272279
$this->assertEquals( $array->getValueHash(), $copy->getValueHash() );
273280
}
274281

275282
/**
276283
* @dataProvider instanceProvider
277-
* @param ReferenceList $references
278284
*/
279285
public function testHasReferenceHash( ReferenceList $references ) {
280286
$this->assertFalse( $references->hasReferenceHash( '~=[,,_,,]:3' ) );
@@ -289,7 +295,6 @@ public function testHasReferenceHash( ReferenceList $references ) {
289295

290296
/**
291297
* @dataProvider instanceProvider
292-
* @param ReferenceList $references
293298
*/
294299
public function testGetReference( ReferenceList $references ) {
295300
$this->assertNull( $references->getReference( '~=[,,_,,]:3' ) );
@@ -304,7 +309,6 @@ public function testGetReference( ReferenceList $references ) {
304309

305310
/**
306311
* @dataProvider instanceProvider
307-
* @param ReferenceList $references
308312
*/
309313
public function testRemoveReferenceHash( ReferenceList $references ) {
310314
$references->removeReferenceHash( '~=[,,_,,]:3' );
@@ -364,6 +368,11 @@ public function testGivenNoneSnak_addNewReferenceThrowsException() {
364368
$references->addNewReference( new PropertyNoValueSnak( 1 ), null );
365369
}
366370

371+
public function testSerializationStability() {
372+
$references = new ReferenceList();
373+
$this->assertSame( 'a:0:{}', $references->serialize() );
374+
}
375+
367376
public function testSerializeRoundtrip() {
368377
$references = new ReferenceList();
369378

0 commit comments

Comments
 (0)