Jeroen De Dauw has uploaded a new change for review. https://gerrit.wikimedia.org/r/80193
Change subject: Split function with boolean flag into two ...................................................................... Split function with boolean flag into two Change-Id: Iece3099946329cd3f078c1adeb2a14ba41924abc --- M DataValues/src/UnDeserializableValue.php M DataValues/tests/phpunit/BooleanValueTest.php M DataValues/tests/phpunit/DataValueTest.php M DataValues/tests/phpunit/GlobeCoordinateValueTest.php M DataValues/tests/phpunit/IriValueTest.php M DataValues/tests/phpunit/LatLongValueTest.php M DataValues/tests/phpunit/MonolingualTextValueTest.php M DataValues/tests/phpunit/MultilingualTextValueTest.php M DataValues/tests/phpunit/NumberValueTest.php M DataValues/tests/phpunit/QuantityValueTest.php M DataValues/tests/phpunit/StringValueTest.php M DataValues/tests/phpunit/TimeValueTest.php M DataValues/tests/phpunit/UnDeserializableValueTest.php M DataValues/tests/phpunit/UnknownValueTest.php 14 files changed, 507 insertions(+), 521 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DataValues refs/changes/93/80193/1 diff --git a/DataValues/src/UnDeserializableValue.php b/DataValues/src/UnDeserializableValue.php index 344db99..93a7ac9 100644 --- a/DataValues/src/UnDeserializableValue.php +++ b/DataValues/src/UnDeserializableValue.php @@ -2,6 +2,8 @@ namespace DataValues; +use InvalidArgumentException; + /** * Class representing a value that could not be unserialized for some reason. * It contains the raw native data structure representing the value, @@ -35,24 +37,24 @@ /** * @since 0.1 * - * @param string $type The originally intended type - * @param mixed $data The raw data structure + * @param string $type The originally intended type + * @param mixed $data The raw data structure * @param string $error The error that occurred when processing the original data structure. * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @internal param mixed $value */ public function __construct( $data, $type, $error ) { if ( !is_null( $type ) && !is_string( $type ) ) { - throw new \InvalidArgumentException( '$type must be string or null' ); + throw new InvalidArgumentException( '$type must be string or null' ); } if ( is_object( $data ) ) { - throw new \InvalidArgumentException( '$data must not be an object' ); + throw new InvalidArgumentException( '$data must not be an object' ); } if ( !is_string( $error ) ) { - throw new \InvalidArgumentException( '$error must be a string' ); + throw new InvalidArgumentException( '$error must be a string' ); } $this->data = $data; diff --git a/DataValues/tests/phpunit/BooleanValueTest.php b/DataValues/tests/phpunit/BooleanValueTest.php index 1840ad7..bfa5288 100644 --- a/DataValues/tests/phpunit/BooleanValueTest.php +++ b/DataValues/tests/phpunit/BooleanValueTest.php @@ -31,34 +31,34 @@ return 'DataValues\BooleanValue'; } - /** - * @see DataValueTest::constructorProvider - * - * @since 0.1 - * - * @return array - */ - public function constructorProvider() { + public function validConstructorArgumentsProvider() { $argLists = array(); $argLists[] = array( false ); - $argLists[] = array( false, 42 ); - $argLists[] = array( false, array() ); - $argLists[] = array( false, '1' ); - $argLists[] = array( false, '' ); - $argLists[] = array( false, 0 ); - $argLists[] = array( false, 1 ); - $argLists[] = array( false, 'foo' ); - $argLists[] = array( false, null ); - $argLists[] = array( true, false ); - $argLists[] = array( true, true ); + $argLists[] = array( true ); + + return $argLists; + } + + public function invalidConstructorArgumentsProvider() { + $argLists = array(); + + $argLists[] = array( ); + $argLists[] = array( 42 ); + $argLists[] = array( array() ); + $argLists[] = array( '1' ); + $argLists[] = array( '' ); + $argLists[] = array( 0 ); + $argLists[] = array( 1 ); + $argLists[] = array( 'foo' ); + $argLists[] = array( null ); return $argLists; } /** * @dataProvider instanceProvider - * @param \DataValues\BooleanValue $boolean + * @param BooleanValue $boolean * @param array $arguments */ public function testGetValue( BooleanValue $boolean, array $arguments ) { diff --git a/DataValues/tests/phpunit/DataValueTest.php b/DataValues/tests/phpunit/DataValueTest.php index 4b8e6fd..f2e1fc0 100644 --- a/DataValues/tests/phpunit/DataValueTest.php +++ b/DataValues/tests/phpunit/DataValueTest.php @@ -26,15 +26,13 @@ */ public abstract function getClass(); - /** - * First element can be a boolean indication if the successive values are valid, - * or a string indicating the type of exception that should be thrown (ie not valid either). - * - * @since 0.1 - * - * @return array - */ - public abstract function constructorProvider(); + public function validConstructorArgumentsProvider() { + return array(); + } + + public function invalidConstructorArgumentsProvider() { + return array(); + } /** * Creates and returns a new instance of the concrete class. @@ -56,47 +54,48 @@ * @return array [instance, constructor args] */ public function instanceProvider() { - $phpFails = array( $this, 'newInstance' ); + $instanceBuilder = array( $this, 'newInstance' ); - return array_filter( array_map( - function( array $args ) use ( $phpFails ) { - $isValid = array_shift( $args ) === true; - - if ( $isValid ) { - return array( call_user_func_array( $phpFails, $args ), $args ); - } - else { - return false; - } + return array_map( + function( array $args ) use ( $instanceBuilder ) { + return array( + call_user_func_array( $instanceBuilder, $args ), + $args + ); }, - $this->constructorProvider() - ), 'is_array' ); + $this->validConstructorArgumentsProvider() + ); } /** - * @dataProvider constructorProvider + * @dataProvider validConstructorArgumentsProvider * * @since 0.1 */ - public function testConstructor() { - $args = func_get_args(); + public function testConstructorWithValidArguments() { + $dataItem = call_user_func_array( + array( $this, 'newInstance' ), + func_get_args() + ); - $valid = array_shift( $args ); - $pokemons = null; - - if ( $valid === false ) { - $valid = 'Exception'; - } - - if ( is_string( $valid ) ) { - $this->setExpectedException( $valid ); - } - - $dataItem = call_user_func_array( array( $this, 'newInstance' ), $args ); $this->assertInstanceOf( $this->getClass(), $dataItem ); } /** + * @dataProvider invalidConstructorArgumentsProvider + * + * @since 0.1 + */ + public function testConstructorWithInvalidArguments() { + $this->setExpectedException( 'Exception' ); + + call_user_func_array( + array( $this, 'newInstance' ), + func_get_args() + ); + } + + /** * @dataProvider instanceProvider * @param DataValue $value * @param array $arguments diff --git a/DataValues/tests/phpunit/GlobeCoordinateValueTest.php b/DataValues/tests/phpunit/GlobeCoordinateValueTest.php index 6009994..c86c9df 100644 --- a/DataValues/tests/phpunit/GlobeCoordinateValueTest.php +++ b/DataValues/tests/phpunit/GlobeCoordinateValueTest.php @@ -32,41 +32,40 @@ return 'DataValues\GlobeCoordinateValue'; } - /** - * @see DataValueTest::constructorProvider - * - * @since 0.1 - * - * @return array - */ - public function constructorProvider() { + public function validConstructorArgumentsProvider() { $argLists = array(); - $argLists[] = array( true, new LatLongValue( 4.2, 4.2 ), 1 ); - $argLists[] = array( true, new LatLongValue( 4.2, 42 ), 1 ); - $argLists[] = array( true, new LatLongValue( 42, 4.2 ), 0.1 ); - $argLists[] = array( true, new LatLongValue( 42, 42 ), 0.1 ); - $argLists[] = array( true, new LatLongValue( -4.2, -4.2 ), 0.1 ); - $argLists[] = array( true, new LatLongValue( 4.2, -42 ), 0.1 ); - $argLists[] = array( true, new LatLongValue( -42, 4.2 ), 10 ); - $argLists[] = array( true, new LatLongValue( 0, 0 ), 0.001 ); + $argLists[] = array( new LatLongValue( 4.2, 4.2 ), 1 ); + $argLists[] = array( new LatLongValue( 4.2, 42 ), 1 ); + $argLists[] = array( new LatLongValue( 42, 4.2 ), 0.1 ); + $argLists[] = array( new LatLongValue( 42, 42 ), 0.1 ); + $argLists[] = array( new LatLongValue( -4.2, -4.2 ), 0.1 ); + $argLists[] = array( new LatLongValue( 4.2, -42 ), 0.1 ); + $argLists[] = array( new LatLongValue( -42, 4.2 ), 10 ); + $argLists[] = array( new LatLongValue( 0, 0 ), 0.001 ); + + $argLists[] = array( new LatLongValue( 4.2, 4.2 ), 1, GlobeCoordinateValue::GLOBE_EARTH ); + $argLists[] = array( new LatLongValue( 4.2, 4.2 ), 1, 'terminus' ); + $argLists[] = array( new LatLongValue( 4.2, 4.2 ), 1, "Schar's World" ); + $argLists[] = array( new LatLongValue( 4.2, 4.2 ), 1, 'coruscant' ); + + return $argLists; + } + + public function invalidConstructorArgumentsProvider() { + $argLists = array(); + + $argLists[] = array( new LatLongValue( 4.2, 4.2 ), null ); + $argLists[] = array( new LatLongValue( 4.2, 4.2 ), 'foo' ); + $argLists[] = array( new LatLongValue( 4.2, 4.2 ), true ); + $argLists[] = array( new LatLongValue( 4.2, 4.2 ), array( 1 ) ); + $argLists[] = array( new LatLongValue( 4.2, 4.2 ), '1' ); + + $argLists[] = array( new LatLongValue( 4.2, 4.2 ), 1, null ); + $argLists[] = array( new LatLongValue( 4.2, 4.2 ), 1, array( 1 ) ); + $argLists[] = array( new LatLongValue( 4.2, 4.2 ), 1, 1 ); // TODO: test precisions that are out of the valid range - - $argLists[] = array( false, new LatLongValue( 4.2, 4.2 ), null ); - $argLists[] = array( false, new LatLongValue( 4.2, 4.2 ), 'foo' ); - $argLists[] = array( false, new LatLongValue( 4.2, 4.2 ), true ); - $argLists[] = array( false, new LatLongValue( 4.2, 4.2 ), array( 1 ) ); - $argLists[] = array( false, new LatLongValue( 4.2, 4.2 ), '1' ); - - $argLists[] = array( false, new LatLongValue( 4.2, 4.2 ), 1, null ); - $argLists[] = array( false, new LatLongValue( 4.2, 4.2 ), 1, array( 1 ) ); - $argLists[] = array( false, new LatLongValue( 4.2, 4.2 ), 1, 1 ); - - $argLists[] = array( true, new LatLongValue( 4.2, 4.2 ), 1, GlobeCoordinateValue::GLOBE_EARTH ); - $argLists[] = array( true, new LatLongValue( 4.2, 4.2 ), 1, 'terminus' ); - $argLists[] = array( true, new LatLongValue( 4.2, 4.2 ), 1, "Schar's World" ); - $argLists[] = array( true, new LatLongValue( 4.2, 4.2 ), 1, 'coruscant' ); return $argLists; } diff --git a/DataValues/tests/phpunit/IriValueTest.php b/DataValues/tests/phpunit/IriValueTest.php index 96d7fdf..6333c00 100644 --- a/DataValues/tests/phpunit/IriValueTest.php +++ b/DataValues/tests/phpunit/IriValueTest.php @@ -31,45 +31,45 @@ return 'DataValues\IriValue'; } - /** - * @see DataValueTest::constructorProvider - * - * @since 0.1 - * - * @return array - */ - public function constructorProvider() { + public function validConstructorArgumentsProvider() { $argLists = array(); + $argLists[] = array( 'ohi', 'foo', 'bar', 'baz' ); + $argLists[] = array( 'http', '//www.wikidata.org/w/index.php', 'title=Special:Version', 'sv-credits-datavalues' ); + $argLists[] = array( 'ohi', 'foo', '', 'baz' ); + $argLists[] = array( 'ohi', 'foo', 'bar', '' ); + $argLists[] = array( 'ohi', 'foo', '', '' ); + $argLists[] = array( 'ohi', 'foo' ); + + return $argLists; + } + + public function invalidConstructorArgumentsProvider() { + $argLists = array(); + + $argLists[] = array(); + + $argLists[] = array( 42 ); + $argLists[] = array( array() ); $argLists[] = array( false ); - $argLists[] = array( false, 42 ); - $argLists[] = array( false, array() ); - $argLists[] = array( false, false ); - $argLists[] = array( false, true ); - $argLists[] = array( false, null ); - $argLists[] = array( false, 'foo' ); - $argLists[] = array( false, '' ); - $argLists[] = array( false, ' foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz ' ); + $argLists[] = array( true ); + $argLists[] = array( null ); + $argLists[] = array( 'foo' ); + $argLists[] = array( '' ); + $argLists[] = array( ' foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz ' ); - $argLists[] = array( false, '', '', '', '' ); - $argLists[] = array( false, 'foo', '', '', '' ); - $argLists[] = array( false, '', 'bar', '', '' ); - $argLists[] = array( false, '', 'foo', 'bar', 'baz' ); - $argLists[] = array( false, 'foo', '', 'bar', 'baz' ); - $argLists[] = array( false, '***', 'foo', 'bar', 'baz' ); - $argLists[] = array( false, 'abc42', 'foo', 'bar', 'baz' ); + $argLists[] = array( '', '', '', '' ); + $argLists[] = array( 'foo', '', '', '' ); + $argLists[] = array( '', 'bar', '', '' ); + $argLists[] = array( '', 'foo', 'bar', 'baz' ); + $argLists[] = array( 'foo', '', 'bar', 'baz' ); + $argLists[] = array( '***', 'foo', 'bar', 'baz' ); + $argLists[] = array( 'abc42', 'foo', 'bar', 'baz' ); - $argLists[] = array( true, 'ohi', 'foo', 'bar', 'baz' ); - $argLists[] = array( true, 'http', '//www.wikidata.org/w/index.php', 'title=Special:Version', 'sv-credits-datavalues' ); - $argLists[] = array( true, 'ohi', 'foo', '', 'baz' ); - $argLists[] = array( true, 'ohi', 'foo', 'bar', '' ); - $argLists[] = array( true, 'ohi', 'foo', '', '' ); - $argLists[] = array( true, 'ohi', 'foo' ); - - $argLists[] = array( false, 'ohi', 'foo', 1 ); - $argLists[] = array( false, 'ohi', 'foo', true ); - $argLists[] = array( false, 'ohi', 'foo', 'baz', null ); - $argLists[] = array( false, 'ohi', 'foo', 'baz', array() ); + $argLists[] = array( 'ohi', 'foo', 1 ); + $argLists[] = array( 'ohi', 'foo', true ); + $argLists[] = array( 'ohi', 'foo', 'baz', null ); + $argLists[] = array( 'ohi', 'foo', 'baz', array() ); return $argLists; } diff --git a/DataValues/tests/phpunit/LatLongValueTest.php b/DataValues/tests/phpunit/LatLongValueTest.php index 49ff480..1e5d7bc 100644 --- a/DataValues/tests/phpunit/LatLongValueTest.php +++ b/DataValues/tests/phpunit/LatLongValueTest.php @@ -32,54 +32,54 @@ return 'DataValues\LatLongValue'; } - /** - * @see DataValueTest::constructorProvider - * - * @since 0.1 - * - * @return array - */ - public function constructorProvider() { + public function validConstructorArgumentsProvider() { $argLists = array(); + $argLists[] = array( 4.2, 4.2 ); + $argLists[] = array( 4.2, 42 ); + $argLists[] = array( 42, 4.2 ); + $argLists[] = array( 42, 42 ); + $argLists[] = array( -4.2, -4.2 ); + $argLists[] = array( 4.2, -42 ); + $argLists[] = array( -42, 4.2 ); + $argLists[] = array( 0, 0 ); + + return $argLists; + } + + public function invalidConstructorArgumentsProvider() { + $argLists = array(); + + $argLists[] = array(); + + $argLists[] = array( 42 ); + $argLists[] = array( array() ); $argLists[] = array( false ); - $argLists[] = array( false, 42 ); - $argLists[] = array( false, array() ); - $argLists[] = array( false, false ); - $argLists[] = array( false, true ); - $argLists[] = array( false, null ); - $argLists[] = array( false, 'foo' ); - $argLists[] = array( false, 42 ); + $argLists[] = array( true ); + $argLists[] = array( null ); + $argLists[] = array( 'foo' ); + $argLists[] = array( 42 ); - $argLists[] = array( false, 'en', 42 ); - $argLists[] = array( false, 'en', 4.2 ); - $argLists[] = array( false, 42, false ); - $argLists[] = array( false, 42, array() ); - $argLists[] = array( false, 42, null ); - $argLists[] = array( false, 42, 'foo' ); - $argLists[] = array( false, 4.2, 'foo' ); + $argLists[] = array( 'en', 42 ); + $argLists[] = array( 'en', 4.2 ); + $argLists[] = array( 42, false ); + $argLists[] = array( 42, array() ); + $argLists[] = array( 42, null ); + $argLists[] = array( 42, 'foo' ); + $argLists[] = array( 4.2, 'foo' ); - $argLists[] = array( false, '4.2', 4.2 ); - $argLists[] = array( false, '4.2', '4.2' ); - $argLists[] = array( false, 4.2, '4.2' ); - $argLists[] = array( false, '42', 42 ); - $argLists[] = array( false, 42, '42' ); - $argLists[] = array( false, '0', 0 ); + $argLists[] = array( '4.2', 4.2 ); + $argLists[] = array( '4.2', '4.2' ); + $argLists[] = array( 4.2, '4.2' ); + $argLists[] = array( '42', 42 ); + $argLists[] = array( 42, '42' ); + $argLists[] = array( '0', 0 ); - $argLists[] = array( false, -91, 0 ); - $argLists[] = array( false, -999, 1 ); - $argLists[] = array( false, 90.001, 2 ); - $argLists[] = array( false, 3, 181 ); - $argLists[] = array( false, 4, -1337 ); - - $argLists[] = array( true, 4.2, 4.2 ); - $argLists[] = array( true, 4.2, 42 ); - $argLists[] = array( true, 42, 4.2 ); - $argLists[] = array( true, 42, 42 ); - $argLists[] = array( true, -4.2, -4.2 ); - $argLists[] = array( true, 4.2, -42 ); - $argLists[] = array( true, -42, 4.2 ); - $argLists[] = array( true, 0, 0 ); + $argLists[] = array( -91, 0 ); + $argLists[] = array( -999, 1 ); + $argLists[] = array( 90.001, 2 ); + $argLists[] = array( 3, 181 ); + $argLists[] = array( 4, -1337 ); return $argLists; } diff --git a/DataValues/tests/phpunit/MonolingualTextValueTest.php b/DataValues/tests/phpunit/MonolingualTextValueTest.php index 3c3e68a..8604eee 100644 --- a/DataValues/tests/phpunit/MonolingualTextValueTest.php +++ b/DataValues/tests/phpunit/MonolingualTextValueTest.php @@ -31,31 +31,30 @@ return 'DataValues\MonolingualTextValue'; } - /** - * @see DataValueTest::constructorProvider - * - * @since 0.1 - * - * @return array - */ - public function constructorProvider() { + public function validConstructorArgumentsProvider() { $argLists = array(); + $argLists[] = array( 'en', 'foo' ); + $argLists[] = array( 'en', ' foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz ' ); + + return $argLists; + } + + public function invalidConstructorArgumentsProvider() { + $argLists = array(); + + $argLists[] = array( 42 ); + $argLists[] = array( array() ); $argLists[] = array( false ); - $argLists[] = array( false, 42 ); - $argLists[] = array( false, array() ); - $argLists[] = array( false, false ); - $argLists[] = array( false, true ); - $argLists[] = array( false, null ); - $argLists[] = array( false, 'foo' ); - $argLists[] = array( false, 'en' ); - $argLists[] = array( false, 'en', 42 ); - $argLists[] = array( false, 'en', false ); - $argLists[] = array( false, 'en', array() ); - $argLists[] = array( false, 'en', null ); - $argLists[] = array( false, '', 'foo' ); - $argLists[] = array( true, 'en', 'foo' ); - $argLists[] = array( true, 'en', ' foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz ' ); + $argLists[] = array( true ); + $argLists[] = array( null ); + $argLists[] = array( 'foo' ); + $argLists[] = array( 'en' ); + $argLists[] = array( 'en', 42 ); + $argLists[] = array( 'en', false ); + $argLists[] = array( 'en', array() ); + $argLists[] = array( 'en', null ); + $argLists[] = array( '', 'foo' ); return $argLists; } diff --git a/DataValues/tests/phpunit/MultilingualTextValueTest.php b/DataValues/tests/phpunit/MultilingualTextValueTest.php index c68584a..45da180 100644 --- a/DataValues/tests/phpunit/MultilingualTextValueTest.php +++ b/DataValues/tests/phpunit/MultilingualTextValueTest.php @@ -32,52 +32,50 @@ return 'DataValues\MultilingualTextValue'; } - /** - * @see DataValueTest::constructorProvider - * - * @since 0.1 - * - * @return array - */ - public function constructorProvider() { + public function validConstructorArgumentsProvider() { $argLists = array(); - $argLists[] = array( false ); - $argLists[] = array( false, 42 ); - $argLists[] = array( false, false ); - $argLists[] = array( false, true ); - $argLists[] = array( false, null ); - $argLists[] = array( false, 'foo' ); - $argLists[] = array( false, 'en' ); - $argLists[] = array( false, 'en', 42 ); - $argLists[] = array( false, 'en', false ); - $argLists[] = array( false, 'en', array() ); - $argLists[] = array( false, 'en', null ); - $argLists[] = array( false, '', 'foo' ); - $argLists[] = array( false, 'en', 'foo' ); - $argLists[] = array( false, 'en', ' foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz ' ); - $argLists[] = array( false, new MonolingualTextValue( 'en', 'foo' ) ); - - $argLists[] = array( true, array() ); - $argLists[] = array( true, array( new MonolingualTextValue( 'en', 'foo' ) ) ); - $argLists[] = array( true, array( new MonolingualTextValue( 'en', 'foo' ), new MonolingualTextValue( 'de', 'foo' ) ) ); - $argLists[] = array( true, array( new MonolingualTextValue( 'en', 'foo' ), new MonolingualTextValue( 'de', 'bar' ) ) ); - $argLists[] = array( true, array( + $argLists[] = array( array() ); + $argLists[] = array( array( new MonolingualTextValue( 'en', 'foo' ) ) ); + $argLists[] = array( array( new MonolingualTextValue( 'en', 'foo' ), new MonolingualTextValue( 'de', 'foo' ) ) ); + $argLists[] = array( array( new MonolingualTextValue( 'en', 'foo' ), new MonolingualTextValue( 'de', 'bar' ) ) ); + $argLists[] = array( array( new MonolingualTextValue( 'en', 'foo' ), new MonolingualTextValue( 'de', ' foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz ' ) ) ); - $argLists[] = array( false, array( 'foo' ) ); - $argLists[] = array( false, array( 42 => 'foo' ) ); - $argLists[] = array( false, array( '' => 'foo' ) ); - $argLists[] = array( false, array( 'en' => 42 ) ); - $argLists[] = array( false, array( 'en' => null ) ); - $argLists[] = array( false, array( 'en' => true ) ); - $argLists[] = array( false, array( 'en' => array() ) ); - $argLists[] = array( false, array( 'en' => 4.2 ) ); + return $argLists; + } - $argLists[] = array( false, array( new MonolingualTextValue( 'en', 'foo' ), false ) ); - $argLists[] = array( false, array( new MonolingualTextValue( 'en', 'foo' ), 'foobar' ) ); + public function invalidConstructorArgumentsProvider() { + $argLists = array(); + + $argLists[] = array( 42 ); + $argLists[] = array( false ); + $argLists[] = array( true ); + $argLists[] = array( null ); + $argLists[] = array( 'foo' ); + $argLists[] = array( 'en' ); + $argLists[] = array( 'en', 42 ); + $argLists[] = array( 'en', false ); + $argLists[] = array( 'en', array() ); + $argLists[] = array( 'en', null ); + $argLists[] = array( '', 'foo' ); + $argLists[] = array( 'en', 'foo' ); + $argLists[] = array( 'en', ' foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz ' ); + $argLists[] = array( new MonolingualTextValue( 'en', 'foo' ) ); + + $argLists[] = array( array( 'foo' ) ); + $argLists[] = array( array( 42 => 'foo' ) ); + $argLists[] = array( array( '' => 'foo' ) ); + $argLists[] = array( array( 'en' => 42 ) ); + $argLists[] = array( array( 'en' => null ) ); + $argLists[] = array( array( 'en' => true ) ); + $argLists[] = array( array( 'en' => array() ) ); + $argLists[] = array( array( 'en' => 4.2 ) ); + + $argLists[] = array( array( new MonolingualTextValue( 'en', 'foo' ), false ) ); + $argLists[] = array( array( new MonolingualTextValue( 'en', 'foo' ), 'foobar' ) ); return $argLists; } diff --git a/DataValues/tests/phpunit/NumberValueTest.php b/DataValues/tests/phpunit/NumberValueTest.php index 8046fe1..5e2d0ce 100644 --- a/DataValues/tests/phpunit/NumberValueTest.php +++ b/DataValues/tests/phpunit/NumberValueTest.php @@ -31,33 +31,32 @@ return 'DataValues\NumberValue'; } - /** - * @see DataValueTest::constructorProvider - * - * @since 0.1 - * - * @return array - */ - public function constructorProvider() { + public function validConstructorArgumentsProvider() { $argLists = array(); + $argLists[] = array( 42 ); + $argLists[] = array( -42 ); + $argLists[] = array( 4.2 ); + $argLists[] = array( -4.2 ); + $argLists[] = array( 0 ); + + return $argLists; + } + + public function invalidConstructorArgumentsProvider() { + $argLists = array(); + + $argLists[] = array( 'foo' ); + $argLists[] = array( '' ); + $argLists[] = array( '0' ); + $argLists[] = array( '42' ); + $argLists[] = array( '-42' ); + $argLists[] = array( '4.2' ); + $argLists[] = array( '-4.2' ); $argLists[] = array( false ); - $argLists[] = array( true, 42 ); - $argLists[] = array( true, -42 ); - $argLists[] = array( true, 4.2 ); - $argLists[] = array( true, -4.2 ); - $argLists[] = array( true, 0 ); - $argLists[] = array( false, 'foo' ); - $argLists[] = array( false, '' ); - $argLists[] = array( false, '0' ); - $argLists[] = array( false, '42' ); - $argLists[] = array( false, '-42' ); - $argLists[] = array( false, '4.2' ); - $argLists[] = array( false, '-4.2' ); - $argLists[] = array( false, false ); - $argLists[] = array( false, true ); - $argLists[] = array( false, null ); - $argLists[] = array( false, '0x20' ); + $argLists[] = array( true ); + $argLists[] = array( null ); + $argLists[] = array( '0x20' ); return $argLists; } diff --git a/DataValues/tests/phpunit/QuantityValueTest.php b/DataValues/tests/phpunit/QuantityValueTest.php index 4b6b41f..e45a339 100644 --- a/DataValues/tests/phpunit/QuantityValueTest.php +++ b/DataValues/tests/phpunit/QuantityValueTest.php @@ -31,63 +31,65 @@ return 'DataValues\QuantityValue'; } - /** - * @see DataValueTest::constructorProvider - * - * @since 0.1 - * - * @return array - */ - public function constructorProvider() { + public function validConstructorArgumentsProvider() { $argLists = array(); - // #0 + $argLists[] = array( 42 ); + $argLists[] = array( -42 ); + $argLists[] = array( 4.2 ); + $argLists[] = array( -4.2 ); + $argLists[] = array( 0 ); + + $argLists[] = array( 42, 'm' ); + $argLists[] = array( -42, 'm' ); + $argLists[] = array( 4.2, 'm' ); + $argLists[] = array( -4.2, 'm' ); + $argLists[] = array( 0, 'm' ); + + $argLists[] = array( 4.2, null ); + + $argLists[] = array( 42, 'm', 4.2 ); + $argLists[] = array( -42, 'm', -4.2 ); + $argLists[] = array( 4.2, 'm', -42 ); + $argLists[] = array( -4.2, 'm', 42 ); + $argLists[] = array( -42, 'm', null ); + + return $argLists; + } + + public function invalidConstructorArgumentsProvider() { + $argLists = array(); + + $argLists[] = array(); + + + $argLists[] = array( 'foo' ); + $argLists[] = array( '' ); + $argLists[] = array( '0' ); + $argLists[] = array( '42' ); + $argLists[] = array( '-42' ); + $argLists[] = array( '4.2' ); + $argLists[] = array( '-4.2' ); $argLists[] = array( false ); + $argLists[] = array( true ); + $argLists[] = array( null ); + $argLists[] = array( '0x20' ); - $argLists[] = array( true, 42 ); - $argLists[] = array( true, -42 ); - $argLists[] = array( true, 4.2 ); - $argLists[] = array( true, -4.2 ); - $argLists[] = array( true, 0 ); - $argLists[] = array( false, 'foo' ); - $argLists[] = array( false, '' ); - $argLists[] = array( false, '0' ); - $argLists[] = array( false, '42' ); - $argLists[] = array( false, '-42' ); - $argLists[] = array( false, '4.2' ); - $argLists[] = array( false, '-4.2' ); - $argLists[] = array( false, false ); - $argLists[] = array( false, true ); - $argLists[] = array( false, null ); - $argLists[] = array( false, '0x20' ); + $argLists[] = array( 'foo', 'm' ); + $argLists[] = array( '', 'm' ); + $argLists[] = array( '0', 'm' ); + $argLists[] = array( 42, 0 ); + $argLists[] = array( -42, 0 ); - // #17 - $argLists[] = array( true, 42, 'm' ); - $argLists[] = array( true, -42, 'm' ); - $argLists[] = array( true, 4.2, 'm' ); - $argLists[] = array( true, -4.2, 'm' ); - $argLists[] = array( true, 0, 'm' ); - $argLists[] = array( false, 'foo', 'm' ); - $argLists[] = array( false, '', 'm' ); - $argLists[] = array( false, '0', 'm' ); - $argLists[] = array( false, 42, 0 ); - $argLists[] = array( false, -42, 0 ); - $argLists[] = array( true, 4.2, null ); - $argLists[] = array( false, -4.2, false ); - $argLists[] = array( false, 0, true ); - $argLists[] = array( false, 'foo', array() ); - $argLists[] = array( false, '', 4.2 ); - $argLists[] = array( false, '0', -1 ); + $argLists[] = array( -4.2, false ); + $argLists[] = array( 0, true ); + $argLists[] = array( 'foo', array() ); + $argLists[] = array( '', 4.2 ); + $argLists[] = array( '0', -1 ); - // #33 - $argLists[] = array( true, 42, 'm', 4.2 ); - $argLists[] = array( true, -42, 'm', -4.2 ); - $argLists[] = array( true, 4.2, 'm', -42 ); - $argLists[] = array( true, -4.2, 'm', 42 ); - $argLists[] = array( false, 42, 'm', false ); - $argLists[] = array( true, -42, 'm', null ); - $argLists[] = array( false, 4.2, 'm', '0' ); - $argLists[] = array( false, -4.2, 'm', '-4.2' ); + $argLists[] = array( 42, 'm', false ); + $argLists[] = array( 4.2, 'm', '0' ); + $argLists[] = array( -4.2, 'm', '-4.2' ); return $argLists; } diff --git a/DataValues/tests/phpunit/StringValueTest.php b/DataValues/tests/phpunit/StringValueTest.php index 1abf77f..57b961d 100644 --- a/DataValues/tests/phpunit/StringValueTest.php +++ b/DataValues/tests/phpunit/StringValueTest.php @@ -31,25 +31,26 @@ return 'DataValues\StringValue'; } - /** - * @see DataValueTest::constructorProvider - * - * @since 0.1 - * - * @return array - */ - public function constructorProvider() { + public function validConstructorArgumentsProvider() { $argLists = array(); + $argLists[] = array( 'foo' ); + $argLists[] = array( '' ); + $argLists[] = array( ' foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz ' ); + + + return $argLists; + } + + public function invalidConstructorArgumentsProvider() { + $argLists = array(); + + $argLists[] = array( ); + $argLists[] = array( 42 ); + $argLists[] = array( array() ); $argLists[] = array( false ); - $argLists[] = array( false, 42 ); - $argLists[] = array( false, array() ); - $argLists[] = array( false, false ); - $argLists[] = array( false, true ); - $argLists[] = array( false, null ); - $argLists[] = array( true, 'foo' ); - $argLists[] = array( true, '' ); - $argLists[] = array( true, ' foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz ' ); + $argLists[] = array( true ); + $argLists[] = array( null ); return $argLists; } diff --git a/DataValues/tests/phpunit/TimeValueTest.php b/DataValues/tests/phpunit/TimeValueTest.php index ef01fb4..2bf4b55 100644 --- a/DataValues/tests/phpunit/TimeValueTest.php +++ b/DataValues/tests/phpunit/TimeValueTest.php @@ -31,18 +31,10 @@ return 'DataValues\TimeValue'; } - /** - * @see DataValueTest::constructorProvider - * - * @since 0.1 - * - * @return array - */ - public function constructorProvider() { + public function validConstructorArgumentsProvider() { $argLists = array(); $argLists[] = array( - true, '+00000002013-01-01T00:00:00Z', 0, 0, @@ -52,7 +44,6 @@ ); $argLists[] = array( - true, '+00000002013-01-01T00:00:00Z', 7200, 9001, @@ -62,7 +53,6 @@ ); $argLists[] = array( - true, '+00000002013-01-01T00:00:00Z', -7200, 0, @@ -72,167 +62,6 @@ ); $argLists[] = array( - 'DataValues\IllegalValueException', - '+00000002013-01-01T00:00:00Z', - '0', - 0, - 0, - TimeValue::PRECISION_SECOND, - 'http://nyan.cat/original.php', - ); - - $argLists[] = array( - 'DataValues\IllegalValueException', - '+00000002013-01-01T00:00:00Z', - 4.2, - 0, - 0, - TimeValue::PRECISION_SECOND, - 'http://nyan.cat/original.php', - ); - - $argLists[] = array( - 'DataValues\IllegalValueException', - '+00000002013-01-01T00:00:00Z', - -20 * 3600, - 0, - 0, - TimeValue::PRECISION_SECOND, - 'http://nyan.cat/original.php', - ); - - $argLists[] = array( - 'DataValues\IllegalValueException', - '+00000002013-01-01T00:00:00Z', - 0, - 0, - 0, - 333, - 'http://nyan.cat/original.php', - ); - - $argLists[] = array( - 'DataValues\IllegalValueException', - '+00000002013-01-01T00:00:00Z', - 0, - 0, - 0, - 9001, - 'http://nyan.cat/original.php', - ); - - $argLists[] = array( - 'DataValues\IllegalValueException', - 42, - 0, - 0, - 0, - TimeValue::PRECISION_SECOND, - 'http://nyan.cat/original.php', - ); - - $argLists[] = array( - 'DataValues\IllegalValueException', - '+00000002013-01-01T00:00:00Z', - 0, - 4.2, - 0, - TimeValue::PRECISION_SECOND, - 'http://nyan.cat/original.php', - ); - - $argLists[] = array( - 'DataValues\IllegalValueException', - '+00000002013-01-01T00:00:00Z', - 0, - 0, - -1, - TimeValue::PRECISION_SECOND, - 'http://nyan.cat/original.php', - ); - - $argLists[] = array( - 'DataValues\IllegalValueException', - 'bla', - 0, - 0, - 0, - TimeValue::PRECISION_SECOND, - 'http://nyan.cat/original.php', - ); - - $argLists[] = array( - 'DataValues\IllegalValueException', - '+00000002013/01/01 00:00:00', - 0, - 0, - 0, - TimeValue::PRECISION_SECOND, - 'http://nyan.cat/original.php', - ); - - $argLists[] = array( - 'DataValues\IllegalValueException', - '+00000002013-22-01T00:00:00Z', - 0, - 0, - 0, - TimeValue::PRECISION_SECOND, - 'http://nyan.cat/original.php', - ); - - $argLists[] = array( - 'DataValues\IllegalValueException', - '+00000002013-01-35T00:00:00Z', - 0, - 0, - 0, - TimeValue::PRECISION_SECOND, - 'http://nyan.cat/original.php', - ); - - $argLists[] = array( - 'DataValues\IllegalValueException', - '+00000002013-01-01T27:00:00Z', - 0, - 0, - 0, - TimeValue::PRECISION_SECOND, - 'http://nyan.cat/original.php', - ); - - $argLists[] = array( - 'DataValues\IllegalValueException', - '+00000002013-01-01T00:66:00Z', - 0, - 0, - 0, - TimeValue::PRECISION_SECOND, - 'http://nyan.cat/original.php', - ); - - $argLists[] = array( - 'DataValues\IllegalValueException', - '+00000002013-01-01T00:00:66Z', - 0, - 0, - 0, - TimeValue::PRECISION_SECOND, - 'http://nyan.cat/original.php', - ); - - $argLists[] = array( - 'DataValues\IllegalValueException', - '+00000002013-01-01T00:00:00+60', - 0, - 0, - 0, - TimeValue::PRECISION_SECOND, - 'http://nyan.cat/original.php', - ); - - $argLists[] = array( - true, '+2013-01-01T00:00:00Z', 0, 0, @@ -242,7 +71,6 @@ ); $argLists[] = array( - true, '-5-01-01T00:00:00Z', 0, 0, @@ -254,6 +82,156 @@ return $argLists; } + public function invalidConstructorArgumentsProvider() { + $argLists = array(); + + $argLists[] = array( + '+00000002013-01-01T00:00:00Z', + '0', + 0, + 0, + TimeValue::PRECISION_SECOND, + 'http://nyan.cat/original.php', + ); + + $argLists[] = array( + '+00000002013-01-01T00:00:00Z', + 4.2, + 0, + 0, + TimeValue::PRECISION_SECOND, + 'http://nyan.cat/original.php', + ); + + $argLists[] = array( + '+00000002013-01-01T00:00:00Z', + -20 * 3600, + 0, + 0, + TimeValue::PRECISION_SECOND, + 'http://nyan.cat/original.php', + ); + + $argLists[] = array( + '+00000002013-01-01T00:00:00Z', + 0, + 0, + 0, + 333, + 'http://nyan.cat/original.php', + ); + + $argLists[] = array( + '+00000002013-01-01T00:00:00Z', + 0, + 0, + 0, + 9001, + 'http://nyan.cat/original.php', + ); + + $argLists[] = array( + 42, + 0, + 0, + 0, + TimeValue::PRECISION_SECOND, + 'http://nyan.cat/original.php', + ); + + $argLists[] = array( + '+00000002013-01-01T00:00:00Z', + 0, + 4.2, + 0, + TimeValue::PRECISION_SECOND, + 'http://nyan.cat/original.php', + ); + + $argLists[] = array( + '+00000002013-01-01T00:00:00Z', + 0, + 0, + -1, + TimeValue::PRECISION_SECOND, + 'http://nyan.cat/original.php', + ); + + $argLists[] = array( + 'bla', + 0, + 0, + 0, + TimeValue::PRECISION_SECOND, + 'http://nyan.cat/original.php', + ); + + $argLists[] = array( + '+00000002013/01/01 00:00:00', + 0, + 0, + 0, + TimeValue::PRECISION_SECOND, + 'http://nyan.cat/original.php', + ); + + $argLists[] = array( + '+00000002013-22-01T00:00:00Z', + 0, + 0, + 0, + TimeValue::PRECISION_SECOND, + 'http://nyan.cat/original.php', + ); + + $argLists[] = array( + '+00000002013-01-35T00:00:00Z', + 0, + 0, + 0, + TimeValue::PRECISION_SECOND, + 'http://nyan.cat/original.php', + ); + + $argLists[] = array( + '+00000002013-01-01T27:00:00Z', + 0, + 0, + 0, + TimeValue::PRECISION_SECOND, + 'http://nyan.cat/original.php', + ); + + $argLists[] = array( + '+00000002013-01-01T00:66:00Z', + 0, + 0, + 0, + TimeValue::PRECISION_SECOND, + 'http://nyan.cat/original.php', + ); + + $argLists[] = array( + '+00000002013-01-01T00:00:66Z', + 0, + 0, + 0, + TimeValue::PRECISION_SECOND, + 'http://nyan.cat/original.php', + ); + + $argLists[] = array( + '+00000002013-01-01T00:00:00+60', + 0, + 0, + 0, + TimeValue::PRECISION_SECOND, + 'http://nyan.cat/original.php', + ); + + return $argLists; + } + /** * @dataProvider instanceProvider * @param TimeValue $time diff --git a/DataValues/tests/phpunit/UnDeserializableValueTest.php b/DataValues/tests/phpunit/UnDeserializableValueTest.php index 800b523..9aa267f 100644 --- a/DataValues/tests/phpunit/UnDeserializableValueTest.php +++ b/DataValues/tests/phpunit/UnDeserializableValueTest.php @@ -34,23 +34,31 @@ return 'DataValues\UnDeserializableValue'; } - /** - * @see DataValueTest::constructorProvider - * - * @since 0.1 - * - * @return array - */ - public function constructorProvider() { + public function validConstructorArgumentsProvider() { $argLists = array(); - $argLists[] = array( true, null, null, 'No type and no data' ); - $argLists[] = array( true, null, 'string', 'A type but no data' ); - $argLists[] = array( true, array( 'stuff' ), 'string', 'A type and bad data' ); + $argLists[] = array( null, null, 'No type and no data' ); + $argLists[] = array( null, 'string', 'A type but no data' ); + $argLists[] = array( array( 'stuff' ), 'string', 'A type and bad data' ); return $argLists; } + public function invalidConstructorArgumentsProvider() { + $argLists = array(); + + $argLists[] = array( new \stdClass(), null, 'No type and no data' ); + $argLists[] = array( null, 42, 'No type and no data' ); + $argLists[] = array( null, false, 'No type and no data' ); + $argLists[] = array( null, array(), 'No type and no data' ); + $argLists[] = array( null, null, null ); + $argLists[] = array( null, null, true ); + $argLists[] = array( null, null, array() ); + + return $argLists; + } + + /** * @dataProvider instanceProvider * diff --git a/DataValues/tests/phpunit/UnknownValueTest.php b/DataValues/tests/phpunit/UnknownValueTest.php index 87e77c2..9fbce11 100644 --- a/DataValues/tests/phpunit/UnknownValueTest.php +++ b/DataValues/tests/phpunit/UnknownValueTest.php @@ -32,25 +32,26 @@ return 'DataValues\UnknownValue'; } - /** - * @see DataValueTest::constructorProvider - * - * @since 0.1 - * - * @return array - */ - public function constructorProvider() { + public function validConstructorArgumentsProvider() { $argLists = array(); + $argLists[] = array( 42 ); + $argLists[] = array( array() ); $argLists[] = array( false ); - $argLists[] = array( true, 42 ); - $argLists[] = array( true, array() ); - $argLists[] = array( true, false ); - $argLists[] = array( true, true ); - $argLists[] = array( true, null ); - $argLists[] = array( true, 'foo' ); - $argLists[] = array( true, '' ); - $argLists[] = array( true, ' foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz ' ); + $argLists[] = array( true ); + $argLists[] = array( null ); + $argLists[] = array( 'foo' ); + $argLists[] = array( '' ); + $argLists[] = array( ' foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz ' ); + + + return $argLists; + } + + public function invalidConstructorArgumentsProvider() { + $argLists = array(); + + $argLists[] = array(); return $argLists; } -- To view, visit https://gerrit.wikimedia.org/r/80193 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iece3099946329cd3f078c1adeb2a14ba41924abc Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DataValues Gerrit-Branch: master Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits