wiki.techinc.nl/tests/phpunit/includes/libs/DeferredStringifierTest.php
Kunal Mehta 75160bdd3b Use MediaWikiCoversValidator for tests that don't use MediaWikiTestCase
Change-Id: I8c4de7e9c72c9969088666007b54c6fd23f6cc13
2018-01-01 08:28:02 +00:00

52 lines
968 B
PHP

<?php
class DeferredStringifierTest extends PHPUnit_Framework_TestCase {
use MediaWikiCoversValidator;
/**
* @covers DeferredStringifier
* @dataProvider provideToString
*/
public function testToString( $params, $expected ) {
$class = new ReflectionClass( 'DeferredStringifier' );
$ds = $class->newInstanceArgs( $params );
$this->assertEquals( $expected, (string)$ds );
}
public static function provideToString() {
return [
// No args
[
[
function () {
return 'foo';
}
],
'foo'
],
// Has args
[
[
function ( $i ) {
return $i;
},
'bar'
],
'bar'
],
];
}
/**
* Verify that the callback is not called if
* it is never converted to a string
*/
public function testCallbackNotCalled() {
$ds = new DeferredStringifier( function () {
throw new Exception( 'This should not be reached!' );
} );
// No exception was thrown
$this->assertTrue( true );
}
}