jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/368373 )
Change subject: Wikibase: "data-values/common": "0.4.0" ...................................................................... Wikibase: "data-values/common": "0.4.0" Change-Id: I91bac9bc3dc215bf3b8c138e5ae7ecd6ba63306f --- M composer.json M composer.lock M composer/autoload_classmap.php M composer/autoload_files.php M composer/autoload_psr4.php M composer/autoload_static.php M composer/installed.json A data-values/common/.gitignore A data-values/common/.scrutinizer.yml A data-values/common/.travis.yml A data-values/common/COPYING A data-values/common/Common.php A data-values/common/README.md A data-values/common/composer.json A data-values/common/phpunit.xml.dist A data-values/common/src/DataValues/MonolingualTextValue.php A data-values/common/src/DataValues/MultilingualTextValue.php A data-values/common/src/ValueFormatters/Exceptions/MismatchingDataValueTypeException.php A data-values/common/src/ValueFormatters/StringFormatter.php A data-values/common/src/ValueParsers/BoolParser.php A data-values/common/src/ValueParsers/DispatchingValueParser.php A data-values/common/src/ValueParsers/FloatParser.php A data-values/common/src/ValueParsers/IntParser.php A data-values/common/src/ValueParsers/Normalizers/NullStringNormalizer.php A data-values/common/src/ValueParsers/Normalizers/StringNormalizer.php A data-values/common/src/ValueParsers/NullParser.php A data-values/common/src/ValueParsers/StringParser.php A data-values/common/src/ValueParsers/StringValueParser.php A data-values/common/tests/DataValues/MonolingualTextValueTest.php A data-values/common/tests/DataValues/MultilingualTextValueTest.php A data-values/common/tests/ValueFormatters/Exceptions/MismatchingDataValueTypeException.php A data-values/common/tests/ValueFormatters/StringFormatterTest.php A data-values/common/tests/ValueParsers/BoolParserTest.php A data-values/common/tests/ValueParsers/DispatchingValueParserTest.php A data-values/common/tests/ValueParsers/FloatParserTest.php A data-values/common/tests/ValueParsers/IntParserTest.php A data-values/common/tests/ValueParsers/Normalizers/NullStringNormalizerTest.php A data-values/common/tests/ValueParsers/NullParserTest.php A data-values/common/tests/ValueParsers/StringParserTest.php A data-values/common/tests/ValueParsers/StringValueParserTest.php A data-values/common/tests/ValueParsers/ValueParserTestBase.php A data-values/common/tests/bootstrap.php 42 files changed, 2,612 insertions(+), 7 deletions(-) Approvals: Legoktm: Looks good to me, approved jenkins-bot: Verified diff --git a/composer.json b/composer.json index 9cccbf1..0bf3228 100644 --- a/composer.json +++ b/composer.json @@ -37,6 +37,7 @@ "require": { "composer/semver": "1.4.2", "cssjanus/cssjanus": "1.2.0", + "data-values/common": "0.4.0", "data-values/data-values": "1.1.0", "data-values/interfaces": "0.2.5", "diff/diff": "2.2.0", diff --git a/composer.lock b/composer.lock index feb54ab..96a6f44 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "9658d48475a992ffd1943e20f7e776d2", + "content-hash": "a4da54567aeb232233426bdab2fe8202", "packages": [ { "name": "composer/semver", @@ -104,6 +104,67 @@ "time": "2017-03-14T20:57:08+00:00" }, { + "name": "data-values/common", + "version": "0.4.0", + "source": { + "type": "git", + "url": "https://github.com/DataValues/Common.git", + "reference": "0fb269955b464e54f7ca3d514e012283d48228a5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/DataValues/Common/zipball/0fb269955b464e54f7ca3d514e012283d48228a5", + "reference": "0fb269955b464e54f7ca3d514e012283d48228a5", + "shasum": "" + }, + "require": { + "data-values/data-values": "~1.0|~0.1", + "data-values/interfaces": "~0.2.0|^0.1.5", + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.3.x-dev" + } + }, + "autoload": { + "files": [ + "Common.php" + ], + "psr-4": { + "DataValues\\": "src/DataValues/", + "ValueFormatters\\": "src/ValueFormatters/", + "ValueParsers\\": "src/ValueParsers/" + }, + "classmap": [ + "tests/ValueParsers" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0+" + ], + "authors": [ + { + "name": "Jeroen De Dauw", + "email": "jeroended...@gmail.com", + "homepage": "http://jeroendedauw.com", + "role": "Developer" + } + ], + "description": "Contains common implementations of the interfaces defined by DataValuesInterfaces", + "homepage": "https://github.com/DataValues/Common", + "keywords": [ + "datavalues", + "valueformatters", + "valueparsers", + "valuevalidators", + "wikidata" + ], + "time": "2017-08-09T17:20:43+00:00" + }, + { "name": "data-values/data-values", "version": "1.1.0", "source": { diff --git a/composer/autoload_classmap.php b/composer/autoload_classmap.php index 637cd66..bf88aa0 100644 --- a/composer/autoload_classmap.php +++ b/composer/autoload_classmap.php @@ -77,6 +77,8 @@ 'DataValues\\DataValue' => $vendorDir . '/data-values/data-values/src/DataValues/DataValue.php', 'DataValues\\DataValueObject' => $vendorDir . '/data-values/data-values/src/DataValues/DataValueObject.php', 'DataValues\\IllegalValueException' => $vendorDir . '/data-values/data-values/src/DataValues/IllegalValueException.php', + 'DataValues\\MonolingualTextValue' => $vendorDir . '/data-values/common/src/DataValues/MonolingualTextValue.php', + 'DataValues\\MultilingualTextValue' => $vendorDir . '/data-values/common/src/DataValues/MultilingualTextValue.php', 'DataValues\\NumberValue' => $vendorDir . '/data-values/data-values/src/DataValues/NumberValue.php', 'DataValues\\StringValue' => $vendorDir . '/data-values/data-values/src/DataValues/StringValue.php', 'DataValues\\Tests\\DataValueTest' => $vendorDir . '/data-values/data-values/tests/phpunit/DataValueTest.php', @@ -734,13 +736,33 @@ 'UtfNormal\\Constants' => $vendorDir . '/wikimedia/utfnormal/src/Constants.php', 'UtfNormal\\Utils' => $vendorDir . '/wikimedia/utfnormal/src/Util.php', 'UtfNormal\\Validator' => $vendorDir . '/wikimedia/utfnormal/src/Validator.php', + 'ValueFormatters\\Exceptions\\MismatchingDataValueTypeException' => $vendorDir . '/data-values/common/src/ValueFormatters/Exceptions/MismatchingDataValueTypeException.php', 'ValueFormatters\\FormatterOptions' => $vendorDir . '/data-values/interfaces/src/ValueFormatters/FormatterOptions.php', 'ValueFormatters\\FormattingException' => $vendorDir . '/data-values/interfaces/src/ValueFormatters/FormattingException.php', + 'ValueFormatters\\StringFormatter' => $vendorDir . '/data-values/common/src/ValueFormatters/StringFormatter.php', 'ValueFormatters\\Test\\ValueFormatterTestBase' => $vendorDir . '/data-values/interfaces/tests/ValueFormatters/ValueFormatterTestBase.php', 'ValueFormatters\\ValueFormatter' => $vendorDir . '/data-values/interfaces/src/ValueFormatters/ValueFormatter.php', 'ValueFormatters\\ValueFormatterBase' => $vendorDir . '/data-values/interfaces/src/ValueFormatters/ValueFormatterBase.php', + 'ValueParsers\\BoolParser' => $vendorDir . '/data-values/common/src/ValueParsers/BoolParser.php', + 'ValueParsers\\DispatchingValueParser' => $vendorDir . '/data-values/common/src/ValueParsers/DispatchingValueParser.php', + 'ValueParsers\\FloatParser' => $vendorDir . '/data-values/common/src/ValueParsers/FloatParser.php', + 'ValueParsers\\IntParser' => $vendorDir . '/data-values/common/src/ValueParsers/IntParser.php', + 'ValueParsers\\Normalizers\\NullStringNormalizer' => $vendorDir . '/data-values/common/src/ValueParsers/Normalizers/NullStringNormalizer.php', + 'ValueParsers\\Normalizers\\StringNormalizer' => $vendorDir . '/data-values/common/src/ValueParsers/Normalizers/StringNormalizer.php', + 'ValueParsers\\Normalizers\\Test\\NullStringNormalizerTest' => $vendorDir . '/data-values/common/tests/ValueParsers/Normalizers/NullStringNormalizerTest.php', + 'ValueParsers\\NullParser' => $vendorDir . '/data-values/common/src/ValueParsers/NullParser.php', 'ValueParsers\\ParseException' => $vendorDir . '/data-values/interfaces/src/ValueParsers/ParseException.php', 'ValueParsers\\ParserOptions' => $vendorDir . '/data-values/interfaces/src/ValueParsers/ParserOptions.php', + 'ValueParsers\\StringParser' => $vendorDir . '/data-values/common/src/ValueParsers/StringParser.php', + 'ValueParsers\\StringValueParser' => $vendorDir . '/data-values/common/src/ValueParsers/StringValueParser.php', + 'ValueParsers\\Test\\BoolParserTest' => $vendorDir . '/data-values/common/tests/ValueParsers/BoolParserTest.php', + 'ValueParsers\\Test\\DispatchingValueParserTest' => $vendorDir . '/data-values/common/tests/ValueParsers/DispatchingValueParserTest.php', + 'ValueParsers\\Test\\FloatParserTest' => $vendorDir . '/data-values/common/tests/ValueParsers/FloatParserTest.php', + 'ValueParsers\\Test\\IntParserTest' => $vendorDir . '/data-values/common/tests/ValueParsers/IntParserTest.php', + 'ValueParsers\\Test\\NullParserTest' => $vendorDir . '/data-values/common/tests/ValueParsers/NullParserTest.php', + 'ValueParsers\\Test\\StringParserTest' => $vendorDir . '/data-values/common/tests/ValueParsers/StringParserTest.php', + 'ValueParsers\\Test\\StringValueParserTest' => $vendorDir . '/data-values/common/tests/ValueParsers/StringValueParserTest.php', + 'ValueParsers\\Test\\ValueParserTestBase' => $vendorDir . '/data-values/common/tests/ValueParsers/ValueParserTestBase.php', 'ValueParsers\\ValueParser' => $vendorDir . '/data-values/interfaces/src/ValueParsers/ValueParser.php', 'ValueValidators\\Error' => $vendorDir . '/data-values/interfaces/src/ValueValidators/Error.php', 'ValueValidators\\Result' => $vendorDir . '/data-values/interfaces/src/ValueValidators/Result.php', diff --git a/composer/autoload_files.php b/composer/autoload_files.php index d5b1bc3..b190456 100644 --- a/composer/autoload_files.php +++ b/composer/autoload_files.php @@ -7,12 +7,13 @@ return array( 'a24b5daa493ecb5e767c7d1592a8da36' => $vendorDir . '/mediawiki/at-ease/src/Functions.php', + 'd1715cacc3c23b16a030645514266a76' => $vendorDir . '/data-values/interfaces/Interfaces.php', + '7cb394c3af2b1ae832979b0368e0da62' => $vendorDir . '/data-values/data-values/DataValues.php', 'c3f7f0e81464740a933532e81fa26cc7' => $vendorDir . '/wikimedia/base-convert/src/Functions.php', 'c50606d667a3fde2b80a955639479d3d' => $vendorDir . '/wikimedia/timestamp/src/defines.php', '04c6c5c2f7095ccf6c481d3e53e1776f' => $vendorDir . '/mustangostang/spyc/Spyc.php', 'd55c27a601de788b19a09b7d057d07ae' => $vendorDir . '/wikimedia/relpath/src/RelPath.php', 'f4c767faab43077fd89ff7cf99ffb4b8' => $vendorDir . '/serialization/serialization/Serialization.php', '3ef87127dc6892a0a78f223558a0b940' => $vendorDir . '/diff/diff/Diff.php', - 'd1715cacc3c23b16a030645514266a76' => $vendorDir . '/data-values/interfaces/Interfaces.php', - '7cb394c3af2b1ae832979b0368e0da62' => $vendorDir . '/data-values/data-values/DataValues.php', + '90559502573a0d473dc66fde5c0ff7e2' => $vendorDir . '/data-values/common/Common.php', ); diff --git a/composer/autoload_psr4.php b/composer/autoload_psr4.php index ea23663..f2e4b41 100644 --- a/composer/autoload_psr4.php +++ b/composer/autoload_psr4.php @@ -13,8 +13,8 @@ 'Wikimedia\\Assert\\Test\\' => array($vendorDir . '/wikimedia/assert/tests/phpunit'), 'Wikimedia\\Assert\\' => array($vendorDir . '/wikimedia/assert/src'), 'ValueValidators\\' => array($vendorDir . '/data-values/interfaces/src/ValueValidators'), - 'ValueParsers\\' => array($vendorDir . '/data-values/interfaces/src/ValueParsers'), - 'ValueFormatters\\' => array($vendorDir . '/data-values/interfaces/src/ValueFormatters'), + 'ValueParsers\\' => array($vendorDir . '/data-values/interfaces/src/ValueParsers', $vendorDir . '/data-values/common/src/ValueParsers'), + 'ValueFormatters\\' => array($vendorDir . '/data-values/interfaces/src/ValueFormatters', $vendorDir . '/data-values/common/src/ValueFormatters'), 'Symfony\\Component\\Process\\' => array($vendorDir . '/symfony/process'), 'Serializers\\' => array($vendorDir . '/serialization/serialization/src/Serializers'), 'RemexHtml\\' => array($vendorDir . '/wikimedia/remex-html/RemexHtml'), @@ -26,6 +26,7 @@ 'Elastica\\' => array($vendorDir . '/ruflin/elastica/lib/Elastica'), 'Diff\\' => array($vendorDir . '/diff/diff/src'), 'Deserializers\\' => array($vendorDir . '/serialization/serialization/src/Deserializers'), + 'DataValues\\' => array($vendorDir . '/data-values/common/src/DataValues'), 'Composer\\Semver\\' => array($vendorDir . '/composer/semver/src'), 'CLDRPluralRuleParser\\' => array($vendorDir . '/wikimedia/cldr-plural-rule-parser/src'), ); diff --git a/composer/autoload_static.php b/composer/autoload_static.php index 8d992b9..042ee2d 100644 --- a/composer/autoload_static.php +++ b/composer/autoload_static.php @@ -8,14 +8,15 @@ { public static $files = array ( 'a24b5daa493ecb5e767c7d1592a8da36' => __DIR__ . '/..' . '/mediawiki/at-ease/src/Functions.php', + 'd1715cacc3c23b16a030645514266a76' => __DIR__ . '/..' . '/data-values/interfaces/Interfaces.php', + '7cb394c3af2b1ae832979b0368e0da62' => __DIR__ . '/..' . '/data-values/data-values/DataValues.php', 'c3f7f0e81464740a933532e81fa26cc7' => __DIR__ . '/..' . '/wikimedia/base-convert/src/Functions.php', 'c50606d667a3fde2b80a955639479d3d' => __DIR__ . '/..' . '/wikimedia/timestamp/src/defines.php', '04c6c5c2f7095ccf6c481d3e53e1776f' => __DIR__ . '/..' . '/mustangostang/spyc/Spyc.php', 'd55c27a601de788b19a09b7d057d07ae' => __DIR__ . '/..' . '/wikimedia/relpath/src/RelPath.php', 'f4c767faab43077fd89ff7cf99ffb4b8' => __DIR__ . '/..' . '/serialization/serialization/Serialization.php', '3ef87127dc6892a0a78f223558a0b940' => __DIR__ . '/..' . '/diff/diff/Diff.php', - 'd1715cacc3c23b16a030645514266a76' => __DIR__ . '/..' . '/data-values/interfaces/Interfaces.php', - '7cb394c3af2b1ae832979b0368e0da62' => __DIR__ . '/..' . '/data-values/data-values/DataValues.php', + '90559502573a0d473dc66fde5c0ff7e2' => __DIR__ . '/..' . '/data-values/common/Common.php', ); public static $prefixLengthsPsr4 = array ( @@ -71,6 +72,7 @@ array ( 'Diff\\' => 5, 'Deserializers\\' => 14, + 'DataValues\\' => 11, ), 'C' => array ( @@ -111,10 +113,12 @@ 'ValueParsers\\' => array ( 0 => __DIR__ . '/..' . '/data-values/interfaces/src/ValueParsers', + 1 => __DIR__ . '/..' . '/data-values/common/src/ValueParsers', ), 'ValueFormatters\\' => array ( 0 => __DIR__ . '/..' . '/data-values/interfaces/src/ValueFormatters', + 1 => __DIR__ . '/..' . '/data-values/common/src/ValueFormatters', ), 'Symfony\\Component\\Process\\' => array ( @@ -159,6 +163,10 @@ 'Deserializers\\' => array ( 0 => __DIR__ . '/..' . '/serialization/serialization/src/Deserializers', + ), + 'DataValues\\' => + array ( + 0 => __DIR__ . '/..' . '/data-values/common/src/DataValues', ), 'Composer\\Semver\\' => array ( @@ -320,6 +328,8 @@ 'DataValues\\DataValue' => __DIR__ . '/..' . '/data-values/data-values/src/DataValues/DataValue.php', 'DataValues\\DataValueObject' => __DIR__ . '/..' . '/data-values/data-values/src/DataValues/DataValueObject.php', 'DataValues\\IllegalValueException' => __DIR__ . '/..' . '/data-values/data-values/src/DataValues/IllegalValueException.php', + 'DataValues\\MonolingualTextValue' => __DIR__ . '/..' . '/data-values/common/src/DataValues/MonolingualTextValue.php', + 'DataValues\\MultilingualTextValue' => __DIR__ . '/..' . '/data-values/common/src/DataValues/MultilingualTextValue.php', 'DataValues\\NumberValue' => __DIR__ . '/..' . '/data-values/data-values/src/DataValues/NumberValue.php', 'DataValues\\StringValue' => __DIR__ . '/..' . '/data-values/data-values/src/DataValues/StringValue.php', 'DataValues\\Tests\\DataValueTest' => __DIR__ . '/..' . '/data-values/data-values/tests/phpunit/DataValueTest.php', @@ -977,13 +987,33 @@ 'UtfNormal\\Constants' => __DIR__ . '/..' . '/wikimedia/utfnormal/src/Constants.php', 'UtfNormal\\Utils' => __DIR__ . '/..' . '/wikimedia/utfnormal/src/Util.php', 'UtfNormal\\Validator' => __DIR__ . '/..' . '/wikimedia/utfnormal/src/Validator.php', + 'ValueFormatters\\Exceptions\\MismatchingDataValueTypeException' => __DIR__ . '/..' . '/data-values/common/src/ValueFormatters/Exceptions/MismatchingDataValueTypeException.php', 'ValueFormatters\\FormatterOptions' => __DIR__ . '/..' . '/data-values/interfaces/src/ValueFormatters/FormatterOptions.php', 'ValueFormatters\\FormattingException' => __DIR__ . '/..' . '/data-values/interfaces/src/ValueFormatters/FormattingException.php', + 'ValueFormatters\\StringFormatter' => __DIR__ . '/..' . '/data-values/common/src/ValueFormatters/StringFormatter.php', 'ValueFormatters\\Test\\ValueFormatterTestBase' => __DIR__ . '/..' . '/data-values/interfaces/tests/ValueFormatters/ValueFormatterTestBase.php', 'ValueFormatters\\ValueFormatter' => __DIR__ . '/..' . '/data-values/interfaces/src/ValueFormatters/ValueFormatter.php', 'ValueFormatters\\ValueFormatterBase' => __DIR__ . '/..' . '/data-values/interfaces/src/ValueFormatters/ValueFormatterBase.php', + 'ValueParsers\\BoolParser' => __DIR__ . '/..' . '/data-values/common/src/ValueParsers/BoolParser.php', + 'ValueParsers\\DispatchingValueParser' => __DIR__ . '/..' . '/data-values/common/src/ValueParsers/DispatchingValueParser.php', + 'ValueParsers\\FloatParser' => __DIR__ . '/..' . '/data-values/common/src/ValueParsers/FloatParser.php', + 'ValueParsers\\IntParser' => __DIR__ . '/..' . '/data-values/common/src/ValueParsers/IntParser.php', + 'ValueParsers\\Normalizers\\NullStringNormalizer' => __DIR__ . '/..' . '/data-values/common/src/ValueParsers/Normalizers/NullStringNormalizer.php', + 'ValueParsers\\Normalizers\\StringNormalizer' => __DIR__ . '/..' . '/data-values/common/src/ValueParsers/Normalizers/StringNormalizer.php', + 'ValueParsers\\Normalizers\\Test\\NullStringNormalizerTest' => __DIR__ . '/..' . '/data-values/common/tests/ValueParsers/Normalizers/NullStringNormalizerTest.php', + 'ValueParsers\\NullParser' => __DIR__ . '/..' . '/data-values/common/src/ValueParsers/NullParser.php', 'ValueParsers\\ParseException' => __DIR__ . '/..' . '/data-values/interfaces/src/ValueParsers/ParseException.php', 'ValueParsers\\ParserOptions' => __DIR__ . '/..' . '/data-values/interfaces/src/ValueParsers/ParserOptions.php', + 'ValueParsers\\StringParser' => __DIR__ . '/..' . '/data-values/common/src/ValueParsers/StringParser.php', + 'ValueParsers\\StringValueParser' => __DIR__ . '/..' . '/data-values/common/src/ValueParsers/StringValueParser.php', + 'ValueParsers\\Test\\BoolParserTest' => __DIR__ . '/..' . '/data-values/common/tests/ValueParsers/BoolParserTest.php', + 'ValueParsers\\Test\\DispatchingValueParserTest' => __DIR__ . '/..' . '/data-values/common/tests/ValueParsers/DispatchingValueParserTest.php', + 'ValueParsers\\Test\\FloatParserTest' => __DIR__ . '/..' . '/data-values/common/tests/ValueParsers/FloatParserTest.php', + 'ValueParsers\\Test\\IntParserTest' => __DIR__ . '/..' . '/data-values/common/tests/ValueParsers/IntParserTest.php', + 'ValueParsers\\Test\\NullParserTest' => __DIR__ . '/..' . '/data-values/common/tests/ValueParsers/NullParserTest.php', + 'ValueParsers\\Test\\StringParserTest' => __DIR__ . '/..' . '/data-values/common/tests/ValueParsers/StringParserTest.php', + 'ValueParsers\\Test\\StringValueParserTest' => __DIR__ . '/..' . '/data-values/common/tests/ValueParsers/StringValueParserTest.php', + 'ValueParsers\\Test\\ValueParserTestBase' => __DIR__ . '/..' . '/data-values/common/tests/ValueParsers/ValueParserTestBase.php', 'ValueParsers\\ValueParser' => __DIR__ . '/..' . '/data-values/interfaces/src/ValueParsers/ValueParser.php', 'ValueValidators\\Error' => __DIR__ . '/..' . '/data-values/interfaces/src/ValueValidators/Error.php', 'ValueValidators\\Result' => __DIR__ . '/..' . '/data-values/interfaces/src/ValueValidators/Result.php', diff --git a/composer/installed.json b/composer/installed.json index 0e46ace..9658540 100644 --- a/composer/installed.json +++ b/composer/installed.json @@ -2644,5 +2644,68 @@ "wikibase", "wikidata" ] + }, + { + "name": "data-values/common", + "version": "0.4.0", + "version_normalized": "0.4.0.0", + "source": { + "type": "git", + "url": "https://github.com/DataValues/Common.git", + "reference": "0fb269955b464e54f7ca3d514e012283d48228a5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/DataValues/Common/zipball/0fb269955b464e54f7ca3d514e012283d48228a5", + "reference": "0fb269955b464e54f7ca3d514e012283d48228a5", + "shasum": "" + }, + "require": { + "data-values/data-values": "~1.0|~0.1", + "data-values/interfaces": "~0.2.0|^0.1.5", + "php": ">=5.3.0" + }, + "time": "2017-08-09T17:20:43+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.3.x-dev" + } + }, + "installation-source": "dist", + "autoload": { + "files": [ + "Common.php" + ], + "psr-4": { + "DataValues\\": "src/DataValues/", + "ValueFormatters\\": "src/ValueFormatters/", + "ValueParsers\\": "src/ValueParsers/" + }, + "classmap": [ + "tests/ValueParsers" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0+" + ], + "authors": [ + { + "name": "Jeroen De Dauw", + "email": "jeroended...@gmail.com", + "homepage": "http://jeroendedauw.com", + "role": "Developer" + } + ], + "description": "Contains common implementations of the interfaces defined by DataValuesInterfaces", + "homepage": "https://github.com/DataValues/Common", + "keywords": [ + "datavalues", + "valueformatters", + "valueparsers", + "valuevalidators", + "wikidata" + ] } ] diff --git a/data-values/common/.gitignore b/data-values/common/.gitignore new file mode 100644 index 0000000..577795c --- /dev/null +++ b/data-values/common/.gitignore @@ -0,0 +1,12 @@ +*~ +*.kate-swp +*.swp + +!.* + +.idea/ +build/ +vendor/ + +composer.phar +composer.lock \ No newline at end of file diff --git a/data-values/common/.scrutinizer.yml b/data-values/common/.scrutinizer.yml new file mode 100644 index 0000000..d6c0c6b --- /dev/null +++ b/data-values/common/.scrutinizer.yml @@ -0,0 +1,13 @@ +build: true +inherit: true + +tools: + php_code_coverage: true + php_code_sniffer: true + php_cpd: true + php_cs_fixer: true + php_loc: true + php_mess_detector: true + php_pdepend: true + php_analyzer: true + sensiolabs_security_checker: true diff --git a/data-values/common/.travis.yml b/data-values/common/.travis.yml new file mode 100644 index 0000000..3484c76 --- /dev/null +++ b/data-values/common/.travis.yml @@ -0,0 +1,15 @@ +language: php + +php: + - 5.3 + - 5.4 + - 5.5 + - 5.6 + - 7 + - hhvm + +before_script: + - travis_retry composer install --prefer-source + +script: + - composer ci diff --git a/data-values/common/COPYING b/data-values/common/COPYING new file mode 100644 index 0000000..ebba08a --- /dev/null +++ b/data-values/common/COPYING @@ -0,0 +1,347 @@ +The license text below "----" applies to all files within this distribution, other +than those that are in a directory which contains files named "LICENSE" or +"COPYING", or a subdirectory thereof. For those files, the license text contained in +said file overrides any license information contained in directories of smaller depth. +Alternative licenses are typically used for software that is provided by external +parties, and merely packaged with this software for convenience. +---- + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + 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. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/data-values/common/Common.php b/data-values/common/Common.php new file mode 100644 index 0000000..a760de2 --- /dev/null +++ b/data-values/common/Common.php @@ -0,0 +1,18 @@ +<?php + +/** + * Entry point of the DataValues Common library. + * + * @since 0.1 + * @codeCoverageIgnore + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ + +if ( defined( 'DATAVALUES_COMMON_VERSION' ) ) { + // Do not initialize more than once. + return 1; +} + +define( 'DATAVALUES_COMMON_VERSION', '0.3.1' ); diff --git a/data-values/common/README.md b/data-values/common/README.md new file mode 100644 index 0000000..c0a8404 --- /dev/null +++ b/data-values/common/README.md @@ -0,0 +1,114 @@ +# DataValues Common + +DataValues Common is a small library build on top of DataValues that provides common +implementations of the DataValues, ValueParsers, ValueFormatters and ValueValidators interfaces. + +It is part of the [DataValues set of libraries](https://github.com/DataValues). + +[![Build Status](https://secure.travis-ci.org/DataValues/Common.png?branch=master)](http://travis-ci.org/DataValues/Common) +[![Code Coverage](https://scrutinizer-ci.com/g/DataValues/Common/badges/coverage.png?s=728b9287ebdd13fbe15255d4d55575c5b5d47b8f)](https://scrutinizer-ci.com/g/DataValues/Common/) +[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/DataValues/Common/badges/quality-score.png?s=3195539d2e929aafaefb4bc006fb0da6c09a4d2a)](https://scrutinizer-ci.com/g/DataValues/Common/) + +On [Packagist](https://packagist.org/packages/data-values/common): +[![Latest Stable Version](https://poser.pugx.org/data-values/common/version.png)](https://packagist.org/packages/data-values/common) +[![Download count](https://poser.pugx.org/data-values/common/d/total.png)](https://packagist.org/packages/data-values/common) + +## Installation + +The recommended way to use this library is via [Composer](http://getcomposer.org/). + +### Composer + +To add this package as a local, per-project dependency to your project, simply add a +dependency on `data-values/common` to your project's `composer.json` file. +Here is a minimal example of a `composer.json` file that just defines a dependency on +version 0.3 of this package: + + { + "require": { + "data-values/common": "0.3.*" + } + } + +### Manual + +Get the code of this package, either via git, or some other means. Also get all dependencies. +You can find a list of the dependencies in the "require" section of the composer.json file. +Then take care of autoloading the classes defined in the src directory. + +## Tests + +This library comes with a set up PHPUnit tests that cover all non-trivial code. You can run these +tests using the PHPUnit configuration file found in the root directory. The tests can also be run +via TravisCI, as a TravisCI configuration file is also provided in the root directory. + +## Authors + +DataValues Common has been written by the Wikidata team, as [Wikimedia Germany] +(https://wikimedia.de) employees for the [Wikidata project](https://wikidata.org/). + +## Release notes + +### 0.4.0 (2017-08-09) + +* Removed MediaWiki integration + +### 0.3.1 (2015-08-14) + +* The component can now be installed together with DataValues Interfaces 0.1.5 + +### 0.3.0 (2015-08-11) + +* Added `DispatchingValueParser` +* Added `StringNormalizer` interface +* Added `NullStringNormalizer` +* Added `StringParser` +* Dropped deprecated constant `DataValuesCommon_VERSION`, use `DATAVALUES_COMMON_VERSION` instead +* Dropped `ValueParserTestBase::getParserClass` +* Dropped `ValueParserTestBase::newParserOptions` +* Made `ValueParserTestBase::getInstance` abstract +* Made `ValueParserTestBase::invalidInputProvider` abstract +* Lowered visibility of all class fields to private + +### 0.2.3 (2014-10-09) + +* Introduced `FORMAT_NAME` class constants on ValueParsers in order to use them as expectedFormat +* Changed ValueParsers to pass rawValue and expectedFormat arguments when constructing a `ParseException` +* Installation together with DataValues 1.x is now supported + +### 0.2.2 (2014-04-11) + +* Introduced `DataValueMismatchException` + +### 0.2.1 (2014-03-12) + +* Minor code cleanup +* Improved PHPUnit bootstrap + +### 0.2 (2013-12-16) + +* Added FloatParser (moved from data-values/number) +* Added IntParser (moved from data-values/number) + +### 0.1.1 (2013-11-22) + +* Fixed link in the MediaWiki credits + +### 0.1 (2013-11-17) + +Initial release with these features: + +* Several DataValue implementations + * MonolingualTextValue + * MultilingualTextValue +* Several ValueFormatter implementations + * StringFormatter +* Several ValueParser implementations + * BoolParser + * DecimalParser + * NullParser + +## Links + +* [DataValues Common on Packagist](https://packagist.org/packages/data-values/common) +* [DataValues Common on TravisCI](https://travis-ci.org/DataValues/Common) diff --git a/data-values/common/composer.json b/data-values/common/composer.json new file mode 100644 index 0000000..45f01ef --- /dev/null +++ b/data-values/common/composer.json @@ -0,0 +1,57 @@ +{ + "name": "data-values/common", + "type": "library", + "description": "Contains common implementations of the interfaces defined by DataValuesInterfaces", + "keywords": [ + "datavalues", + "valueparsers", + "valueformatters", + "valuevalidators", + "wikidata" + ], + "homepage": "https://github.com/DataValues/Common", + "license": "GPL-2.0+", + "authors": [ + { + "name": "Jeroen De Dauw", + "email": "jeroended...@gmail.com", + "homepage": "http://jeroendedauw.com", + "role": "Developer" + } + ], + "support": { + "irc": "irc://irc.freenode.net/wikidata" + }, + "require": { + "php": ">=5.3.0", + "data-values/data-values": "~1.0|~0.1", + "data-values/interfaces": "~0.2.0|^0.1.5" + }, + "extra": { + "branch-alias": { + "dev-master": "0.3.x-dev" + } + }, + "autoload": { + "files" : [ + "Common.php" + ], + "psr-4": { + "DataValues\\": "src/DataValues/", + "ValueFormatters\\": "src/ValueFormatters/", + "ValueParsers\\": "src/ValueParsers/" + }, + "classmap": [ + "tests/ValueParsers" + ] + }, + "scripts": { + "test": [ + "composer validate --no-interaction", + "phpunit --coverage-text=/dev/null" + ], + "ci": [ + "composer test" + ] + } +} diff --git a/data-values/common/phpunit.xml.dist b/data-values/common/phpunit.xml.dist new file mode 100644 index 0000000..1c6adb1 --- /dev/null +++ b/data-values/common/phpunit.xml.dist @@ -0,0 +1,24 @@ +<phpunit backupGlobals="false" + backupStaticAttributes="false" + bootstrap="tests/bootstrap.php" + cacheTokens="false" + colors="true" + convertErrorsToExceptions="true" + convertNoticesToExceptions="true" + convertWarningsToExceptions="true" + stopOnError="false" + stopOnFailure="false" + stopOnIncomplete="false" + stopOnSkipped="false" + verbose="true"> + <testsuites> + <testsuite name="DataValuesCommon"> + <directory>tests</directory> + </testsuite> + </testsuites> + <filter> + <whitelist addUncoveredFilesFromWhitelist="true"> + <directory suffix=".php">src</directory> + </whitelist> + </filter> +</phpunit> diff --git a/data-values/common/src/DataValues/MonolingualTextValue.php b/data-values/common/src/DataValues/MonolingualTextValue.php new file mode 100644 index 0000000..dcd3cd2 --- /dev/null +++ b/data-values/common/src/DataValues/MonolingualTextValue.php @@ -0,0 +1,147 @@ +<?php + +namespace DataValues; + +/** + * Class representing a monolingual text value. + * + * @since 0.1 + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ +class MonolingualTextValue extends DataValueObject { + + /** + * @var string + */ + private $text; + + /** + * @var string + */ + private $languageCode; + + /** + * @since 0.1 + * + * @param string $languageCode + * @param string $text + * + * @throws IllegalValueException + */ + public function __construct( $languageCode, $text ) { + if ( !is_string( $languageCode ) ) { + throw new IllegalValueException( 'Can only construct MonolingualTextValue with a string language code.' ); + } + elseif ( $languageCode === '' ) { + throw new IllegalValueException( 'Can not construct a MonolingualTextValue with an empty language code.' ); + } + + if ( !is_string( $text ) ) { + throw new IllegalValueException( 'Can only construct a MonolingualTextValue with a string value.' ); + } + + $this->text = $text; + $this->languageCode = $languageCode; + } + + /** + * @see Serializable::serialize + * + * @return string + */ + public function serialize() { + return serialize( array( $this->languageCode, $this->text ) ); + } + + /** + * @see Serializable::unserialize + * + * @param string $value + */ + public function unserialize( $value ) { + list( $languageCode, $text ) = unserialize( $value ); + $this->__construct( $languageCode, $text ); + } + + /** + * @see DataValue::getType + * + * @return string + */ + public static function getType() { + return 'monolingualtext'; + } + + /** + * @see DataValue::getSortKey + * + * @return string + */ + public function getSortKey() { + // TODO: we might want to re-think this key. Perhaps the language should simply be omitted. + return $this->languageCode . $this->text; + } + + /** + * @see DataValue::getValue + * + * @return MonolingualTextValue + */ + public function getValue() { + return $this; + } + + /** + * Returns the text. + * + * @since 0.1 + * + * @return string + */ + public function getText() { + return $this->text; + } + + /** + * Returns the language code. + * + * @since 0.1 + * + * @return string + */ + public function getLanguageCode() { + return $this->languageCode; + } + + /** + * @see DataValue::getArrayValue + * + * @return string[] + */ + public function getArrayValue() { + return array( + 'text' => $this->text, + 'language' => $this->languageCode, + ); + } + + /** + * Constructs a new instance of the DataValue from the provided data. + * This can round-trip with @see getArrayValue + * + * @since 0.1 + * + * @param string[] $data + * + * @return MonolingualTextValue + * @throws IllegalValueException + */ + public static function newFromArray( $data ) { + self::requireArrayFields( $data, array( 'language', 'text' ) ); + + return new static( $data['language'], $data['text'] ); + } + +} diff --git a/data-values/common/src/DataValues/MultilingualTextValue.php b/data-values/common/src/DataValues/MultilingualTextValue.php new file mode 100644 index 0000000..97e3bbe --- /dev/null +++ b/data-values/common/src/DataValues/MultilingualTextValue.php @@ -0,0 +1,146 @@ +<?php + +namespace DataValues; + +/** + * Class representing a multilingual text value. + * + * @since 0.1 + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ +class MultilingualTextValue extends DataValueObject { + + /** + * Array with language codes pointing to their associated texts. + * + * @var MonolingualTextValue[] + */ + private $texts = array(); + + /** + * @since 0.1 + * + * @param MonolingualTextValue[] $monolingualValues + * + * @throws IllegalValueException + */ + public function __construct( array $monolingualValues ) { + foreach ( $monolingualValues as $monolingualValue ) { + if ( !( $monolingualValue instanceof MonolingualTextValue ) ) { + throw new IllegalValueException( 'Can only construct MultilingualTextValue from MonolingualTextValue objects' ); + } + + $languageCode = $monolingualValue->getLanguageCode(); + + if ( array_key_exists( $languageCode, $this->texts ) ) { + throw new IllegalValueException( 'Can only add a single MonolingualTextValue per language to a MultilingualTextValue' ); + } + + $this->texts[$languageCode] = $monolingualValue; + } + } + + /** + * @see Serializable::serialize + * + * @return string + */ + public function serialize() { + return serialize( $this->texts ); + } + + /** + * @see Serializable::unserialize + * + * @param string $value + */ + public function unserialize( $value ) { + $this->__construct( unserialize( $value ) ); + } + + /** + * @see DataValue::getType + * + * @return string + */ + public static function getType() { + return 'multilingualtext'; + } + + /** + * @see DataValue::getSortKey + * + * @return string|float|int + */ + public function getSortKey() { + return empty( $this->texts ) ? '' : reset( $this->texts )->getSortKey(); + } + + /** + * Returns the texts as an array of monolingual text values. + * + * @since 0.1 + * + * @return MonolingualTextValue[] + */ + public function getTexts() { + return $this->texts; + } + + /** + * Returns the multilingual text value + * @see DataValue::getValue + * + * @return MultilingualTextValue + */ + public function getValue() { + return $this; + } + + /** + * @see DataValue::getArrayValue + * + * @return mixed + */ + public function getArrayValue() { + $values = array(); + + /** + * @var MonolingualTextValue $text + */ + foreach ( $this->texts as $text ) { + $values[] = $text->getArrayValue(); + } + + return $values; + } + + /** + * Constructs a new instance of the DataValue from the provided data. + * This can round-trip with + * @see getArrayValue + * + * @since 0.1 + * + * @param mixed $data + * + * @throws IllegalValueException if $data is not an array. + * @return MultilingualTextValue + */ + public static function newFromArray( $data ) { + if ( !is_array( $data ) ) { + throw new IllegalValueException( "array expected" ); + } + + $values = array(); + + foreach ( $data as $monolingualValue ) { + $values[] = MonolingualTextValue::newFromArray( $monolingualValue ); + } + + return new static( $values ); + } + +} diff --git a/data-values/common/src/ValueFormatters/Exceptions/MismatchingDataValueTypeException.php b/data-values/common/src/ValueFormatters/Exceptions/MismatchingDataValueTypeException.php new file mode 100644 index 0000000..a07825e --- /dev/null +++ b/data-values/common/src/ValueFormatters/Exceptions/MismatchingDataValueTypeException.php @@ -0,0 +1,58 @@ +<?php + +namespace ValueFormatters\Exceptions; + +use Exception; +use ValueFormatters\FormattingException; + +/** + * @since 0.2.1 + * + * @licence GNU GPL v2+ + * @author Katie Filbert < aude.w...@gmail.com > + */ +class MismatchingDataValueTypeException extends FormattingException { + + /** + * @var string + */ + private $expectedValueType; + + /** + * @var string + */ + private $dataValueType; + + /** + * @param string $expectedValueType + * @param string $dataValueType + * @param string $message + * @param Exception $previous + */ + public function __construct( $expectedValueType, $dataValueType, $message = '', + Exception $previous = null + ) { + $this->expectedValueType = $expectedValueType; + $this->dataValueType = $dataValueType; + + $message = '$dataValueType "' . $dataValueType . '" does not match $expectedValueType "' + . $expectedValueType . '": $message'; + + parent::__construct( $message, 0, $previous ); + } + + /** + * @return string + */ + public function getExpectedValueType() { + return $this->expectedValueType; + } + + /** + * @return string + */ + public function getDataValueType() { + return $this->dataValueType; + } + +} diff --git a/data-values/common/src/ValueFormatters/StringFormatter.php b/data-values/common/src/ValueFormatters/StringFormatter.php new file mode 100644 index 0000000..acb6b50 --- /dev/null +++ b/data-values/common/src/ValueFormatters/StringFormatter.php @@ -0,0 +1,34 @@ +<?php + +namespace ValueFormatters; + +use DataValues\StringValue; +use InvalidArgumentException; + +/** + * Formatter for string values + * + * @since 0.1 + * + * @licence GNU GPL v2+ + * @author Katie Filbert < aude.w...@gmail.com > + */ +class StringFormatter extends ValueFormatterBase { + + /** + * @see ValueFormatter::format + * + * @param StringValue $dataValue + * + * @throws InvalidArgumentException + * @return string Text + */ + public function format( $dataValue ) { + if ( !( $dataValue instanceof StringValue ) ) { + throw new InvalidArgumentException( 'Data value type mismatch. Expected a StringValue.' ); + } + + return $dataValue->getValue(); + } + +} diff --git a/data-values/common/src/ValueParsers/BoolParser.php b/data-values/common/src/ValueParsers/BoolParser.php new file mode 100644 index 0000000..fb73aa2 --- /dev/null +++ b/data-values/common/src/ValueParsers/BoolParser.php @@ -0,0 +1,50 @@ +<?php + +namespace ValueParsers; + +use DataValues\BooleanValue; + +/** + * ValueParser that parses the string representation of a boolean. + * + * @since 0.1 + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ +class BoolParser extends StringValueParser { + + const FORMAT_NAME = 'bool'; + + private static $values = array( + 'yes' => true, + 'on' => true, + '1' => true, + 'true' => true, + 'no' => false, + 'off' => false, + '0' => false, + 'false' => false, + ); + + /** + * @see StringValueParser::stringParse + * + * @param string $value + * + * @return BooleanValue + * @throws ParseException + */ + protected function stringParse( $value ) { + $rawValue = $value; + + $value = strtolower( $value ); + + if ( array_key_exists( $value, self::$values ) ) { + return new BooleanValue( self::$values[$value] ); + } + + throw new ParseException( 'Not a boolean', $rawValue, self::FORMAT_NAME ); + } + +} diff --git a/data-values/common/src/ValueParsers/DispatchingValueParser.php b/data-values/common/src/ValueParsers/DispatchingValueParser.php new file mode 100644 index 0000000..cdd92de --- /dev/null +++ b/data-values/common/src/ValueParsers/DispatchingValueParser.php @@ -0,0 +1,71 @@ +<?php + +namespace ValueParsers; + +use InvalidArgumentException; + +/** + * A generic value parser that forwards parsing to a list of other value parsers and returns the + * result of the first parse attempt that succeeded. + * + * @since 0.3 + * + * @licence GNU GPL v2+ + * @author Thiemo Mättig + */ +class DispatchingValueParser implements ValueParser { + + /** + * @var ValueParser[] + */ + private $parsers; + + /** + * @see ParseException::getExpectedFormat + * + * @var string + */ + private $format; + + /** + * @param ValueParser[] $parsers + * @param string $format An identifier describing the expected format of the values to parse. + * + * @throws InvalidArgumentException + */ + public function __construct( array $parsers, $format ) { + if ( empty( $parsers ) ) { + throw new InvalidArgumentException( '$parsers must be a non-empty array' ); + } + + if ( !is_string( $format ) || $format === '' ) { + throw new InvalidArgumentException( '$format must be a non-empty string' ); + } + + $this->parsers = $parsers; + $this->format = $format; + } + + /** + * @param mixed $value + * + * @throws ParseException + * @return mixed + */ + public function parse( $value ) { + foreach ( $this->parsers as $parser ) { + try { + return $parser->parse( $value ); + } catch ( ParseException $ex ) { + continue; + } + } + + throw new ParseException( + 'The value is not recognitzed by the configured parsers', + $value, + $this->format + ); + } + +} diff --git a/data-values/common/src/ValueParsers/FloatParser.php b/data-values/common/src/ValueParsers/FloatParser.php new file mode 100644 index 0000000..9472fa6 --- /dev/null +++ b/data-values/common/src/ValueParsers/FloatParser.php @@ -0,0 +1,37 @@ +<?php + +namespace ValueParsers; + +use DataValues\NumberValue; + +/** + * ValueParser that parses the string representation of a float. + * + * @since 0.1 + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ +class FloatParser extends StringValueParser { + + const FORMAT_NAME = 'float'; + + /** + * @see StringValueParser::stringParse + * + * TODO: add options for different group and decimal separators. + * + * @param string $value + * + * @return NumberValue + * @throws ParseException + */ + protected function stringParse( $value ) { + if ( preg_match( '/^(-)?\d+((\.|,)\d+)?$/', $value ) ) { + return new NumberValue( (float)$value ); + } + + throw new ParseException( 'Not a float', $value, self::FORMAT_NAME ); + } + +} diff --git a/data-values/common/src/ValueParsers/IntParser.php b/data-values/common/src/ValueParsers/IntParser.php new file mode 100644 index 0000000..8ca2f0f --- /dev/null +++ b/data-values/common/src/ValueParsers/IntParser.php @@ -0,0 +1,37 @@ +<?php + +namespace ValueParsers; + +use DataValues\NumberValue; + +/** + * ValueParser that parses the string representation of an integer. + * + * @since 0.1 + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ +class IntParser extends StringValueParser { + + const FORMAT_NAME = 'int'; + + /** + * @see StringValueParser::stringParse + * + * @param string $value + * + * @return NumberValue + * @throws ParseException + */ + protected function stringParse( $value ) { + $positiveValue = strpos( $value, '-' ) === 0 ? substr( $value, 1 ) : $value; + + if ( ctype_digit( $positiveValue ) ) { + return new NumberValue( (int)$value ); + } + + throw new ParseException( 'Not an integer', $value, self::FORMAT_NAME ); + } + +} diff --git a/data-values/common/src/ValueParsers/Normalizers/NullStringNormalizer.php b/data-values/common/src/ValueParsers/Normalizers/NullStringNormalizer.php new file mode 100644 index 0000000..70ce302 --- /dev/null +++ b/data-values/common/src/ValueParsers/Normalizers/NullStringNormalizer.php @@ -0,0 +1,31 @@ +<?php + +namespace ValueParsers\Normalizers; + +use InvalidArgumentException; + +/** + * Null implementation of StringNormalizer. + * + * @since 0.3 + * + * @license GPL 2+ + * @author Daniel Kinzler + */ +class NullStringNormalizer implements StringNormalizer { + + /** + * @param string $value + * + * @throws InvalidArgumentException if $value is not a string + * @return string the normalized value + */ + public function normalize( $value ) { + if ( !is_string( $value ) ) { + throw new InvalidArgumentException( 'Parameter $value must be a string' ); + } + + return $value; + } + +} diff --git a/data-values/common/src/ValueParsers/Normalizers/StringNormalizer.php b/data-values/common/src/ValueParsers/Normalizers/StringNormalizer.php new file mode 100644 index 0000000..d0cfe90 --- /dev/null +++ b/data-values/common/src/ValueParsers/Normalizers/StringNormalizer.php @@ -0,0 +1,25 @@ +<?php + +namespace ValueParsers\Normalizers; + +use InvalidArgumentException; + +/** + * Interface for string normalization. + * + * @since 0.3 + * + * @license GPL 2+ + * @author Daniel Kinzler + */ +interface StringNormalizer { + + /** + * @param string $value + * + * @throws InvalidArgumentException if $value is not a string + * @return string the normalized value + */ + public function normalize( $value ); + +} diff --git a/data-values/common/src/ValueParsers/NullParser.php b/data-values/common/src/ValueParsers/NullParser.php new file mode 100644 index 0000000..de6ca58 --- /dev/null +++ b/data-values/common/src/ValueParsers/NullParser.php @@ -0,0 +1,28 @@ +<?php + +namespace ValueParsers; + +use DataValues\UnknownValue; + +/** + * Implementation of the ValueParser interface that does a null parse. + * + * @since 0.1 + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ +class NullParser implements ValueParser { + + /** + * @see ValueParser::parse + * + * @param mixed $value + * + * @return UnknownValue + */ + public function parse( $value ) { + return new UnknownValue( $value ); + } + +} diff --git a/data-values/common/src/ValueParsers/StringParser.php b/data-values/common/src/ValueParsers/StringParser.php new file mode 100644 index 0000000..820446d --- /dev/null +++ b/data-values/common/src/ValueParsers/StringParser.php @@ -0,0 +1,49 @@ +<?php + +namespace ValueParsers; + +use DataValues\StringValue; +use InvalidArgumentException; +use ValueParsers\Normalizers\NullStringNormalizer; +use ValueParsers\Normalizers\StringNormalizer; + +/** + * Implementation of the ValueParser interface for StringValues. + * + * @since 0.3 + * + * @licence GNU GPL v2+ + * @author Daniel Kinzler + */ +class StringParser implements ValueParser { + + /** + * @var StringNormalizer + */ + private $normalizer; + + /** + * @param StringNormalizer $normalizer + */ + public function __construct( StringNormalizer $normalizer = null ) { + $this->normalizer = $normalizer ?: new NullStringNormalizer(); + } + + /** + * @see ValueParser::parse + * + * @param string $value + * + * @throws InvalidArgumentException if $value is not a string + * @return StringValue + */ + public function parse( $value ) { + if ( !is_string( $value ) ) { + throw new InvalidArgumentException( 'Parameter $value must be a string' ); + } + + $value = $this->normalizer->normalize( $value ); + return new StringValue( $value ); + } + +} diff --git a/data-values/common/src/ValueParsers/StringValueParser.php b/data-values/common/src/ValueParsers/StringValueParser.php new file mode 100644 index 0000000..0e17ac2 --- /dev/null +++ b/data-values/common/src/ValueParsers/StringValueParser.php @@ -0,0 +1,120 @@ +<?php + +namespace ValueParsers; + +use InvalidArgumentException; +use RuntimeException; + +/** + * ValueParser that parses the string representation of something. + * + * @since 0.1 + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ +abstract class StringValueParser implements ValueParser { + + /** + * @since 0.1 + * + * @var ParserOptions + */ + protected $options; + + /** + * @since 0.1 + * + * @param ParserOptions|null $options + */ + public function __construct( ParserOptions $options = null ) { + $this->options = $options ?: new ParserOptions(); + + $this->defaultOption( ValueParser::OPT_LANG, 'en' ); + } + + /** + * @see ValueParser::parse + * + * @param mixed $value + * + * @return mixed + * @throws ParseException + */ + public function parse( $value ) { + if ( is_string( $value ) ) { + return $this->stringParse( $value ); + } + + throw new ParseException( 'Not a string' ); + } + + /** + * Parses the provided string and returns the result. + * + * @since 0.1 + * + * @param string $value + * + * @return mixed + */ + protected abstract function stringParse( $value ); + + /** + * @since 0.1 + * + * @param ParserOptions $options + */ + public function setOptions( ParserOptions $options ) { + $this->options = $options; + } + + /** + * @since 0.1 + * + * @return ParserOptions + */ + public function getOptions() { + return $this->options; + } + + /** + * Shortcut to $this->options->getOption. + * + * @since 0.1 + * + * @param string $option + * + * @throws InvalidArgumentException + * @return mixed + */ + protected final function getOption( $option ) { + return $this->options->getOption( $option ); + } + + /** + * Shortcut to $this->options->requireOption. + * + * @since 0.1 + * + * @param string $option + * + * @throws RuntimeException + */ + protected final function requireOption( $option ) { + $this->options->requireOption( $option ); + } + + /** + * Shortcut to $this->options->defaultOption. + * + * @since 0.1 + * + * @param string $option + * @param mixed $default + */ + protected final function defaultOption( $option, $default ) { + $this->options->defaultOption( $option, $default ); + } + +} diff --git a/data-values/common/tests/DataValues/MonolingualTextValueTest.php b/data-values/common/tests/DataValues/MonolingualTextValueTest.php new file mode 100644 index 0000000..5d271f4 --- /dev/null +++ b/data-values/common/tests/DataValues/MonolingualTextValueTest.php @@ -0,0 +1,73 @@ +<?php + +namespace DataValues\Tests; + +use DataValues\MonolingualTextValue; + +/** + * @covers DataValues\MonolingualTextValue + * + * @since 0.1 + * + * @group DataValue + * @group DataValueExtensions + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ +class MonolingualTextValueTest extends DataValueTest { + + /** + * @see DataValueTest::getClass + * + * @return string + */ + public function getClass() { + return 'DataValues\MonolingualTextValue'; + } + + 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, null ); + $argLists[] = array( array(), null ); + $argLists[] = array( false, null ); + $argLists[] = array( true, null ); + $argLists[] = array( null, null ); + $argLists[] = array( 'en', 42 ); + $argLists[] = array( 'en', false ); + $argLists[] = array( 'en', array() ); + $argLists[] = array( 'en', null ); + $argLists[] = array( '', 'foo' ); + + return $argLists; + } + + /** + * @dataProvider instanceProvider + * @param MonolingualTextValue $text + * @param array $arguments + */ + public function testGetText( MonolingualTextValue $text, array $arguments ) { + $this->assertEquals( $arguments[1], $text->getText() ); + } + + /** + * @dataProvider instanceProvider + * @param MonolingualTextValue $text + * @param array $arguments + */ + public function testGetLanguageCode( MonolingualTextValue $text, array $arguments ) { + $this->assertEquals( $arguments[0], $text->getLanguageCode() ); + } + +} diff --git a/data-values/common/tests/DataValues/MultilingualTextValueTest.php b/data-values/common/tests/DataValues/MultilingualTextValueTest.php new file mode 100644 index 0000000..b0cc406 --- /dev/null +++ b/data-values/common/tests/DataValues/MultilingualTextValueTest.php @@ -0,0 +1,91 @@ +<?php + +namespace DataValues\Tests; + +use DataValues\MonolingualTextValue; +use DataValues\MultilingualTextValue; + +/** + * @covers DataValues\MultilingualTextValue + * + * @since 0.1 + * + * @group DataValue + * @group DataValueExtensions + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ +class MultilingualTextValueTest extends DataValueTest { + + /** + * @see DataValueTest::getClass + * + * @return string + */ + public function getClass() { + return 'DataValues\MultilingualTextValue'; + } + + public function validConstructorArgumentsProvider() { + $argLists = 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 ' ) + ) ); + + return $argLists; + } + + public function invalidConstructorArgumentsProvider() { + $argLists = array(); + + $argLists[] = array( array( 42 ) ); + $argLists[] = array( array( false ) ); + $argLists[] = array( array( true ) ); + $argLists[] = array( array( null ) ); + $argLists[] = array( array( array() ) ); + $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; + } + + /** + * @dataProvider instanceProvider + * @param MultilingualTextValue $texts + * @param array $arguments + */ + public function testGetTexts( MultilingualTextValue $texts, array $arguments ) { + $actual = $texts->getTexts(); + + $this->assertInternalType( 'array', $actual ); + $this->assertContainsOnlyInstancesOf( '\DataValues\MonolingualTextValue', $actual ); + $this->assertEquals( $arguments[0], array_values( $actual ) ); + } + + /** + * @dataProvider instanceProvider + * @param MultilingualTextValue $texts + * @param array $arguments + */ + public function testGetValue( MultilingualTextValue $texts, array $arguments ) { + $this->assertInstanceOf( $this->getClass(), $texts->getValue() ); + } + +} diff --git a/data-values/common/tests/ValueFormatters/Exceptions/MismatchingDataValueTypeException.php b/data-values/common/tests/ValueFormatters/Exceptions/MismatchingDataValueTypeException.php new file mode 100644 index 0000000..8a21187 --- /dev/null +++ b/data-values/common/tests/ValueFormatters/Exceptions/MismatchingDataValueTypeException.php @@ -0,0 +1,59 @@ +<?php + +namespace ValueFormatters\Tests\Exceptions; + +use ValueFormatters\Exceptions\MismatchingDataValueTypeException; + +/** + * @covers ValueFormatters\Exceptions\MismatchingDataValueTypeException + * + * @group ValueFormatters + * @group DataValueExtensions + * + * @licence GNU GPL v2+ + * @author Katie Filbert < aude.w...@gmail.com > + */ +class MismatchingDataValueTypeExceptionTest extends \PHPUnit_Framework_TestCase { + + /** + * @dataProvider constructorProvider + * @param string $expectedType + * @param string $actualType + */ + public function testConstructorWithRequiredArguments( $expectedType, $actualType ) { + $exception = new MismatchingDataValueTypeException( $expectedType, $actualType ); + + $this->assertEquals( $actualType, $exception->getDataValueType() ); + $this->assertEquals( $expectedType, $exception->getExpectedValueType() ); + } + + /** + * @dataProvider constructorProvider + * @param string $expectedType + * @param string $actualType + */ + public function testConstructorWithAllArguments( $expectedType, $actualType ) { + $message = 'Onoez! an error!'; + $previous = new \Exception( 'Onoez!' ); + + $exception = new MismatchingDataValueTypeException( + $expectedType, + $actualType, + $message, + $previous + ); + + $this->assertEquals( $actualType, $exception->getDataValueType() ); + $this->assertEquals( $expectedType, $exception->getExpectedValueType() ); + $this->assertContains( $message, $exception->getMessage() ); + $this->assertEquals( $previous, $exception->getPrevious() ); + } + + public function constructorProvider() { + return array( + array( 'string', 'time' ), + array( 'globecoordinate', 'string' ) + ); + } + +} diff --git a/data-values/common/tests/ValueFormatters/StringFormatterTest.php b/data-values/common/tests/ValueFormatters/StringFormatterTest.php new file mode 100644 index 0000000..3aef150 --- /dev/null +++ b/data-values/common/tests/ValueFormatters/StringFormatterTest.php @@ -0,0 +1,59 @@ +<?php + +namespace ValueFormatters\Test; + +use DataValues\StringValue; +use ValueFormatters\FormatterOptions; +use ValueFormatters\StringFormatter; + +/** + * @covers ValueFormatters\StringFormatter + * + * @group ValueFormatters + * @group DataValueExtensions + * + * @licence GNU GPL v2+ + * @author Katie Filbert < aude.w...@gmail.com > + */ +class StringFormatterTest extends ValueFormatterTestBase { + + /** + * @deprecated since 0.2, just use getInstance. + */ + protected function getFormatterClass() { + throw new \LogicException( 'Should not be called, use getInstance' ); + } + + /** + * @see ValueFormatterTestBase::getInstance + * + * @param FormatterOptions|null $options + * + * @return StringFormatter + */ + protected function getInstance( FormatterOptions $options = null ) { + return new StringFormatter( $options ); + } + + /** + * @see ValueFormatterTestBase::validProvider + */ + public function validProvider() { + $strings = array( + 'ice cream', + 'cake', + '', + ' a ', + ' ', + ); + + $argLists = array(); + + foreach ( $strings as $string ) { + $argLists[] = array( new StringValue( $string ), $string ); + } + + return $argLists; + } + +} diff --git a/data-values/common/tests/ValueParsers/BoolParserTest.php b/data-values/common/tests/ValueParsers/BoolParserTest.php new file mode 100644 index 0000000..9de03a2 --- /dev/null +++ b/data-values/common/tests/ValueParsers/BoolParserTest.php @@ -0,0 +1,73 @@ +<?php + +namespace ValueParsers\Test; + +use DataValues\BooleanValue; +use ValueParsers\BoolParser; + +/** + * @covers ValueParsers\BoolParser + * + * @group ValueParsers + * @group DataValueExtensions + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ +class BoolParserTest extends StringValueParserTest { + + /** + * @see ValueParserTestBase::getInstance + * + * @return BoolParser + */ + protected function getInstance() { + return new BoolParser(); + } + + /** + * @see ValueParserTestBase::validInputProvider + */ + public function validInputProvider() { + $argLists = array(); + + $valid = array( + 'yes' => true, + 'on' => true, + '1' => true, + 'true' => true, + 'no' => false, + 'off' => false, + '0' => false, + 'false' => false, + + 'YeS' => true, + 'ON' => true, + 'No' => false, + 'OfF' => false, + ); + + foreach ( $valid as $value => $expected ) { + $expected = new BooleanValue( $expected ); + $argLists[] = array( (string)$value, $expected ); + } + + return $argLists; + } + + public function invalidInputProvider() { + $argLists = parent::invalidInputProvider(); + + $invalid = array( + 'foo', + '2', + ); + + foreach ( $invalid as $value ) { + $argLists[] = array( $value ); + } + + return $argLists; + } + +} diff --git a/data-values/common/tests/ValueParsers/DispatchingValueParserTest.php b/data-values/common/tests/ValueParsers/DispatchingValueParserTest.php new file mode 100644 index 0000000..dc94e1f --- /dev/null +++ b/data-values/common/tests/ValueParsers/DispatchingValueParserTest.php @@ -0,0 +1,90 @@ +<?php + +namespace ValueParsers\Test; + +use InvalidArgumentException; +use PHPUnit_Framework_MockObject_Matcher_Invocation; +use PHPUnit_Framework_TestCase; +use ValueParsers\DispatchingValueParser; +use ValueParsers\ParseException; +use ValueParsers\ValueParser; + +/** + * @covers ValueParsers\DispatchingValueParser + * + * @group ValueParsers + * @group WikibaseLib + * @group Wikibase + * + * @licence GNU GPL v2+ + * @author Thiemo Mättig + */ +class DispatchingValueParserTest extends PHPUnit_Framework_TestCase { + + /** + * @param PHPUnit_Framework_MockObject_Matcher_Invocation $invocation + * + * @return ValueParser + */ + private function getParser( PHPUnit_Framework_MockObject_Matcher_Invocation $invocation ) { + $mock = $this->getMockBuilder( 'ValueParsers\ValueParser' ) + ->disableOriginalConstructor() + ->getMock(); + + $mock->expects( $invocation ) + ->method( 'parse' ) + ->will( $this->returnCallback( function( $value ) { + if ( $value === 'invalid' ) { + throw new ParseException( 'failed' ); + } + return $value; + } ) ); + + return $mock; + } + + /** + * @dataProvider invalidConstructorArgumentsProvider + * @expectedException InvalidArgumentException + */ + public function testGivenInvalidConstructorArguments_constructorThrowsException( $parsers, $format ) { + new DispatchingValueParser( $parsers, $format ); + } + + public function invalidConstructorArgumentsProvider() { + $parsers = array( + $this->getParser( $this->never() ), + ); + + return array( + array( array(), 'format' ), + array( $parsers, null ), + array( $parsers, '' ), + ); + } + + public function testParse() { + $parser = new DispatchingValueParser( + array( + $this->getParser( $this->once() ), + $this->getParser( $this->never() ), + ), + 'format' + ); + + $this->assertEquals( 'valid', $parser->parse( 'valid' ) ); + } + + public function testParseThrowsException() { + $parser = new DispatchingValueParser( + array( + $this->getParser( $this->once() ), + ), + 'format' + ); + + $this->setExpectedException( 'ValueParsers\ParseException' ); + $parser->parse( 'invalid' ); + } + +} diff --git a/data-values/common/tests/ValueParsers/FloatParserTest.php b/data-values/common/tests/ValueParsers/FloatParserTest.php new file mode 100644 index 0000000..27d35fe --- /dev/null +++ b/data-values/common/tests/ValueParsers/FloatParserTest.php @@ -0,0 +1,94 @@ +<?php + +namespace ValueParsers\Test; + +use DataValues\NumberValue; +use ValueParsers\FloatParser; + +/** + * @covers ValueParsers\FloatParser + * + * @group ValueParsers + * @group DataValueExtensions + * @group FloatParserTest + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ +class FloatParserTest extends StringValueParserTest { + + /** + * @see ValueParserTestBase::getInstance + * + * @return FloatParser + */ + protected function getInstance() { + return new FloatParser(); + } + + /** + * @see ValueParserTestBase::validInputProvider + */ + public function validInputProvider() { + $argLists = array(); + + $valid = array( + '0' => 0, + '1' => 1, + '42' => 42, + '01' => 01, + '9001' => 9001, + '-1' => -1, + '-42' => -42, + + '0.0' => 0, + '1.0' => 1, + '4.2' => 4.2, + '0.1' => 0.1, + '90.01' => 90.01, + '-1.0' => -1, + '-4.2' => -4.2, + ); + + foreach ( $valid as $value => $expected ) { + // Because PHP turns them into ints/floats using black magic + $value = (string)$value; + + // Because 1 is an int but will come out as a float + $expected = (float)$expected; + + $expected = new NumberValue( $expected ); + $argLists[] = array( $value, $expected ); + } + + return $argLists; + } + + public function invalidInputProvider() { + $argLists = parent::invalidInputProvider(); + + $invalid = array( + 'foo', + '', + '--1', + '1-', + '1 1', + '1,', + ',1', + ',1,', + 'one', + '0x20', + '+1', + '1+1', + '1-1', + '1.2.3', + ); + + foreach ( $invalid as $value ) { + $argLists[] = array( $value ); + } + + return $argLists; + } + +} diff --git a/data-values/common/tests/ValueParsers/IntParserTest.php b/data-values/common/tests/ValueParsers/IntParserTest.php new file mode 100644 index 0000000..e039373 --- /dev/null +++ b/data-values/common/tests/ValueParsers/IntParserTest.php @@ -0,0 +1,83 @@ +<?php + +namespace ValueParsers\Test; + +use DataValues\NumberValue; +use ValueParsers\IntParser; + +/** + * @covers ValueParsers\IntParser + * + * @group ValueParsers + * @group DataValueExtensions + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ +class IntParserTest extends StringValueParserTest { + + /** + * @see ValueParserTestBase::getInstance + * + * @return IntParser + */ + protected function getInstance() { + return new IntParser(); + } + + /** + * @see ValueParserTestBase::validInputProvider + */ + public function validInputProvider() { + $argLists = array(); + + $valid = array( + '0' => 0, + '1' => 1, + '42' => 42, + '01' => 01, + '9001' => 9001, + '-1' => -1, + '-42' => -42, + ); + + foreach ( $valid as $value => $expected ) { + // Because PHP turns them into ints using black magic + $value = (string)$value; + + $expected = new NumberValue( $expected ); + $argLists[] = array( $value, $expected ); + } + + return $argLists; + } + + public function invalidInputProvider() { + $argLists = parent::invalidInputProvider(); + + $invalid = array( + 'foo', + '4.2', + '', + '--1', + '1-', + '1 1', + '1,', + ',1', + ',1,', + 'one', + '0x20', + '+1', + '1+1', + '1-1', + '1.2.3', + ); + + foreach ( $invalid as $value ) { + $argLists[] = array( $value ); + } + + return $argLists; + } + +} diff --git a/data-values/common/tests/ValueParsers/Normalizers/NullStringNormalizerTest.php b/data-values/common/tests/ValueParsers/Normalizers/NullStringNormalizerTest.php new file mode 100644 index 0000000..ba52837 --- /dev/null +++ b/data-values/common/tests/ValueParsers/Normalizers/NullStringNormalizerTest.php @@ -0,0 +1,55 @@ +<?php + +namespace ValueParsers\Normalizers\Test; + +use DataValues\DataValue; +use DataValues\StringValue; +use PHPUnit_Framework_TestCase; +use ValueParsers\Normalizers\NullStringNormalizer; + +/** + * @covers ValueParsers\Normalizers\NullStringNormalizer + * + * @group ValueParsers + * @group DataValueExtensions + * + * @licence GNU GPL v2+ + * @author Thiemo Mättig + */ +class NullStringNormalizerTest extends PHPUnit_Framework_TestCase { + + /** + * @dataProvider stringProvider + */ + public function testNormalize( $value ) { + $normalizer = new NullStringNormalizer(); + $this->assertSame( $value, $normalizer->normalize( $value ) ); + } + + public function stringProvider() { + return array( + array( '' ), + array( 'a' ), + array( ' a ' ), + ); + } + + /** + * @dataProvider invalidValueProvider + */ + public function testNormalizeException( $value ) { + $normalizer = new NullStringNormalizer(); + $this->setExpectedException( 'InvalidArgumentException' ); + $normalizer->normalize( $value ); + } + + public function invalidValueProvider() { + return array( + array( null ), + array( true ), + array( 1 ), + array( new StringValue( '' ) ), + ); + } + +} diff --git a/data-values/common/tests/ValueParsers/NullParserTest.php b/data-values/common/tests/ValueParsers/NullParserTest.php new file mode 100644 index 0000000..f4ad45f --- /dev/null +++ b/data-values/common/tests/ValueParsers/NullParserTest.php @@ -0,0 +1,75 @@ +<?php + +namespace ValueParsers\Test; + +use DataValues\UnknownValue; +use ValueParsers\NullParser; +use ValueParsers\ValueParser; + +/** + * @covers ValueParsers\NullParser + * + * @group ValueParsers + * @group DataValueExtensions + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ +class NullParserTest extends ValueParserTestBase { + + /** + * @see ValueParserTestBase::getInstance + * + * @return NullParser + */ + protected function getInstance() { + return new NullParser(); + } + + /** + * @see ValueParserTestBase::validInputProvider + */ + public function validInputProvider() { + $argLists = array(); + + $values = array( + '42', + 42, + false, + array(), + 'ohi there!', + null, + 4.2, + ); + + foreach ( $values as $value ) { + $argLists[] = array( + $value, + new UnknownValue( $value ) + ); + } + + return $argLists; + } + + /** + * @see ValueParserTestBase::invalidInputProvider + */ + public function invalidInputProvider() { + return array( + array( null ) + ); + } + + /** + * @see ValueParserTestBase::testParseWithInvalidInputs + * + * @dataProvider invalidInputProvider + * @param mixed $value + * @param ValueParser|null $parser + */ + public function testParseWithInvalidInputs( $value, ValueParser $parser = null ) { + $this->markTestSkipped( 'NullParser has no invalid inputs' ); + } + +} diff --git a/data-values/common/tests/ValueParsers/StringParserTest.php b/data-values/common/tests/ValueParsers/StringParserTest.php new file mode 100644 index 0000000..0875166 --- /dev/null +++ b/data-values/common/tests/ValueParsers/StringParserTest.php @@ -0,0 +1,63 @@ +<?php + +namespace ValueParsers\Test; + +use DataValues\DataValue; +use DataValues\StringValue; +use ValueParsers\Normalizers\StringNormalizer; +use ValueParsers\StringParser; + +/** + * @covers ValueParsers\StringParser + * + * @group ValueParsers + * @group DataValueExtensions + * + * @licence GNU GPL v2+ + * @author Daniel Kinzler + */ +class StringParserTest extends \PHPUnit_Framework_TestCase { + + public function provideParse() { + $normalizer = $this->getMock( 'ValueParsers\Normalizers\StringNormalizer' ); + $normalizer->expects( $this->once() ) + ->method( 'normalize' ) + ->will( $this->returnCallback( function( $value ) { + return strtolower( trim( $value ) ); + } ) ); + + return array( + 'simple' => array( 'hello world', null, new StringValue( 'hello world' ) ), + 'normalize' => array( ' Hello World ', $normalizer, new StringValue( 'hello world' ) ), + ); + } + + /** + * @dataProvider provideParse + */ + public function testParse( $input, StringNormalizer $normalizer = null, DataValue $expected ) { + $parser = new StringParser( $normalizer ); + $value = $parser->parse( $input ); + + $this->assertInstanceOf( 'DataValues\StringValue', $value ); + $this->assertEquals( $expected->toArray(), $value->toArray() ); + } + + public function nonStringProvider() { + return array( + 'null' => array( null ), + 'array' => array( array() ), + 'int' => array( 7 ), + ); + } + + /** + * @dataProvider nonStringProvider + */ + public function testGivenNonString_parseThrowsException( $input ) { + $parser = new StringParser(); + $this->setExpectedException( 'InvalidArgumentException' ); + $parser->parse( $input ); + } + +} diff --git a/data-values/common/tests/ValueParsers/StringValueParserTest.php b/data-values/common/tests/ValueParsers/StringValueParserTest.php new file mode 100644 index 0000000..962de1d --- /dev/null +++ b/data-values/common/tests/ValueParsers/StringValueParserTest.php @@ -0,0 +1,55 @@ +<?php + +namespace ValueParsers\Test; + +use ValueParsers\ParserOptions; +use ValueParsers\StringValueParser; + +/** + * Unit test StringValueParser class. + * + * @since 0.1 + * + * @group ValueParsers + * @group DataValueExtensions + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ +abstract class StringValueParserTest extends ValueParserTestBase { + + /** + * @see ValueParserTestBase::invalidInputProvider + * + * @return array[] + */ + public function invalidInputProvider() { + return array( + array( true ), + array( false ), + array( null ), + array( 4.2 ), + array( array() ), + array( 42 ), + ); + } + + public function testSetAndGetOptions() { + /** + * @var StringValueParser $parser + */ + $parser = $this->getInstance(); + + $parser->setOptions( new ParserOptions() ); + + $this->assertEquals( new ParserOptions(), $parser->getOptions() ); + + $options = new ParserOptions(); + $options->setOption( '~=[,,_,,]:3', '~=[,,_,,]:3' ); + + $parser->setOptions( $options ); + + $this->assertEquals( $options, $parser->getOptions() ); + } + +} diff --git a/data-values/common/tests/ValueParsers/ValueParserTestBase.php b/data-values/common/tests/ValueParsers/ValueParserTestBase.php new file mode 100644 index 0000000..f937f81 --- /dev/null +++ b/data-values/common/tests/ValueParsers/ValueParserTestBase.php @@ -0,0 +1,109 @@ +<?php + +namespace ValueParsers\Test; + +use Comparable; +use DataValues\DataValue; +use PHPUnit_Framework_TestCase; +use ValueParsers\ParserOptions; +use ValueParsers\ValueParser; + +/** + * Base for unit tests for ValueParser implementing classes. + * + * @since 0.1 + * + * @group ValueParsers + * @group DataValueExtensions + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ +abstract class ValueParserTestBase extends PHPUnit_Framework_TestCase { + + /** + * @since 0.1 + * + * @return array[] + */ + public abstract function validInputProvider(); + + /** + * @since 0.1 + * + * @return array[] + */ + public abstract function invalidInputProvider(); + + /** + * @since 0.1 + * + * @return ValueParser + */ + protected abstract function getInstance(); + + /** + * @since 0.1 + * + * @dataProvider validInputProvider + * @param mixed $value + * @param mixed $expected + * @param ValueParser|null $parser + */ + public function testParseWithValidInputs( $value, $expected, ValueParser $parser = null ) { + if ( $parser === null ) { + $parser = $this->getInstance(); + } + + $this->assertSmartEquals( $expected, $parser->parse( $value ) ); + } + + /** + * @param DataValue|mixed $expected + * @param DataValue|mixed $actual + */ + private function assertSmartEquals( $expected, $actual ) { + if ( $this->requireDataValue() || $expected instanceof Comparable ) { + if ( $expected instanceof DataValue && $actual instanceof DataValue ) { + $msg = "testing equals():\n" + . preg_replace( '/\s+/', ' ', print_r( $actual->toArray(), true ) ) . " should equal\n" + . preg_replace( '/\s+/', ' ', print_r( $expected->toArray(), true ) ); + } else { + $msg = 'testing equals()'; + } + + $this->assertTrue( $expected->equals( $actual ), $msg ); + } + else { + $this->assertEquals( $expected, $actual ); + } + } + + /** + * @since 0.1 + * + * @dataProvider invalidInputProvider + * @param mixed $value + * @param ValueParser|null $parser + */ + public function testParseWithInvalidInputs( $value, ValueParser $parser = null ) { + if ( $parser === null ) { + $parser = $this->getInstance(); + } + + $this->setExpectedException( 'ValueParsers\ParseException' ); + $parser->parse( $value ); + } + + /** + * Returns if the result of the parsing process should be checked to be a DataValue. + * + * @since 0.1 + * + * @return bool + */ + protected function requireDataValue() { + return true; + } + +} diff --git a/data-values/common/tests/bootstrap.php b/data-values/common/tests/bootstrap.php new file mode 100644 index 0000000..ac82d46 --- /dev/null +++ b/data-values/common/tests/bootstrap.php @@ -0,0 +1,14 @@ +<?php + +if ( PHP_SAPI !== 'cli' ) { + die( 'Not an entry point' ); +} + +error_reporting( E_ALL | E_STRICT ); +ini_set( 'display_errors', 1 ); + +if ( !is_readable( __DIR__ . '/../vendor/autoload.php' ) ) { + die( 'You need to install this package with Composer before you can run the tests' ); +} + +require_once __DIR__ . '/../vendor/autoload.php'; -- To view, visit https://gerrit.wikimedia.org/r/368373 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I91bac9bc3dc215bf3b8c138e5ae7ecd6ba63306f Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/vendor Gerrit-Branch: master Gerrit-Owner: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Legoktm <lego...@member.fsf.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits