diff options
author | Timo Tijhof <krinkle@fastmail.com> | 2023-06-02 20:18:54 +0100 |
---|---|---|
committer | Aaron Schulz <aschulz@wikimedia.org> | 2023-06-05 19:39:33 +0000 |
commit | 90e2ed6ccb11b3f071f22a67a588dc7acfb18350 (patch) | |
tree | 104e52d560721e52188bc756b6dcba5130ad801e /tests/phpunit/includes/libs/GenericArrayObjectTest.php | |
parent | e2747e78e08df2e23dc7f2ef7f0bf611a804b21a (diff) | |
download | mediawikicore-90e2ed6ccb11b3f071f22a67a588dc7acfb18350.tar.gz mediawikicore-90e2ed6ccb11b3f071f22a67a588dc7acfb18350.zip |
site: Simplify SiteList by removing GenericArrayObject indirection
== Background ==
In 2012, commit afe46f1403a (Id7e9b59c7e) added libs/GenericArrayObject
along with an (unused) abstract GenericArrayObjectTest case.
The same code was also added to the Wikibase extension with
change 6347b35a55cd (Ifa7f1dc702).
The code was then factored out from Wikibase into the wmde/Diff
library.
In 2013, GenericArrayObject was removed from wmde/Diff in the commit
at https://github.com/wmde/Diff/commit/d9c2bd5c140e2a783fd42298db6c.
== This change ==
Remove the GenericArrayObject indirection from SiteList as there exist
nothing outside SiteList refering to it in Codesearch Everywhere, and
even in SiteList much of the code in GenericArrayObject is overridden,
unused, or otherwise needlessly indirect.
Change-Id: Ifea09c5de50af1616058d8baa9037db273dfb0e5
Diffstat (limited to 'tests/phpunit/includes/libs/GenericArrayObjectTest.php')
-rw-r--r-- | tests/phpunit/includes/libs/GenericArrayObjectTest.php | 278 |
1 files changed, 0 insertions, 278 deletions
diff --git a/tests/phpunit/includes/libs/GenericArrayObjectTest.php b/tests/phpunit/includes/libs/GenericArrayObjectTest.php deleted file mode 100644 index 21aa3fa34973..000000000000 --- a/tests/phpunit/includes/libs/GenericArrayObjectTest.php +++ /dev/null @@ -1,278 +0,0 @@ -<?php - -/** - * Tests for the GenericArrayObject and deriving classes. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * http://www.gnu.org/copyleft/gpl.html - * - * @file - * @since 1.20 - * - * @ingroup Test - * @group GenericArrayObject - * - * @author Jeroen De Dauw < jeroendedauw@gmail.com > - */ -abstract class GenericArrayObjectTest extends PHPUnit\Framework\TestCase { - - use MediaWikiCoversValidator; - - /** - * Returns objects that can serve as elements in the concrete - * GenericArrayObject deriving class being tested. - * - * @since 1.20 - * - * @return array - */ - abstract public function elementInstancesProvider(); - - /** - * Returns the name of the concrete class being tested. - * - * @since 1.20 - * - * @return string - */ - abstract public function getInstanceClass(); - - /** - * Provides instances of the concrete class being tested. - * - * @since 1.20 - * - * @return array - */ - public function instanceProvider() { - $instances = []; - - foreach ( $this->elementInstancesProvider() as $elementInstances ) { - $instances[] = $this->getNew( $elementInstances[0] ); - } - - return $this->arrayWrap( $instances ); - } - - /** - * @since 1.20 - * - * @param array $elements - * - * @return GenericArrayObject - */ - protected function getNew( array $elements = [] ) { - $class = $this->getInstanceClass(); - - return new $class( $elements ); - } - - /** - * @dataProvider elementInstancesProvider - * - * @since 1.20 - * - * @param array $elements - * - * @covers GenericArrayObject::__construct - */ - public function testConstructor( array $elements ) { - $arrayObject = $this->getNew( $elements ); - - $this->assertEquals( count( $elements ), $arrayObject->count() ); - } - - /** - * @dataProvider elementInstancesProvider - * - * @since 1.20 - * - * @param array $elements - * - * @covers GenericArrayObject::isEmpty - */ - public function testIsEmpty( array $elements ) { - $arrayObject = $this->getNew( $elements ); - - $this->assertEquals( $elements === [], $arrayObject->isEmpty() ); - } - - /** - * @dataProvider instanceProvider - * - * @since 1.20 - * - * @param GenericArrayObject $list - * - * @covers GenericArrayObject::offsetUnset - */ - public function testUnset( GenericArrayObject $list ) { - if ( $list->isEmpty() ) { - $this->assertTrue( true ); // We cannot test unset if there are no elements - } else { - $offset = $list->getIterator()->key(); - $count = $list->count(); - $list->offsetUnset( $offset ); - $this->assertEquals( $count - 1, $list->count() ); - } - - if ( !$list->isEmpty() ) { - $offset = $list->getIterator()->key(); - $count = $list->count(); - unset( $list[$offset] ); - $this->assertEquals( $count - 1, $list->count() ); - } - } - - /** - * @dataProvider elementInstancesProvider - * - * @since 1.20 - * - * @param array $elements - * - * @covers GenericArrayObject::append - */ - public function testAppend( array $elements ) { - $list = $this->getNew(); - - $listSize = count( $elements ); - - foreach ( $elements as $element ) { - $list->append( $element ); - } - - $this->assertEquals( $listSize, $list->count() ); - - $list = $this->getNew(); - - foreach ( $elements as $element ) { - $list[] = $element; - } - - $this->assertEquals( $listSize, $list->count() ); - - $this->checkTypeChecks( static function ( GenericArrayObject $list, $element ) { - $list->append( $element ); - } ); - } - - /** - * @since 1.20 - * - * @param callable $function - */ - protected function checkTypeChecks( $function ) { - $list = $this->getNew(); - - $elementClass = $list->getObjectType(); - - foreach ( [ 42, 'foo', [], (object)[], 4.2 ] as $element ) { - $validValid = $element instanceof $elementClass; - - try { - $function( $list, $element ); - $valid = true; - } catch ( InvalidArgumentException $exception ) { - $valid = false; - } - - $this->assertEquals( - $validValid, - $valid, - 'Object of invalid type got successfully added to a GenericArrayObject' - ); - } - } - - /** - * @dataProvider elementInstancesProvider - * - * @since 1.20 - * - * @param array $elements - * @covers GenericArrayObject::getObjectType - * @covers GenericArrayObject::offsetSet - */ - public function testOffsetSet( array $elements ) { - if ( $elements === [] ) { - $this->assertTrue( true ); - - return; - } - - $list = $this->getNew(); - - $element = reset( $elements ); - $list->offsetSet( 42, $element ); - $this->assertEquals( $element, $list->offsetGet( 42 ) ); - - $list = $this->getNew(); - - $element = reset( $elements ); - $list['oHai'] = $element; - $this->assertEquals( $element, $list['oHai'] ); - - $list = $this->getNew(); - - $element = reset( $elements ); - $list->offsetSet( 9001, $element ); - $this->assertEquals( $element, $list[9001] ); - - $list = $this->getNew(); - - $element = reset( $elements ); - $list->offsetSet( null, $element ); - $this->assertEquals( $element, $list[0] ); - - $list = $this->getNew(); - $offset = 0; - - foreach ( $elements as $element ) { - $list->offsetSet( null, $element ); - $this->assertEquals( $element, $list[$offset++] ); - } - - $this->assertEquals( count( $elements ), $list->count() ); - - $this->checkTypeChecks( static function ( GenericArrayObject $list, $element ) { - $list->offsetSet( mt_rand(), $element ); - } ); - } - - /** - * @dataProvider instanceProvider - * - * @since 1.21 - * - * @param GenericArrayObject $list - * - * @covers GenericArrayObject::getSerializationData - * @covers GenericArrayObject::serialize - * @covers GenericArrayObject::unserialize - */ - public function testSerialization( GenericArrayObject $list ) { - $serialization = serialize( $list ); - $copy = unserialize( $serialization ); - - $this->assertEquals( $serialization, serialize( $copy ) ); - $this->assertSame( count( $list ), count( $copy ) ); - - $list = $list->getArrayCopy(); - $copy = $copy->getArrayCopy(); - - $this->assertArrayEquals( $list, $copy, true, true ); - } -} |