Separate MediaWiki unit and integration tests
[lhc/web/wiklou.git] / tests / phpunit / unit / includes / libs / DeferredStringifierTest.php
1 <?php
2
3 /**
4 * @covers DeferredStringifier
5 */
6 class DeferredStringifierTest extends PHPUnit\Framework\TestCase {
7
8 use MediaWikiCoversValidator;
9
10 /**
11 * @dataProvider provideToString
12 */
13 public function testToString( $params, $expected ) {
14 $class = new ReflectionClass( DeferredStringifier::class );
15 $ds = $class->newInstanceArgs( $params );
16 $this->assertEquals( $expected, (string)$ds );
17 }
18
19 public static function provideToString() {
20 return [
21 // No args
22 [
23 [
24 function () {
25 return 'foo';
26 }
27 ],
28 'foo'
29 ],
30 // Has args
31 [
32 [
33 function ( $i ) {
34 return $i;
35 },
36 'bar'
37 ],
38 'bar'
39 ],
40 ];
41 }
42
43 /**
44 * Verify that the callback is not called if
45 * it is never converted to a string
46 */
47 public function testCallbackNotCalled() {
48 $ds = new DeferredStringifier( function () {
49 throw new Exception( 'This should not be reached!' );
50 } );
51 // No exception was thrown
52 $this->assertTrue( true );
53 }
54 }