Merge "Throw InvalidArgumentException when validating/formatting null"

This commit is contained in:
jenkins-bot 2018-05-18 19:00:32 +00:00 committed by Gerrit Code Review
commit 22d63b1973
4 changed files with 14 additions and 13 deletions

View file

@ -1,7 +1,6 @@
<?php
use DataValues\StringValue;
use ValueFormatters\Exceptions\MismatchingDataValueTypeException;
use ValueFormatters\ValueFormatter;
use Wikibase\Lib\SnakFormatter;
@ -33,12 +32,12 @@ class MathFormatter implements ValueFormatter {
/**
* @param StringValue $value
*
* @throws MismatchingDataValueTypeException
* @throws InvalidArgumentException if not called with a StringValue
* @return string
*/
public function format( $value ) {
if ( !( $value instanceof StringValue ) ) {
throw new MismatchingDataValueTypeException( 'StringValue', get_class( $value ) );
throw new InvalidArgumentException( '$value must be a StringValue' );
}
$tex = $value->getValue();

View file

@ -1,26 +1,28 @@
<?php
use DataValues\StringValue;
use ValueFormatters\Exceptions\MismatchingDataValueTypeException;
use ValueValidators\Error;
use ValueValidators\Result;
use ValueValidators\ValueValidator;
// @author Duc Linh Tran, Julian Hilbig, Moritz Schubotz
/**
* @author Duc Linh Tran
* @author Julian Hilbig
* @author Moritz Schubotz
*/
class MathValidator implements ValueValidator {
/**
* Validates a value with MathInputCheckRestbase
*
* @param mixed $value The value to validate
* @param StringValue $value The value to validate
*
* @return \ValueValidators\Result
* @throws ValueFormatters\Exceptions\MismatchingDataValueTypeException
* @throws InvalidArgumentException if not called with a StringValue
*/
public function validate( $value ) {
if ( !( $value instanceof StringValue ) ) {
throw new MismatchingDataValueTypeException( 'StringValue', get_class( $value ) );
throw new InvalidArgumentException( '$value must be a StringValue' );
}
// get input String from value

View file

@ -43,7 +43,7 @@ class MathFormatterTest extends MediaWikiTestCase {
}
/**
* @expectedException ValueFormatters\Exceptions\MismatchingDataValueTypeException
* @expectedException InvalidArgumentException
*/
public function testNotStringValue() {
$formatter = new MathFormatter( SnakFormatter::FORMAT_PLAIN );
@ -51,7 +51,7 @@ class MathFormatterTest extends MediaWikiTestCase {
}
/**
* @expectedException ValueFormatters\Exceptions\MismatchingDataValueTypeException
* @expectedException InvalidArgumentException
*/
public function testNullValue() {
$formatter = new MathFormatter( SnakFormatter::FORMAT_PLAIN );

View file

@ -38,7 +38,7 @@ class MathValidatorTest extends MediaWikiTestCase {
}
/**
* @expectedException ValueFormatters\Exceptions\MismatchingDataValueTypeException
* @expectedException InvalidArgumentException
*/
public function testNotStringValue() {
$validator = new MathValidator();
@ -46,7 +46,7 @@ class MathValidatorTest extends MediaWikiTestCase {
}
/**
* @expectedException ValueFormatters\Exceptions\MismatchingDataValueTypeException
* @expectedException InvalidArgumentException
*/
public function testNullValue() {
$validator = new MathValidator();