From 1fb1fa4601b86588256bac743fa931c66b56206a Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Thu, 24 Apr 2014 11:57:41 +0200 Subject: [PATCH] Pass phpcs-strict on some test files (1/x) Change-Id: I7f8dee09ac734cbc369441431841f2d4aa5d7f51 --- tests/phpunit/MediaWikiLangTestCase.php | 1 - .../phpunit/MediaWikiPHPUnitTestListener.php | 26 +++++++++++++---- tests/phpunit/MediaWikiTestCase.php | 9 +++--- tests/phpunit/ResourceLoaderTestCase.php | 5 ++-- tests/phpunit/includes/ArticleTest.php | 4 ++- tests/phpunit/includes/BlockTest.php | 28 +++++++++++++++---- tests/phpunit/includes/EditPageTest.php | 13 +++++++-- tests/phpunit/includes/ExternalStoreTest.php | 5 +++- tests/phpunit/includes/ExtraParserTest.php | 25 ++++++++++++++--- 9 files changed, 88 insertions(+), 28 deletions(-) diff --git a/tests/phpunit/MediaWikiLangTestCase.php b/tests/phpunit/MediaWikiLangTestCase.php index 1131385f6b..53e672247e 100644 --- a/tests/phpunit/MediaWikiLangTestCase.php +++ b/tests/phpunit/MediaWikiLangTestCase.php @@ -4,7 +4,6 @@ * Base class that store and restore the Language objects */ abstract class MediaWikiLangTestCase extends MediaWikiTestCase { - protected function setUp() { global $wgLanguageCode, $wgContLang; parent::setUp(); diff --git a/tests/phpunit/MediaWikiPHPUnitTestListener.php b/tests/phpunit/MediaWikiPHPUnitTestListener.php index c8ec4114d0..9eeb251e13 100644 --- a/tests/phpunit/MediaWikiPHPUnitTestListener.php +++ b/tests/phpunit/MediaWikiPHPUnitTestListener.php @@ -1,6 +1,6 @@ logChannel, 'ERROR in ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e ) ); + wfDebugLog( + $this->logChannel, + 'ERROR in ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e ) + ); } /** @@ -45,8 +48,13 @@ class MediaWikiPHPUnitTestListener implements PHPUnit_Framework_TestListener { * @param PHPUnit_Framework_AssertionFailedError $e * @param float $time */ - public function addFailure( PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time ) { - wfDebugLog( $this->logChannel, 'FAILURE in ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e ) ); + public function addFailure( PHPUnit_Framework_Test $test, + PHPUnit_Framework_AssertionFailedError $e, $time + ) { + wfDebugLog( + $this->logChannel, + 'FAILURE in ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e ) + ); } /** @@ -57,7 +65,10 @@ class MediaWikiPHPUnitTestListener implements PHPUnit_Framework_TestListener { * @param float $time */ public function addIncompleteTest( PHPUnit_Framework_Test $test, Exception $e, $time ) { - wfDebugLog( $this->logChannel, 'Incomplete test ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e ) ); + wfDebugLog( + $this->logChannel, + 'Incomplete test ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e ) + ); } /** @@ -70,7 +81,10 @@ class MediaWikiPHPUnitTestListener implements PHPUnit_Framework_TestListener { * @since Method available since Release 3.0.0 */ public function addSkippedTest( PHPUnit_Framework_Test $test, Exception $e, $time ) { - wfDebugLog( $this->logChannel, 'Skipped test ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e ) ); + wfDebugLog( + $this->logChannel, + 'Skipped test ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e ) + ); } /** diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index 1c9b7fb32b..53b944d6a4 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -4,7 +4,6 @@ * @since 1.18 */ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { - /** * $called tracks whether the setUp and tearDown method has been called. * class extending MediaWikiTestCase usually override setUp and tearDown @@ -254,7 +253,8 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { $oldHex = strtoupper( dechex( $this->phpErrorLevel ) ); $newHex = strtoupper( dechex( $phpErrorLevel ) ); - $message = "PHP error_reporting setting was left dirty: was 0x$oldHex before test, 0x$newHex after test!"; + $message = "PHP error_reporting setting was left dirty: " + . "was 0x$oldHex before test, 0x$newHex after test!"; $this->fail( $message ); } @@ -772,7 +772,9 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { * @param bool $ordered If the order of the values should match * @param bool $named If the keys should match */ - protected function assertArrayEquals( array $expected, array $actual, $ordered = false, $named = false ) { + protected function assertArrayEquals( array $expected, array $actual, + $ordered = false, $named = false + ) { if ( !$ordered ) { $this->objectAssociativeSort( $expected ); $this->objectAssociativeSort( $actual ); @@ -1105,5 +1107,4 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { $this->assertEmpty( $errors, implode( "\n", $errors ) ); } - } diff --git a/tests/phpunit/ResourceLoaderTestCase.php b/tests/phpunit/ResourceLoaderTestCase.php index a03e9ccc86..f8c4c6c8ae 100644 --- a/tests/phpunit/ResourceLoaderTestCase.php +++ b/tests/phpunit/ResourceLoaderTestCase.php @@ -1,7 +1,6 @@ assertTrue( $this->block->equals( Block::newFromTarget( 'UTBlockee' ) ), "newFromTarget() returns the same block as the one that was made" ); + $this->assertTrue( + $this->block->equals( Block::newFromTarget( 'UTBlockee' ) ), + "newFromTarget() returns the same block as the one that was made" + ); } /** * @covers Block::newFromID */ public function testINewFromIDReturnsCorrectBlock() { - $this->assertTrue( $this->block->equals( Block::newFromID( $this->blockId ) ), "newFromID() returns the same block as the one that was made" ); + $this->assertTrue( + $this->block->equals( Block::newFromID( $this->blockId ) ), + "newFromID() returns the same block as the one that was made" + ); } /** @@ -88,7 +94,11 @@ class BlockTest extends MediaWikiLangTestCase { public function testBug26425BlockTimestampDefaultsToTime() { // delta to stop one-off errors when things happen to go over a second mark. $delta = abs( $this->madeAt - $this->block->mTimestamp ); - $this->assertLessThan( 2, $delta, "If no timestamp is specified, the block is recorded as time()" ); + $this->assertLessThan( + 2, + $delta, + "If no timestamp is specified, the block is recorded as time()" + ); } /** @@ -101,7 +111,11 @@ class BlockTest extends MediaWikiLangTestCase { */ public function testBug29116NewFromTargetWithEmptyIp( $vagueTarget ) { $block = Block::newFromTarget( 'UTBlockee', $vagueTarget ); - $this->assertTrue( $this->block->equals( $block ), "newFromTarget() returns the same block as the one that was made when given empty vagueTarget param " . var_export( $vagueTarget, true ) ); + $this->assertTrue( + $this->block->equals( $block ), + "newFromTarget() returns the same block as the one that was made when " + . "given empty vagueTarget param " . var_export( $vagueTarget, true ) + ); } public static function provideBug29116Data() { @@ -215,7 +229,11 @@ class BlockTest extends MediaWikiLangTestCase { $user = null; // clear $block = Block::newFromID( $res['id'] ); - $this->assertEquals( 'UserOnForeignWiki', $block->getTarget()->getName(), 'Correct blockee name' ); + $this->assertEquals( + 'UserOnForeignWiki', + $block->getTarget()->getName(), + 'Correct blockee name' + ); $this->assertEquals( '14146', $block->getTarget()->getId(), 'Correct blockee id' ); $this->assertEquals( 'MetaWikiUser', $block->getBlocker(), 'Correct blocker name' ); $this->assertEquals( 'MetaWikiUser', $block->getByName(), 'Correct blocker name' ); diff --git a/tests/phpunit/includes/EditPageTest.php b/tests/phpunit/includes/EditPageTest.php index 4da844809c..3c653b4a7a 100644 --- a/tests/phpunit/includes/EditPageTest.php +++ b/tests/phpunit/includes/EditPageTest.php @@ -75,7 +75,8 @@ class EditPageTest extends MediaWikiLangTestCase { * * wpTextbox1: the text to submit * * wpSummary: the edit summary * * wpEditToken: the edit token (will be inserted if not provided) - * * wpEdittime: timestamp of the edit's base revision (will be inserted if not provided) + * * wpEdittime: timestamp of the edit's base revision (will be inserted + * if not provided) * * wpStarttime: timestamp when the edit started (will be inserted if not provided) * * wpSectionTitle: the section to edit * * wpMinorEdit: mark as minor edit @@ -474,8 +475,14 @@ hello } $starttime = wfTimestampNow(); - $adamsTime = wfTimestamp( TS_MW, (int)wfTimestamp( TS_UNIX, $starttime ) + (int)$adamsEdit['wpStarttime'] ); - $bertasTime = wfTimestamp( TS_MW, (int)wfTimestamp( TS_UNIX, $starttime ) + (int)$bertasEdit['wpStarttime'] ); + $adamsTime = wfTimestamp( + TS_MW, + (int)wfTimestamp( TS_UNIX, $starttime ) + (int)$adamsEdit['wpStarttime'] + ); + $bertasTime = wfTimestamp( + TS_MW, + (int)wfTimestamp( TS_UNIX, $starttime ) + (int)$bertasEdit['wpStarttime'] + ); $adamsEdit['wpStarttime'] = $adamsTime; $bertasEdit['wpStarttime'] = $bertasTime; diff --git a/tests/phpunit/includes/ExternalStoreTest.php b/tests/phpunit/includes/ExternalStoreTest.php index cd3364e227..07c2957c3a 100644 --- a/tests/phpunit/includes/ExternalStoreTest.php +++ b/tests/phpunit/includes/ExternalStoreTest.php @@ -75,7 +75,10 @@ class ExternalStoreFOO { return null; } - if ( $itemID !== false && is_array( $this->data[$cluster][$id] ) && isset( $this->data[$cluster][$id][$itemID] ) ) { + if ( $itemID !== false + && is_array( $this->data[$cluster][$id] ) + && isset( $this->data[$cluster][$id][$itemID] ) + ) { return $this->data[$cluster][$id][$itemID]; } diff --git a/tests/phpunit/includes/ExtraParserTest.php b/tests/phpunit/includes/ExtraParserTest.php index 3cf7abdcf7..4a4130e048 100644 --- a/tests/phpunit/includes/ExtraParserTest.php +++ b/tests/phpunit/includes/ExtraParserTest.php @@ -130,8 +130,16 @@ class ExtraParserTest extends MediaWikiTestCase { * @covers Parser::getSection */ public function testGetSection() { - $outputText2 = $this->parser->getSection( "Section 0\n== Heading 1 ==\nSection 1\n=== Heading 2 ===\nSection 2\n== Heading 3 ==\nSection 3\n", 2 ); - $outputText1 = $this->parser->getSection( "Section 0\n== Heading 1 ==\nSection 1\n=== Heading 2 ===\nSection 2\n== Heading 3 ==\nSection 3\n", 1 ); + $outputText2 = $this->parser->getSection( + "Section 0\n== Heading 1 ==\nSection 1\n=== Heading 2 ===\n" + . "Section 2\n== Heading 3 ==\nSection 3\n", + 2 + ); + $outputText1 = $this->parser->getSection( + "Section 0\n== Heading 1 ==\nSection 1\n=== Heading 2 ===\n" + . "Section 2\n== Heading 3 ==\nSection 3\n", + 1 + ); $this->assertEquals( "=== Heading 2 ===\nSection 2", $outputText2 ); $this->assertEquals( "== Heading 1 ==\nSection 1\n=== Heading 2 ===\nSection 2", $outputText1 ); @@ -141,7 +149,12 @@ class ExtraParserTest extends MediaWikiTestCase { * @covers Parser::replaceSection */ public function testReplaceSection() { - $outputText = $this->parser->replaceSection( "Section 0\n== Heading 1 ==\nSection 1\n=== Heading 2 ===\nSection 2\n== Heading 3 ==\nSection 3\n", 1, "New section 1" ); + $outputText = $this->parser->replaceSection( + "Section 0\n== Heading 1 ==\nSection 1\n=== Heading 2 ===\n" + . "Section 2\n== Heading 3 ==\nSection 3\n", + 1, + "New section 1" + ); $this->assertEquals( "Section 0\nNew section 1\n\n== Heading 3 ==\nSection 3", $outputText ); } @@ -152,7 +165,11 @@ class ExtraParserTest extends MediaWikiTestCase { */ public function testGetPreloadText() { $title = Title::newFromText( __FUNCTION__ ); - $outputText = $this->parser->getPreloadText( "{{Foo}} censored information ", $title, $this->options ); + $outputText = $this->parser->getPreloadText( + "{{Foo}} censored information ", + $title, + $this->options + ); $this->assertEquals( "{{Foo}} information ", $outputText ); } -- 2.20.1