Skip to content

Commit d5b296c

Browse files
thiemowmdeWMDE bot
authored andcommitted
Make use of yield in dataProviders where it makes sense
I believe this makes the code quite a bit more readable. It also appears like there was quite a bit of unused code in SnakListTest. Change-Id: I10f8c171bed47bb607c6de6cff1e97f77687e938
1 parent 73b78ca commit d5b296c

File tree

7 files changed

+98
-184
lines changed

7 files changed

+98
-184
lines changed

tests/unit/ByPropertyIdArrayTest.php

Lines changed: 56 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -256,59 +256,56 @@ public function testToFlatArray( array $objects ) {
256256
self::assertEquals( $objects, $indexedArray->toFlatArray() );
257257
}
258258

259-
public static function moveProvider() {
259+
public static function moveProvider(): iterable {
260260
$c = self::statementsProvider();
261-
$argLists = [];
262-
263-
$argLists[] = [ $c, $c[0], 0, $c ];
264-
$argLists[] = [ $c, $c[0], 1, [ $c[1], $c[0], $c[2], $c[3], $c[4], $c[5] ] ];
265-
$argLists[] = [ $c, $c[0], 2, [ $c[1], $c[0], $c[2], $c[3], $c[4], $c[5] ] ];
266-
$argLists[] = [ $c, $c[0], 3, [ $c[2], $c[3], $c[4], $c[1], $c[0], $c[5] ] ];
267-
$argLists[] = [ $c, $c[0], 4, [ $c[2], $c[3], $c[4], $c[1], $c[0], $c[5] ] ];
268-
$argLists[] = [ $c, $c[0], 5, [ $c[2], $c[3], $c[4], $c[1], $c[0], $c[5] ] ];
269-
$argLists[] = [ $c, $c[0], 6, [ $c[2], $c[3], $c[4], $c[5], $c[1], $c[0] ] ];
270-
271-
$argLists[] = [ $c, $c[1], 0, [ $c[1], $c[0], $c[2], $c[3], $c[4], $c[5] ] ];
272-
$argLists[] = [ $c, $c[1], 1, $c ];
273-
$argLists[] = [ $c, $c[1], 2, $c ];
274-
$argLists[] = [ $c, $c[1], 3, [ $c[2], $c[3], $c[4], $c[0], $c[1], $c[5] ] ];
275-
$argLists[] = [ $c, $c[1], 4, [ $c[2], $c[3], $c[4], $c[0], $c[1], $c[5] ] ];
276-
$argLists[] = [ $c, $c[1], 5, [ $c[2], $c[3], $c[4], $c[0], $c[1], $c[5] ] ];
277-
$argLists[] = [ $c, $c[1], 6, [ $c[2], $c[3], $c[4], $c[5], $c[0], $c[1] ] ];
278-
279-
$argLists[] = [ $c, $c[2], 0, [ $c[2], $c[3], $c[4], $c[0], $c[1], $c[5] ] ];
280-
$argLists[] = [ $c, $c[2], 1, $c ];
281-
$argLists[] = [ $c, $c[2], 2, $c ];
282-
$argLists[] = [ $c, $c[2], 3, [ $c[0], $c[1], $c[3], $c[2], $c[4], $c[5] ] ];
283-
$argLists[] = [ $c, $c[2], 4, [ $c[0], $c[1], $c[3], $c[4], $c[2], $c[5] ] ];
284-
$argLists[] = [ $c, $c[2], 5, [ $c[0], $c[1], $c[3], $c[4], $c[2], $c[5] ] ];
285-
$argLists[] = [ $c, $c[2], 6, [ $c[0], $c[1], $c[5], $c[3], $c[4], $c[2] ] ];
286-
287-
$argLists[] = [ $c, $c[3], 0, [ $c[3], $c[2], $c[4], $c[0], $c[1], $c[5] ] ];
288-
$argLists[] = [ $c, $c[3], 1, [ $c[0], $c[1], $c[3], $c[2], $c[4], $c[5] ] ];
289-
$argLists[] = [ $c, $c[3], 2, [ $c[0], $c[1], $c[3], $c[2], $c[4], $c[5] ] ];
290-
$argLists[] = [ $c, $c[3], 3, $c ];
291-
$argLists[] = [ $c, $c[3], 4, [ $c[0], $c[1], $c[2], $c[4], $c[3], $c[5] ] ];
292-
$argLists[] = [ $c, $c[3], 5, [ $c[0], $c[1], $c[2], $c[4], $c[3], $c[5] ] ];
293-
$argLists[] = [ $c, $c[3], 6, [ $c[0], $c[1], $c[5], $c[2], $c[4], $c[3] ] ];
294-
295-
$argLists[] = [ $c, $c[4], 0, [ $c[4], $c[2], $c[3], $c[0], $c[1], $c[5] ] ];
296-
$argLists[] = [ $c, $c[4], 1, [ $c[0], $c[1], $c[4], $c[2], $c[3], $c[5] ] ];
297-
$argLists[] = [ $c, $c[4], 2, [ $c[0], $c[1], $c[4], $c[2], $c[3], $c[5] ] ];
298-
$argLists[] = [ $c, $c[4], 3, [ $c[0], $c[1], $c[2], $c[4], $c[3], $c[5] ] ];
299-
$argLists[] = [ $c, $c[4], 4, $c ];
300-
$argLists[] = [ $c, $c[4], 5, $c ];
301-
$argLists[] = [ $c, $c[4], 6, [ $c[0], $c[1], $c[5], $c[2], $c[3], $c[4] ] ];
302-
303-
$argLists[] = [ $c, $c[5], 0, [ $c[5], $c[0], $c[1], $c[2], $c[3], $c[4] ] ];
304-
$argLists[] = [ $c, $c[5], 1, [ $c[0], $c[1], $c[5], $c[2], $c[3], $c[4] ] ];
305-
$argLists[] = [ $c, $c[5], 2, [ $c[0], $c[1], $c[5], $c[2], $c[3], $c[4] ] ];
306-
$argLists[] = [ $c, $c[5], 3, $c ];
307-
$argLists[] = [ $c, $c[5], 4, $c ];
308-
$argLists[] = [ $c, $c[5], 5, $c ];
309-
$argLists[] = [ $c, $c[5], 6, $c ];
310261

311-
return $argLists;
262+
yield [ $c, $c[0], 0, $c ];
263+
yield [ $c, $c[0], 1, [ $c[1], $c[0], $c[2], $c[3], $c[4], $c[5] ] ];
264+
yield [ $c, $c[0], 2, [ $c[1], $c[0], $c[2], $c[3], $c[4], $c[5] ] ];
265+
yield [ $c, $c[0], 3, [ $c[2], $c[3], $c[4], $c[1], $c[0], $c[5] ] ];
266+
yield [ $c, $c[0], 4, [ $c[2], $c[3], $c[4], $c[1], $c[0], $c[5] ] ];
267+
yield [ $c, $c[0], 5, [ $c[2], $c[3], $c[4], $c[1], $c[0], $c[5] ] ];
268+
yield [ $c, $c[0], 6, [ $c[2], $c[3], $c[4], $c[5], $c[1], $c[0] ] ];
269+
270+
yield [ $c, $c[1], 0, [ $c[1], $c[0], $c[2], $c[3], $c[4], $c[5] ] ];
271+
yield [ $c, $c[1], 1, $c ];
272+
yield [ $c, $c[1], 2, $c ];
273+
yield [ $c, $c[1], 3, [ $c[2], $c[3], $c[4], $c[0], $c[1], $c[5] ] ];
274+
yield [ $c, $c[1], 4, [ $c[2], $c[3], $c[4], $c[0], $c[1], $c[5] ] ];
275+
yield [ $c, $c[1], 5, [ $c[2], $c[3], $c[4], $c[0], $c[1], $c[5] ] ];
276+
yield [ $c, $c[1], 6, [ $c[2], $c[3], $c[4], $c[5], $c[0], $c[1] ] ];
277+
278+
yield [ $c, $c[2], 0, [ $c[2], $c[3], $c[4], $c[0], $c[1], $c[5] ] ];
279+
yield [ $c, $c[2], 1, $c ];
280+
yield [ $c, $c[2], 2, $c ];
281+
yield [ $c, $c[2], 3, [ $c[0], $c[1], $c[3], $c[2], $c[4], $c[5] ] ];
282+
yield [ $c, $c[2], 4, [ $c[0], $c[1], $c[3], $c[4], $c[2], $c[5] ] ];
283+
yield [ $c, $c[2], 5, [ $c[0], $c[1], $c[3], $c[4], $c[2], $c[5] ] ];
284+
yield [ $c, $c[2], 6, [ $c[0], $c[1], $c[5], $c[3], $c[4], $c[2] ] ];
285+
286+
yield [ $c, $c[3], 0, [ $c[3], $c[2], $c[4], $c[0], $c[1], $c[5] ] ];
287+
yield [ $c, $c[3], 1, [ $c[0], $c[1], $c[3], $c[2], $c[4], $c[5] ] ];
288+
yield [ $c, $c[3], 2, [ $c[0], $c[1], $c[3], $c[2], $c[4], $c[5] ] ];
289+
yield [ $c, $c[3], 3, $c ];
290+
yield [ $c, $c[3], 4, [ $c[0], $c[1], $c[2], $c[4], $c[3], $c[5] ] ];
291+
yield [ $c, $c[3], 5, [ $c[0], $c[1], $c[2], $c[4], $c[3], $c[5] ] ];
292+
yield [ $c, $c[3], 6, [ $c[0], $c[1], $c[5], $c[2], $c[4], $c[3] ] ];
293+
294+
yield [ $c, $c[4], 0, [ $c[4], $c[2], $c[3], $c[0], $c[1], $c[5] ] ];
295+
yield [ $c, $c[4], 1, [ $c[0], $c[1], $c[4], $c[2], $c[3], $c[5] ] ];
296+
yield [ $c, $c[4], 2, [ $c[0], $c[1], $c[4], $c[2], $c[3], $c[5] ] ];
297+
yield [ $c, $c[4], 3, [ $c[0], $c[1], $c[2], $c[4], $c[3], $c[5] ] ];
298+
yield [ $c, $c[4], 4, $c ];
299+
yield [ $c, $c[4], 5, $c ];
300+
yield [ $c, $c[4], 6, [ $c[0], $c[1], $c[5], $c[2], $c[3], $c[4] ] ];
301+
302+
yield [ $c, $c[5], 0, [ $c[5], $c[0], $c[1], $c[2], $c[3], $c[4] ] ];
303+
yield [ $c, $c[5], 1, [ $c[0], $c[1], $c[5], $c[2], $c[3], $c[4] ] ];
304+
yield [ $c, $c[5], 2, [ $c[0], $c[1], $c[5], $c[2], $c[3], $c[4] ] ];
305+
yield [ $c, $c[5], 3, $c ];
306+
yield [ $c, $c[5], 4, $c ];
307+
yield [ $c, $c[5], 5, $c ];
308+
yield [ $c, $c[5], 6, $c ];
312309
}
313310

314311
/**
@@ -358,35 +355,31 @@ public function testMoveThrowingOutOfBoundsExceptionOnInvalidIndex() {
358355
$indexedArray->moveObjectToIndex( $statements[0], 9999 );
359356
}
360357

361-
public static function addProvider() {
358+
public static function addProvider(): iterable {
362359
$c = self::statementsProvider();
363360

364-
$argLists = [];
365-
366-
$argLists[] = [ [], $c[0], null, [ $c[0] ] ];
367-
$argLists[] = [ [], $c[0], 1, [ $c[0] ] ];
368-
$argLists[] = [ [ $c[0] ], $c[2], 0, [ $c[2], $c[0] ] ];
369-
$argLists[] = [ [ $c[2], $c[1] ], $c[0], 0, [ $c[0], $c[1], $c[2] ] ];
370-
$argLists[] = [
361+
yield [ [], $c[0], null, [ $c[0] ] ];
362+
yield [ [], $c[0], 1, [ $c[0] ] ];
363+
yield [ [ $c[0] ], $c[2], 0, [ $c[2], $c[0] ] ];
364+
yield [ [ $c[2], $c[1] ], $c[0], 0, [ $c[0], $c[1], $c[2] ] ];
365+
yield [
371366
[ $c[0], $c[1], $c[3] ],
372367
$c[5],
373368
1,
374369
[ $c[0], $c[1], $c[5], $c[3] ],
375370
];
376-
$argLists[] = [
371+
yield [
377372
[ $c[0], $c[1], $c[5], $c[3] ],
378373
$c[2],
379374
2,
380375
[ $c[0], $c[1], $c[2], $c[3], $c[5] ],
381376
];
382-
$argLists[] = [
377+
yield [
383378
[ $c[0], $c[1], $c[2], $c[3], $c[5] ],
384379
$c[4],
385380
null,
386381
[ $c[0], $c[1], $c[2], $c[3], $c[4], $c[5] ],
387382
];
388-
389-
return $argLists;
390383
}
391384

392385
/**

tests/unit/Entity/EntityIdTest.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,12 @@
2323
*/
2424
class EntityIdTest extends \PHPUnit\Framework\TestCase {
2525

26-
public static function instanceProvider() {
27-
$ids = [];
28-
29-
$ids[] = [ new ItemId( 'Q1' ), '' ];
30-
$ids[] = [ new ItemId( 'Q42' ), '' ];
31-
$ids[] = [ new ItemId( 'Q31337' ), '' ];
32-
$ids[] = [ new ItemId( 'Q2147483647' ), '' ];
33-
$ids[] = [ new NumericPropertyId( 'P101010' ), '' ];
34-
35-
return $ids;
26+
public static function instanceProvider(): iterable {
27+
yield [ new ItemId( 'Q1' ), '' ];
28+
yield [ new ItemId( 'Q42' ), '' ];
29+
yield [ new ItemId( 'Q31337' ), '' ];
30+
yield [ new ItemId( 'Q2147483647' ), '' ];
31+
yield [ new NumericPropertyId( 'P101010' ), '' ];
3632
}
3733

3834
/**

tests/unit/Entity/ItemTest.php

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -111,25 +111,21 @@ public static function simpleSiteLinkProvider() {
111111
return $argLists;
112112
}
113113

114-
public static function simpleSiteLinksProvider() {
115-
$argLists = [];
116-
117-
$argLists[] = [];
114+
public static function simpleSiteLinksProvider(): iterable {
115+
yield [];
118116

119-
$argLists[] = [ new SiteLink( 'enwiki', 'Wikidata', [ new ItemId( 'Q42' ) ] ) ];
117+
yield [ new SiteLink( 'enwiki', 'Wikidata', [ new ItemId( 'Q42' ) ] ) ];
120118

121-
$argLists[] = [
119+
yield [
122120
new SiteLink( 'enwiki', 'Wikidata' ),
123121
new SiteLink( 'nlwiki', 'Wikidata', [ new ItemId( 'Q3' ) ] ),
124122
];
125123

126-
$argLists[] = [
124+
yield [
127125
new SiteLink( 'enwiki', 'Wikidata' ),
128126
new SiteLink( 'nlwiki', 'Wikidata' ),
129127
new SiteLink( 'foo bar', 'baz bah', [ new ItemId( 'Q2' ) ] ),
130128
];
131-
132-
return $argLists;
133129
}
134130

135131
public function testHasLinkToSiteForFalse() {
@@ -487,40 +483,27 @@ public function testSetEmptyAlias() {
487483
$this->assertFalse( $item->getAliasGroups()->hasGroupForLanguage( 'en' ) );
488484
}
489485

490-
public static function instanceProvider() {
491-
$entities = [];
492-
486+
public static function instanceProvider(): iterable {
493487
// empty
494488
$entity = self::getNewEmpty();
495-
$entities[] = $entity;
489+
yield [ $entity ];
496490

497491
// ID only
498492
$entity = clone $entity;
499493
$entity->setId( new ItemId( 'Q44' ) );
500-
501-
$entities[] = $entity;
494+
yield [ $entity ];
502495

503496
// with labels and stuff
504497
$entity = self::getNewEmpty();
505498
$entity->setAliases( 'en', [ 'o', 'noez' ] );
506499
$entity->setLabel( 'de', 'spam' );
507500
$entity->setDescription( 'en', 'foo bar baz' );
508-
509-
$entities[] = $entity;
501+
yield [ $entity ];
510502

511503
// with labels etc and ID
512504
$entity = clone $entity;
513505
$entity->setId( new ItemId( 'Q42' ) );
514-
515-
$entities[] = $entity;
516-
517-
$argLists = [];
518-
519-
foreach ( $entities as $entity ) {
520-
$argLists[] = [ $entity ];
521-
}
522-
523-
return $argLists;
506+
yield [ $entity ];
524507
}
525508

526509
/**

tests/unit/ReferenceTest.php

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,51 +23,31 @@
2323
*/
2424
class ReferenceTest extends \PHPUnit\Framework\TestCase {
2525

26-
public static function snakListProvider() {
27-
$snakLists = [];
26+
public static function snakListProvider(): iterable {
27+
yield [ new SnakList() ];
2828

29-
$snakLists[] = new SnakList();
30-
31-
$snakLists[] = new SnakList(
29+
yield [ new SnakList(
3230
[ new PropertyValueSnak( new NumericPropertyId( 'P1' ), new StringValue( 'a' ) ) ]
33-
);
31+
) ];
3432

35-
$snakLists[] = new SnakList( [
33+
yield [ new SnakList( [
3634
new PropertyValueSnak( new NumericPropertyId( 'P1' ), new StringValue( 'a' ) ),
3735
new PropertySomeValueSnak( new NumericPropertyId( 'P2' ) ),
3836
new PropertyNoValueSnak( new NumericPropertyId( 'P3' ) ),
39-
] );
40-
41-
$argLists = [];
42-
43-
foreach ( $snakLists as $snakList ) {
44-
$argLists[] = [ $snakList ];
45-
}
46-
47-
return $argLists;
37+
] ) ];
4838
}
4939

50-
public static function instanceProvider() {
51-
$references = [];
40+
public static function instanceProvider(): iterable {
41+
yield [ new Reference() ];
5242

53-
$references[] = new Reference();
54-
55-
$references[] = new Reference( [
43+
yield [ new Reference( [
5644
new PropertyValueSnak( new NumericPropertyId( 'P1' ), new StringValue( 'a' ) ),
57-
] );
45+
] ) ];
5846

59-
$references[] = new Reference( [
47+
yield [ new Reference( [
6048
new PropertyValueSnak( new NumericPropertyId( 'P1' ), new StringValue( 'a' ) ),
6149
new PropertySomeValueSnak( new NumericPropertyId( 'P2' ) ),
62-
] );
63-
64-
$argLists = [];
65-
66-
foreach ( $references as $reference ) {
67-
$argLists[] = [ $reference ];
68-
}
69-
70-
return $argLists;
50+
] ) ];
7151
}
7252

7353
/**

tests/unit/SiteLinkTest.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,10 @@ public function testGetSiteId( $siteId ) {
3434
$this->assertSame( $siteId, $siteLink->getSiteId() );
3535
}
3636

37-
public static function siteIdProvider() {
38-
$argLists = [];
39-
40-
$argLists[] = [ 'enwiki' ];
41-
$argLists[] = [ 'nlwiki' ];
42-
$argLists[] = [ 'Nyan!' ];
43-
44-
return $argLists;
37+
public static function siteIdProvider(): iterable {
38+
yield [ 'enwiki' ];
39+
yield [ 'nlwiki' ];
40+
yield [ 'Nyan!' ];
4541
}
4642

4743
/**
@@ -70,14 +66,10 @@ public function testGetPageName( $pageName ) {
7066
$this->assertSame( $pageName, $siteLink->getPageName() );
7167
}
7268

73-
public static function pageNameProvider() {
74-
$argLists = [];
75-
76-
$argLists[] = [ 'Wikidata' ];
77-
$argLists[] = [ 'Nyan_Cat' ];
78-
$argLists[] = [ 'NYAN DATA ALL ACROSS THE SKY ~=[,,_,,]:3' ];
79-
80-
return $argLists;
69+
public static function pageNameProvider(): iterable {
70+
yield [ 'Wikidata' ];
71+
yield [ 'Nyan_Cat' ];
72+
yield [ 'NYAN DATA ALL ACROSS THE SKY ~=[,,_,,]:3' ];
8173
}
8274

8375
/**

tests/unit/Snak/SnakListTest.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,6 @@
2020
*/
2121
class SnakListTest extends \PHPUnit\Framework\TestCase {
2222

23-
public static function elementInstancesProvider() {
24-
$id42 = new NumericPropertyId( 'P42' );
25-
26-
$argLists = [];
27-
28-
$argLists[] = [ [ new PropertyNoValueSnak( $id42 ) ] ];
29-
$argLists[] = [ [ new PropertyNoValueSnak( new NumericPropertyId( 'P9001' ) ) ] ];
30-
$argLists[] = [ [ new PropertyValueSnak( $id42, new StringValue( 'a' ) ) ] ];
31-
32-
return $argLists;
33-
}
34-
3523
public static function instanceProvider() {
3624
$id42 = new NumericPropertyId( 'P42' );
3725
$id9001 = new NumericPropertyId( 'P9001' );
@@ -141,7 +129,7 @@ public function testRemoveSnak( SnakList $array ) {
141129
public function testAddSnak( SnakList $array ) {
142130
$elementCount = $array->count();
143131

144-
$element = $this->elementInstancesProvider()[0][0][0];
132+
$element = new PropertyNoValueSnak( new NumericPropertyId( 'P42' ) );
145133

146134
if ( !$array->hasSnak( $element ) ) {
147135
++$elementCount;

0 commit comments

Comments
 (0)