Skip to content

Commit

Permalink
Merge pull request #791 from wmde/SiteLinkList
Browse files Browse the repository at this point in the history
Allow iterable in SiteLinkList constructor
  • Loading branch information
JeroenDeDauw authored Nov 1, 2018
2 parents 56ec215 + a0aadb2 commit fbeec44
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/SiteLinkList.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class SiteLinkList implements IteratorAggregate, Countable, Comparable {
private $siteLinks = [];

/**
* @param SiteLink[] $siteLinks
* @param iterable|SiteLink[] $siteLinks Can be a non-array iterable since 8.1
*
* @throws InvalidArgumentException
*/
public function __construct( array $siteLinks = [] ) {
public function __construct( /* iterable */ $siteLinks = [] ) {
foreach ( $siteLinks as $siteLink ) {
if ( !( $siteLink instanceof SiteLink ) ) {
throw new InvalidArgumentException( 'Every element of $siteLinks must be an instance of SiteLink' );
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/SiteLinkListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,13 @@ public function testListWithElementsHasCorrectCount() {
$this->assertSame( 3, $list->count() );
}

public function testCanConstructWithIterable() {
$links = [ new SiteLink( 'enwiki', 'foo' ) ];

$this->assertEquals(
new SiteLinkList( $links ),
new SiteLinkList( new SiteLinkList( $links ) )
);
}

}

0 comments on commit fbeec44

Please sign in to comment.