MediaWiki REL1_31
DeferredStringifierTest.php
Go to the documentation of this file.
1<?php
2
6class DeferredStringifierTest extends PHPUnit\Framework\TestCase {
7
8 use MediaWikiCoversValidator;
9
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
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}
testCallbackNotCalled()
Verify that the callback is not called if it is never converted to a string.
testToString( $params, $expected)
provideToString
$params