Daniel Kinzler has uploaded a new change for review.
https://gerrit.wikimedia.org/r/74358
Change subject: Reset output buffers after each test.
......................................................................
Reset output buffers after each test.
Previously, some tests left an output buffer in place,
preventing output from phpunit to continue.
Change-Id: I2e040157b4aadf6bb18581ef2495862d680feec5
---
M lib/tests/phpunit/specials/SpecialPageTestBase.php
M repo/tests/phpunit/includes/LinkedData/EntityDataRequestHandlerTest.php
2 files changed, 67 insertions(+), 14 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/58/74358/1
diff --git a/lib/tests/phpunit/specials/SpecialPageTestBase.php
b/lib/tests/phpunit/specials/SpecialPageTestBase.php
index 7276d19..5ec8067 100644
--- a/lib/tests/phpunit/specials/SpecialPageTestBase.php
+++ b/lib/tests/phpunit/specials/SpecialPageTestBase.php
@@ -32,6 +32,28 @@
*/
abstract class SpecialPageTestBase extends \MediaWikiTestCase {
+ protected $obLevel;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->obLevel = ob_get_level();
+ }
+
+ public function tearDown() {
+ $obLevel = ob_get_level();
+
+ while ( ob_get_level() > $this->obLevel ) {
+ ob_end_clean();
+ }
+
+ if ( $obLevel !== $this->obLevel ) {
+ $this->fail( "Test changed output buffer level: was
{$this->obLevel} before test, but $obLevel after test.");
+ }
+
+ parent::tearDown();
+ }
+
//public function testConstructor() {
//$this->assertInstanceOf( 'SpecialPage', new
\SpecialItemDisambiguation() );
//}
@@ -69,19 +91,32 @@
$out->setTitle( $page->getTitle() );
ob_start();
- $page->execute( $sub );
- if ( $out->getRedirect() !== '' ) {
- $out->output();
- $text = ob_get_contents();
- } elseif ( $out->isDisabled() ) {
- $text = ob_get_contents();
- } else {
- $text = $out->getHTML();
+ $exception = null;
+ try {
+ $page->execute( $sub );
+
+ if ( $out->getRedirect() !== '' ) {
+ $out->output();
+ $text = ob_get_contents();
+ } elseif ( $out->isDisabled() ) {
+ $text = ob_get_contents();
+ } else {
+ $text = $out->getHTML();
+ }
+ } catch ( \Exception $ex ) {
+ // PHP 5.3 doesn't have `finally`
+ $exception = $ex;
}
+ // poor man's `finally` block
ob_end_clean();
+ // re-throw any errors after `finally` handling.
+ if ( $exception ) {
+ throw $exception;
+ }
+
$code = $response->getStatusCode();
if ( $code > 0 ) {
diff --git
a/repo/tests/phpunit/includes/LinkedData/EntityDataRequestHandlerTest.php
b/repo/tests/phpunit/includes/LinkedData/EntityDataRequestHandlerTest.php
index fe20662..67f1263 100644
--- a/repo/tests/phpunit/includes/LinkedData/EntityDataRequestHandlerTest.php
+++ b/repo/tests/phpunit/includes/LinkedData/EntityDataRequestHandlerTest.php
@@ -56,6 +56,30 @@
*/
protected $interfaceTitle;
+ protected $obLevel;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->interfaceTitle = Title::newFromText(
"Special:EntityDataRequestHandlerTest" );
+
+ $this->obLevel = ob_get_level();
+ }
+
+ public function tearDown() {
+ $obLevel = ob_get_level();
+
+ while ( ob_get_level() > $this->obLevel ) {
+ ob_end_clean();
+ }
+
+ if ( $obLevel !== $this->obLevel ) {
+ $this->fail( "Test changed output buffer level: was
{$this->obLevel} before test, but $obLevel after test.");
+ }
+
+ parent::tearDown();
+ }
+
protected function saveItem( Item $item ) {
$content = ItemContent::newFromItem( $item );
$content->save( "testing", null, EDIT_NEW );
@@ -71,12 +95,6 @@
}
return $item;
- }
-
- public function setUp() {
- parent::setUp();
-
- $this->interfaceTitle = Title::newFromText(
"Special:EntityDataRequestHandlerTest" );
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/74358
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2e040157b4aadf6bb18581ef2495862d680feec5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits