From 6a55db1a97180fdc6a75b66e94bfe6fd2e7fa180 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Sat, 10 Jan 2015 17:52:37 -0800 Subject: [PATCH] Move DeferredStringifier into libs, add tests Change-Id: I384d1a3854e957315584d30ec58c48c02fee6a2c --- autoload.php | 2 +- includes/{ => libs}/DeferredStringifier.php | 0 .../includes/libs/DeferredStringifierTest.php | 39 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) rename includes/{ => libs}/DeferredStringifier.php (100%) create mode 100644 tests/phpunit/includes/libs/DeferredStringifierTest.php diff --git a/autoload.php b/autoload.php index 674d4b0f43..72345feaba 100644 --- a/autoload.php +++ b/autoload.php @@ -292,7 +292,7 @@ $wgAutoloadLocalClasses = array( 'DateFormatter' => __DIR__ . '/includes/parser/DateFormatter.php', 'DeadendPagesPage' => __DIR__ . '/includes/specials/SpecialDeadendpages.php', 'DeferrableUpdate' => __DIR__ . '/includes/deferred/DeferredUpdates.php', - 'DeferredStringifier' => __DIR__ . '/includes/DeferredStringifier.php', + 'DeferredStringifier' => __DIR__ . '/includes/libs/DeferredStringifier.php', 'DeferredUpdates' => __DIR__ . '/includes/deferred/DeferredUpdates.php', 'DeleteAction' => __DIR__ . '/includes/actions/DeleteAction.php', 'DeleteArchivedFiles' => __DIR__ . '/maintenance/deleteArchivedFiles.php', diff --git a/includes/DeferredStringifier.php b/includes/libs/DeferredStringifier.php similarity index 100% rename from includes/DeferredStringifier.php rename to includes/libs/DeferredStringifier.php diff --git a/tests/phpunit/includes/libs/DeferredStringifierTest.php b/tests/phpunit/includes/libs/DeferredStringifierTest.php new file mode 100644 index 0000000000..9aaf113456 --- /dev/null +++ b/tests/phpunit/includes/libs/DeferredStringifierTest.php @@ -0,0 +1,39 @@ +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 ); + } +} -- 2.20.1