Thiemo Mättig (WMDE) has uploaded a new change for review. https://gerrit.wikimedia.org/r/192300
Change subject: Rework and fix issues in DateTimeParserTest ...................................................................... Rework and fix issues in DateTimeParserTest This does not add/remove/change any of the test cases. It's pure refactoring and fixing documentation. * Fix wrong @return tag. * Add missing PHPDoc tags. * Remove @return from data providers, the fact that they always return array[] is not worth redundant documentation. * Remove redundant constructor arguments from test cases. None of these arguments is currently tested. But it's possible that this parser can parse, for example, a time zone or calendar model suffix. That's why I'm not removing the possibility to use these arguments in future tests. Change-Id: Iacfe30040fc703bbd77862beef92fc382594b725 --- M lib/tests/phpunit/parsers/DateTimeParserTest.php 1 file changed, 72 insertions(+), 63 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/00/192300/1 diff --git a/lib/tests/phpunit/parsers/DateTimeParserTest.php b/lib/tests/phpunit/parsers/DateTimeParserTest.php index d615657..2c354b9 100644 --- a/lib/tests/phpunit/parsers/DateTimeParserTest.php +++ b/lib/tests/phpunit/parsers/DateTimeParserTest.php @@ -5,8 +5,8 @@ use DataValues\TimeValue; use ValueFormatters\TimeFormatter; use ValueParsers\Test\StringValueParserTest; +use Wikibase\Lib\Parsers\DateTimeParser; use Wikibase\Lib\Parsers\EraParser; -use Wikibase\Lib\Parsers\MWTimeIsoParser; /** * @covers Wikibase\Lib\Parsers\DateTimeParser @@ -23,14 +23,17 @@ class DateTimeParserTest extends StringValueParserTest { /** - * @return MWTimeIsoParser + * @return DateTimeParser */ protected function getInstance() { $class = $this->getParserClass(); - return new $class( $this->getMockEraParser(), $this->newParserOptions() ); + return new $class( $this->getEraParser(), $this->newParserOptions() ); } - private function getMockEraParser() { + /** + * @return EraParser + */ + private function getEraParser() { $mock = $this->getMockBuilder( 'Wikibase\Lib\Parsers\EraParser' ) ->disableOriginalConstructor() ->getMock(); @@ -52,6 +55,8 @@ } /** + * @see ValueParserTestBase::getParserClass + * * @return string */ protected function getParserClass() { @@ -60,124 +65,128 @@ /** * @see ValueParserTestBase::validInputProvider - * - * @return array */ public function validInputProvider() { - $argLists = array(); + $argList = array(); $valid = array( - - // Normal / easy dates + // Normal/easy dates '10/10/2010' => - array( '+0000000000002010-10-10T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000002010-10-10T00:00:00Z' ), '10.10.2010' => - array( '+0000000000002010-10-10T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000002010-10-10T00:00:00Z' ), ' 10. 10. 2010 ' => - array( '+0000000000002010-10-10T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000002010-10-10T00:00:00Z' ), '10 10 2010' => - array( '+0000000000002010-10-10T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000002010-10-10T00:00:00Z' ), '10/10/0010' => - array( '+0000000000000010-10-10T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000000010-10-10T00:00:00Z' ), '1 July 2013' => - array( '+0000000000002013-07-01T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000002013-07-01T00:00:00Z' ), '1. July 2013' => - array( '+0000000000002013-07-01T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000002013-07-01T00:00:00Z' ), '1 Jul 2013' => - array( '+0000000000002013-07-01T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000002013-07-01T00:00:00Z' ), 'January 9 1920' => - array( '+0000000000001920-01-09T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000001920-01-09T00:00:00Z' ), 'Feb 11 1930' => - array( '+0000000000001930-02-11T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000001930-02-11T00:00:00Z' ), '1st July 2013' => - array( '+0000000000002013-07-01T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000002013-07-01T00:00:00Z' ), '2nd July 2013' => - array( '+0000000000002013-07-02T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000002013-07-02T00:00:00Z' ), '3rd July 2013' => - array( '+0000000000002013-07-03T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000002013-07-03T00:00:00Z' ), '1th July 2013' => - array( '+0000000000002013-07-01T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000002013-07-01T00:00:00Z' ), '2th July 2013' => - array( '+0000000000002013-07-02T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000002013-07-02T00:00:00Z' ), '3th July 2013' => - array( '+0000000000002013-07-03T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000002013-07-03T00:00:00Z' ), '4th July 2013' => - array( '+0000000000002013-07-04T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000002013-07-04T00:00:00Z' ), - //Year first dates + // Year first dates '2009-01-09' => - array( '+0000000000002009-01-09T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000002009-01-09T00:00:00Z' ), '55-01-09' => - array( '+0000000000000055-01-09T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000000055-01-09T00:00:00Z' ), '555-01-09' => - array( '+0000000000000555-01-09T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000000555-01-09T00:00:00Z' ), '33300-1-1' => - array( '+0000000000033300-01-01T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000033300-01-01T00:00:00Z' ), '3330002-1-1' => - array( '+0000000003330002-01-01T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000003330002-01-01T00:00:00Z' ), - //Less than 4 digit years + // Less than 4 digit years '10/10/10' => - array( '+0000000000000010-10-10T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000000010-10-10T00:00:00Z' ), '9 Jan 09' => - array( '+0000000000000009-01-09T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000000009-01-09T00:00:00Z' ), '1/1/1' => - array( '+0000000000000001-01-01T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000000001-01-01T00:00:00Z' ), '1-1-1' => - array( '+0000000000000001-01-01T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000000001-01-01T00:00:00Z' ), '31-1-55' => - array( '+0000000000000055-01-31T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000000055-01-31T00:00:00Z' ), '10-10-100' => - array( '+0000000000000100-10-10T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000000100-10-10T00:00:00Z' ), '4th July 11' => - array( '+0000000000000011-07-04T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000000011-07-04T00:00:00Z' ), '4th July 111' => - array( '+0000000000000111-07-04T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000000111-07-04T00:00:00Z' ), '4th July 1' => - array( '+0000000000000001-07-04T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000000001-07-04T00:00:00Z' ), - //More than 4 digit years + // More than 4 digit years '4th July 10000' => - array( '+0000000000010000-07-04T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000010000-07-04T00:00:00Z' ), '10/10/22000' => - array( '+0000000000022000-10-10T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000022000-10-10T00:00:00Z' ), '1-1-33300' => - array( '+0000000000033300-01-01T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000033300-01-01T00:00:00Z' ), '4th July 7214614279199781' => - array( '+7214614279199781-07-04T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+7214614279199781-07-04T00:00:00Z' ), '-10100-02-29' => - array( '-0000000000010100-03-01T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '-0000000000010100-03-01T00:00:00Z' ), // Years with leading zeros '4th July 00000002015' => - array( '+0000000000002015-07-04T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000002015-07-04T00:00:00Z' ), '00000002015-07-04' => - array( '+0000000000002015-07-04T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000002015-07-04T00:00:00Z' ), '4th July 00000092015' => - array( '+0000000000092015-07-04T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000092015-07-04T00:00:00Z' ), '00000092015-07-04' => - array( '+0000000000092015-07-04T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000092015-07-04T00:00:00Z' ), - //Testing Leap Year stuff + // Testing leap year stuff '10000-02-29' => - array( '+0000000000010000-02-29T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000010000-02-29T00:00:00Z' ), '10100-02-29' => - array( '+0000000000010100-03-01T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), + array( '+0000000000010100-03-01T00:00:00Z' ), '10400-02-29' => - array( '+0000000000010400-02-29T00:00:00Z', 0 , 0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ), - - + array( '+0000000000010400-02-29T00:00:00Z' ), ); - foreach ( $valid as $value => $expected ) { - // $time, $timezone, $before, $after, $precision, $calendarModel - $expected = new TimeValue( $expected[0], $expected[1], $expected[2], $expected[3], $expected[4], $expected[5] ); - $argLists[] = array( (string)$value, $expected ); + foreach ( $valid as $value => $args ) { + $expected = new TimeValue( + $args[0], + array_key_exists( 1, $args ) ? $args[1] : 0, + array_key_exists( 2, $args ) ? $args[2] : 0, + array_key_exists( 3, $args ) ? $args[3] : 0, + array_key_exists( 4, $args ) ? $args[4] : TimeValue::PRECISION_DAY, + array_key_exists( 5, $args ) ? $args[5] : TimeFormatter::CALENDAR_GREGORIAN + ); + $argList[] = array( (string)$value, $expected ); } - return $argLists; + return $argList; } + /** + * @see StringValueParserTest::invalidInputProvider + */ public function invalidInputProvider() { $argLists = parent::invalidInputProvider(); -- To view, visit https://gerrit.wikimedia.org/r/192300 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iacfe30040fc703bbd77862beef92fc382594b725 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits