wiki.techinc.nl/tests/phpunit/includes/libs/DeferredStringifierTest.php
Umherirrender 45da581551 Use ::class to resolve class names in tests
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: Ie541a7baae10ab6f5c13f95ac2ff6598b8f8950c
2018-01-26 22:49:13 +01:00

54 lines
980 B
PHP

<?php
/**
* @covers DeferredStringifier
*/
class DeferredStringifierTest extends PHPUnit_Framework_TestCase {
use MediaWikiCoversValidator;
/**
* @dataProvider provideToString
*/
public function testToString( $params, $expected ) {
$class = new ReflectionClass( DeferredStringifier::class );
$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 );
}
}