wiki.techinc.nl/tests/phpunit/includes/libs/DeferredStringifierTest.php
Kunal Mehta 6a55db1a97 Move DeferredStringifier into libs, add tests
Change-Id: I384d1a3854e957315584d30ec58c48c02fee6a2c
2015-01-13 11:04:44 -08:00

39 lines
905 B
PHP

<?php
class DeferredStringifierTest extends PHPUnit_Framework_TestCase {
/**
* @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 array(
// No args
array( array( function() {
return 'foo';
} ), 'foo' ),
// Has args
array( array( 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 );
}
}