From a0aadb2728ecb41b41006bd7d33c8965165563cb Mon Sep 17 00:00:00 2001 From: Jeroen De Dauw Date: Fri, 14 Sep 2018 11:52:43 +0200 Subject: [PATCH] Allow iterable in SiteLinkList constructor Like we just did with TermList --- src/SiteLinkList.php | 4 ++-- tests/unit/SiteLinkListTest.php | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/SiteLinkList.php b/src/SiteLinkList.php index 8917b1f7..ff03ef19 100644 --- a/src/SiteLinkList.php +++ b/src/SiteLinkList.php @@ -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' ); diff --git a/tests/unit/SiteLinkListTest.php b/tests/unit/SiteLinkListTest.php index c04e96dd..1228b47a 100644 --- a/tests/unit/SiteLinkListTest.php +++ b/tests/unit/SiteLinkListTest.php @@ -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 ) ) + ); + } + }