diff options
Diffstat (limited to 'tests/phpunit/includes/libs/GenericArrayObjectTest.php')
-rw-r--r-- | tests/phpunit/includes/libs/GenericArrayObjectTest.php | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/tests/phpunit/includes/libs/GenericArrayObjectTest.php b/tests/phpunit/includes/libs/GenericArrayObjectTest.php index 70fce111..7436c43c 100644 --- a/tests/phpunit/includes/libs/GenericArrayObjectTest.php +++ b/tests/phpunit/includes/libs/GenericArrayObjectTest.php @@ -36,7 +36,7 @@ abstract class GenericArrayObjectTest extends MediaWikiTestCase { * * @return array */ - public abstract function elementInstancesProvider(); + abstract public function elementInstancesProvider(); /** * Returns the name of the concrete class being tested. @@ -45,7 +45,7 @@ abstract class GenericArrayObjectTest extends MediaWikiTestCase { * * @return string */ - public abstract function getInstanceClass(); + abstract public function getInstanceClass(); /** * Provides instances of the concrete class being tested. @@ -58,7 +58,7 @@ abstract class GenericArrayObjectTest extends MediaWikiTestCase { $instances = array(); foreach ( $this->elementInstancesProvider() as $elementInstances ) { - $instances[] = $this->getNew( $elementInstances ); + $instances[] = $this->getNew( $elementInstances[0] ); } return $this->arrayWrap( $instances ); @@ -73,6 +73,7 @@ abstract class GenericArrayObjectTest extends MediaWikiTestCase { */ protected function getNew( array $elements = array() ) { $class = $this->getInstanceClass(); + return new $class( $elements ); } @@ -110,7 +111,9 @@ abstract class GenericArrayObjectTest extends MediaWikiTestCase { * @param GenericArrayObject $list */ public function testUnset( GenericArrayObject $list ) { - if ( !$list->isEmpty() ) { + 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 ); @@ -123,10 +126,6 @@ abstract class GenericArrayObjectTest extends MediaWikiTestCase { unset( $list[$offset] ); $this->assertEquals( $count - 1, $list->count() ); } - - $exception = null; - try { $list->offsetUnset( 'sdfsedtgsrdysftu' ); } catch ( \Exception $exception ){} - $this->assertInstanceOf( '\Exception', $exception ); } /** @@ -155,7 +154,7 @@ abstract class GenericArrayObjectTest extends MediaWikiTestCase { $this->assertEquals( $listSize, $list->count() ); - $this->checkTypeChecks( function( GenericArrayObject $list, $element ) { + $this->checkTypeChecks( function ( GenericArrayObject $list, $element ) { $list->append( $element ); } ); } @@ -171,14 +170,13 @@ abstract class GenericArrayObjectTest extends MediaWikiTestCase { $elementClass = $list->getObjectType(); - foreach ( array( 42, 'foo', array(), new \stdClass(), 4.2 ) as $element ) { + foreach ( array( 42, 'foo', array(), new stdClass(), 4.2 ) as $element ) { $validValid = $element instanceof $elementClass; - try{ + try { call_user_func( $function, $list, $element ); $valid = true; - } - catch ( InvalidArgumentException $exception ) { + } catch ( InvalidArgumentException $exception ) { $valid = false; } @@ -200,6 +198,7 @@ abstract class GenericArrayObjectTest extends MediaWikiTestCase { public function testOffsetSet( array $elements ) { if ( $elements === array() ) { $this->assertTrue( true ); + return; } @@ -237,9 +236,28 @@ abstract class GenericArrayObjectTest extends MediaWikiTestCase { $this->assertEquals( count( $elements ), $list->count() ); - $this->checkTypeChecks( function( GenericArrayObject $list, $element ) { + $this->checkTypeChecks( function ( GenericArrayObject $list, $element ) { $list->offsetSet( mt_rand(), $element ); } ); } + /** + * @dataProvider instanceProvider + * + * @since 1.21 + * + * @param GenericArrayObject $list + */ + public function testSerialization( GenericArrayObject $list ) { + $serialization = serialize( $list ); + $copy = unserialize( $serialization ); + + $this->assertEquals( $serialization, serialize( $copy ) ); + $this->assertEquals( count( $list ), count( $copy ) ); + + $list = $list->getArrayCopy(); + $copy = $copy->getArrayCopy(); + + $this->assertArrayEquals( $list, $copy, true, true ); + } } |