2019-09-11 17:22:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Wikimedia\Tests\Message;
|
|
|
|
|
|
2019-09-11 17:33:56 +00:00
|
|
|
use InvalidArgumentException;
|
2019-09-11 17:22:58 +00:00
|
|
|
use Wikimedia\Message\MessageValue;
|
|
|
|
|
use Wikimedia\Message\ParamType;
|
2020-01-10 00:00:51 +00:00
|
|
|
use Wikimedia\Message\ScalarParam;
|
2019-09-11 17:22:58 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers \Wikimedia\Message\ScalarParam
|
|
|
|
|
*/
|
|
|
|
|
class ScalarParamTest extends \PHPUnit\Framework\TestCase {
|
|
|
|
|
|
|
|
|
|
public static function provideConstruct() {
|
|
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
ParamType::NUM, 1,
|
|
|
|
|
'<num>1</num>',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
ParamType::PLAINTEXT, 'foo & bar',
|
|
|
|
|
'<plaintext>foo & bar</plaintext>',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
ParamType::TEXT, new MessageValue( 'key' ),
|
|
|
|
|
'<text><message key="key"></message></text>',
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @dataProvider provideConstruct */
|
|
|
|
|
public function testConstruct( $type, $value, $expected ) {
|
|
|
|
|
$mp = new ScalarParam( $type, $value );
|
|
|
|
|
$this->assertSame( $type, $mp->getType() );
|
|
|
|
|
$this->assertSame( $value, $mp->getValue() );
|
|
|
|
|
$this->assertSame( $expected, $mp->dump() );
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-11 17:33:56 +00:00
|
|
|
public function testConstruct_badType() {
|
|
|
|
|
$this->expectException( InvalidArgumentException::class );
|
|
|
|
|
$this->expectExceptionMessage(
|
|
|
|
|
'ParamType::LIST cannot be used with ScalarParam; use ListParam instead'
|
|
|
|
|
);
|
|
|
|
|
new ScalarParam( ParamType::LIST, [] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testConstruct_badValueNULL() {
|
|
|
|
|
$this->expectException( InvalidArgumentException::class );
|
|
|
|
|
$this->expectExceptionMessage(
|
|
|
|
|
'Scalar parameter must be a string, number, or MessageValue; got NULL'
|
|
|
|
|
);
|
|
|
|
|
new ScalarParam( ParamType::TEXT, null );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testConstruct_badValueClass() {
|
|
|
|
|
$this->expectException( InvalidArgumentException::class );
|
|
|
|
|
$this->expectExceptionMessage(
|
|
|
|
|
'Scalar parameter must be a string, number, or MessageValue; got stdClass'
|
|
|
|
|
);
|
|
|
|
|
new ScalarParam( ParamType::TEXT, new \stdClass );
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-11 17:22:58 +00:00
|
|
|
}
|