wiki.techinc.nl/tests/phpunit/unit/includes/libs/DeferredStringifierTest.php
Max Semenik 5bf93709f4 Move a lot of libs tests to the unit test directory
Change-Id: Ie7eb1016cd735f07b00524815598581e0d485f2a
2019-11-11 17:53:56 -08: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 );
}
}