Skip to content

Commit a0aadb2

Browse files
committed
Allow iterable in SiteLinkList constructor
Like we just did with TermList
1 parent 6d7b08c commit a0aadb2

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/SiteLinkList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ class SiteLinkList implements IteratorAggregate, Countable, Comparable {
3030
private $siteLinks = [];
3131

3232
/**
33-
* @param SiteLink[] $siteLinks
33+
* @param iterable|SiteLink[] $siteLinks Can be a non-array iterable since 8.1
3434
*
3535
* @throws InvalidArgumentException
3636
*/
37-
public function __construct( array $siteLinks = [] ) {
37+
public function __construct( /* iterable */ $siteLinks = [] ) {
3838
foreach ( $siteLinks as $siteLink ) {
3939
if ( !( $siteLink instanceof SiteLink ) ) {
4040
throw new InvalidArgumentException( 'Every element of $siteLinks must be an instance of SiteLink' );

tests/unit/SiteLinkListTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,13 @@ public function testListWithElementsHasCorrectCount() {
337337
$this->assertSame( 3, $list->count() );
338338
}
339339

340+
public function testCanConstructWithIterable() {
341+
$links = [ new SiteLink( 'enwiki', 'foo' ) ];
342+
343+
$this->assertEquals(
344+
new SiteLinkList( $links ),
345+
new SiteLinkList( new SiteLinkList( $links ) )
346+
);
347+
}
348+
340349
}

0 commit comments

Comments
 (0)