2015-01-11 01:52:37 +00:00
|
|
|
<?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
|
2015-01-29 20:10:08 +00:00
|
|
|
array(
|
|
|
|
|
array(
|
|
|
|
|
function() {
|
|
|
|
|
return 'foo';
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
'foo'
|
|
|
|
|
),
|
2015-01-11 01:52:37 +00:00
|
|
|
// Has args
|
2015-01-29 20:10:08 +00:00
|
|
|
array(
|
|
|
|
|
array(
|
|
|
|
|
function( $i ) {
|
|
|
|
|
return $i;
|
|
|
|
|
},
|
|
|
|
|
'bar'
|
|
|
|
|
),
|
|
|
|
|
'bar'
|
|
|
|
|
),
|
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() {
|
|
|
|
|
$ds = new DeferredStringifier( function() {
|
|
|
|
|
throw new Exception( 'This should not be reached!' );
|
|
|
|
|
} );
|
|
|
|
|
// No exception was thrown
|
|
|
|
|
$this->assertTrue( true );
|
|
|
|
|
}
|
|
|
|
|
}
|