3 namespace Wikimedia\ParamValidator
;
6 * @covers Wikimedia\ParamValidator\TypeDef
8 class TypeDefTest
extends \PHPUnit\Framework\TestCase
{
10 public function testMisc() {
11 $typeDef = $this->getMockBuilder( TypeDef
::class )
12 ->setConstructorArgs( [ new SimpleCallbacks( [] ) ] )
13 ->getMockForAbstractClass();
15 $this->assertSame( [ 'foobar' ], $typeDef->normalizeSettings( [ 'foobar' ] ) );
16 $this->assertNull( $typeDef->getEnumValues( 'foobar', [], [] ) );
17 $this->assertSame( '123', $typeDef->stringifyValue( 'foobar', 123, [], [] ) );
20 public function testGetValue() {
21 $options = [ (object)[] ];
23 $callbacks = $this->getMockBuilder( Callbacks
::class )->getMockForAbstractClass();
24 $callbacks->expects( $this->once() )->method( 'getValue' )
26 $this->identicalTo( 'foobar' ),
27 $this->identicalTo( null ),
28 $this->identicalTo( $options )
30 ->willReturn( 'zyx' );
32 $typeDef = $this->getMockBuilder( TypeDef
::class )
33 ->setConstructorArgs( [ $callbacks ] )
34 ->getMockForAbstractClass();
38 $typeDef->getValue( 'foobar', [ ParamValidator
::PARAM_DEFAULT
=> 'foo' ], $options )
42 public function testDescribeSettings() {
43 $typeDef = $this->getMockBuilder( TypeDef
::class )
44 ->setConstructorArgs( [ new SimpleCallbacks( [] ) ] )
45 ->getMockForAbstractClass();
49 $typeDef->describeSettings(
51 [ ParamValidator
::PARAM_TYPE
=> 'xxx' ],
60 $typeDef->describeSettings(
62 [ ParamValidator
::PARAM_DEFAULT
=> 123 ],
69 'default' => [ 'value' => '123' ],
71 $typeDef->describeSettings(
73 [ ParamValidator
::PARAM_DEFAULT
=> 123 ],