2015-01-11 01:52:37 +00:00
|
|
|
<?php
|
|
|
|
|
|
2017-12-29 23:44:13 +00:00
|
|
|
/**
|
|
|
|
|
* @covers DeferredStringifier
|
|
|
|
|
*/
|
2015-01-11 01:52:37 +00:00
|
|
|
class DeferredStringifierTest extends PHPUnit_Framework_TestCase {
|
|
|
|
|
|
2017-12-29 23:22:37 +00:00
|
|
|
use MediaWikiCoversValidator;
|
|
|
|
|
|
2015-01-11 01:52:37 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideToString
|
|
|
|
|
*/
|
|
|
|
|
public function testToString( $params, $expected ) {
|
|
|
|
|
$class = new ReflectionClass( 'DeferredStringifier' );
|
|
|
|
|
$ds = $class->newInstanceArgs( $params );
|
|
|
|
|
$this->assertEquals( $expected, (string)$ds );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideToString() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2015-01-11 01:52:37 +00:00
|
|
|
// No args
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[
|
2017-06-26 16:35:31 +00:00
|
|
|
function () {
|
2015-01-29 20:10:08 +00:00
|
|
|
return 'foo';
|
|
|
|
|
}
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2015-01-29 20:10:08 +00:00
|
|
|
'foo'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2015-01-11 01:52:37 +00:00
|
|
|
// Has args
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[
|
2017-06-26 16:35:31 +00:00
|
|
|
function ( $i ) {
|
2015-01-29 20:10:08 +00:00
|
|
|
return $i;
|
|
|
|
|
},
|
|
|
|
|
'bar'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2015-01-29 20:10:08 +00:00
|
|
|
'bar'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2015-01-11 01:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Verify that the callback is not called if
|
|
|
|
|
* it is never converted to a string
|
|
|
|
|
*/
|
|
|
|
|
public function testCallbackNotCalled() {
|
2017-06-26 16:35:31 +00:00
|
|
|
$ds = new DeferredStringifier( function () {
|
2015-01-11 01:52:37 +00:00
|
|
|
throw new Exception( 'This should not be reached!' );
|
|
|
|
|
} );
|
|
|
|
|
// No exception was thrown
|
|
|
|
|
$this->assertTrue( true );
|
|
|
|
|
}
|
|
|
|
|
}
|