mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-15 03:34:10 +00:00
Merge "Throw InvalidArgumentException when validating/formatting null"
This commit is contained in:
commit
22d63b1973
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue