jenkins-bot has submitted this change and it was merged. Change subject: Improve testing infrastructure ......................................................................
Improve testing infrastructure * Instead of a hacky 'sed -i' in composer.json, dynamically declare the class MediaWikiTestCase if missing (when PHPUnit is called directly). * Check if phpdbg is installed, else use php * Skip two tests when running HHVM because of issue #4797 "Multiple calls of 'include' do not check for file modification HHVM 3.5.0" https://github.com/facebook/hhvm/issues/4797 Possibly a workaround will be later added, but for now try to render MediaWikiFarm compatible with WMF CI suites * Fixed two phpcs issues * Dynamically create two JSON files with bad syntax (used in a test) to avoid trigerring a CI error report * Made phpdoc optional for now Bug: T151879 Change-Id: I17604c11e773f74f2c8b7ccb6aa7919cb729d552 --- M composer.json M src/MediaWikiFarm.php M tests/phpunit/ConfigurationTest.php M tests/phpunit/MediaWikiFarmTestCase.php M tests/phpunit/MultiversionInstallationTest.php D tests/phpunit/data/config/badsyntax.json D tests/phpunit/data/config/empty.json 7 files changed, 35 insertions(+), 17 deletions(-) Approvals: Seb35: Looks good to me, approved jenkins-bot: Verified diff --git a/composer.json b/composer.json index 7a94498..61956c2 100644 --- a/composer.json +++ b/composer.json @@ -16,27 +16,21 @@ }, "require-dev": { "justinrainbow/json-schema": "~3.0", - "phpdocumentor/phpdocumentor": "*", "phpunit/phpunit": "~4.8", "jakub-onderka/php-parallel-lint": "*", "phpmd/phpmd": "*", "mediawiki/mediawiki-codesniffer": "*" }, + "suggest": { + "phpdocumentor/phpdocumentor": "*" + }, "scripts": { "validate-schema": "php ./bin/validate-schema.php", "lint": "parallel-lint --exclude vendor .", "phpcs": "phpcs -p -s", - "phpdoc": "phpdoc -d bin,src -t ./docs/code", - "phpunit": [ - "sed -i 's/extends MediaWikiTestCase/extends PHPUnit_Framework_TestCase/' tests/phpunit/MediaWikiFarmTestCase.php", - "phpdbg -qrr `which phpunit` --strict-coverage", - "sed -i 's/extends PHPUnit_Framework_TestCase/extends MediaWikiTestCase/' tests/phpunit/MediaWikiFarmTestCase.php" - ], - "unit": [ - "sed -i 's/extends MediaWikiTestCase/extends PHPUnit_Framework_TestCase/' tests/phpunit/MediaWikiFarmTestCase.php", - "phpunit --no-coverage", - "sed -i 's/extends PHPUnit_Framework_TestCase/extends MediaWikiTestCase/' tests/phpunit/MediaWikiFarmTestCase.php" - ], + "phpdoc": "[ \"`which phpdoc`\" = \"\" ] || phpdoc -d bin,src -t ./docs/code", + "phpunit": "which phpdbg && phpdbg -qrr `which phpunit` --strict-coverage || phpunit --strict-coverage", + "unit": "phpunit --no-coverage", "test": [ "composer lint", "composer unit", diff --git a/src/MediaWikiFarm.php b/src/MediaWikiFarm.php index 7d47050..8a324ad 100644 --- a/src/MediaWikiFarm.php +++ b/src/MediaWikiFarm.php @@ -539,7 +539,9 @@ } # Shortcut loading + // @codingStandardsIgnoreStart if( $this->cacheDir && ( $result = $this->readFile( 'versions.php', $this->cacheDir, false ) ) && array_key_exists( $host, $result ) ) { + // @codingStandardsIgnoreEnd $result = $result[$host]; $fresh = true; $myfreshness = filemtime( $this->cacheDir . '/versions.php' ); diff --git a/tests/phpunit/ConfigurationTest.php b/tests/phpunit/ConfigurationTest.php index 4c03391..7e4b13d 100644 --- a/tests/phpunit/ConfigurationTest.php +++ b/tests/phpunit/ConfigurationTest.php @@ -182,7 +182,6 @@ $farm->checkExistence(); $farm->getMediaWikiConfig(); $settings = $farm->getConfiguration( 'settings' ); - #$this->assertEquals( [], $settings ); $extensions = $farm->getConfiguration( 'extensions' ); $skins = $farm->getConfiguration( 'skins' ); $this->assertTrue( $settings['wgUseExtensionTestExtensionBiLoading'] ); diff --git a/tests/phpunit/MediaWikiFarmTestCase.php b/tests/phpunit/MediaWikiFarmTestCase.php index 9b5e037..d9493b6 100644 --- a/tests/phpunit/MediaWikiFarmTestCase.php +++ b/tests/phpunit/MediaWikiFarmTestCase.php @@ -9,6 +9,13 @@ require_once dirname( dirname( dirname( __FILE__ ) ) ) . '/src/AbstractMediaWikiFarmScript.php'; +# These tests can be called either directly with PHPUnit or through the PHPUnit infrastructure +# inside MediaWiki (the wrapper tests/phpunit/phpunit.php). +# When executing PHPUnit alone, this class does not exist +if( !class_exists( 'MediaWikiTestCase' ) ) { + + class MediaWikiTestCase extends PHPUnit_Framework_TestCase {} +} abstract class MediaWikiFarmTestCase extends MediaWikiTestCase { @@ -76,6 +83,10 @@ # Move http404.php to current directory - @todo: should be improved copy( self::$wgMediaWikiFarmConfigDir . '/http404.php', 'phpunitHTTP404.php' ); + + # Dynamically create these files to avoid CI error reports + file_put_contents( self::$wgMediaWikiFarmConfigDir . '/badsyntax.json', "{\n\t\"element1\",\n}\n" ); + file_put_contents( self::$wgMediaWikiFarmConfigDir . '/empty.json', "null\n" ); } /** @@ -101,6 +112,12 @@ if( is_file( 'phpunitHTTP404.php' ) ) { unlink( 'phpunitHTTP404.php' ); } + if( is_file( self::$wgMediaWikiFarmConfigDir . '/badsyntax.json' ) ) { + unlink( self::$wgMediaWikiFarmConfigDir . '/badsyntax.json' ); + } + if( is_file( self::$wgMediaWikiFarmConfigDir . '/empty.json' ) ) { + unlink( self::$wgMediaWikiFarmConfigDir . '/empty.json' ); + } parent::tearDownAfterClass(); } diff --git a/tests/phpunit/MultiversionInstallationTest.php b/tests/phpunit/MultiversionInstallationTest.php index f48ef73..693e041 100644 --- a/tests/phpunit/MultiversionInstallationTest.php +++ b/tests/phpunit/MultiversionInstallationTest.php @@ -369,6 +369,11 @@ $this->assertTrue( is_file( self::$wgMediaWikiFarmConfigDir . '/deployments.php' ) ); $this->assertTrue( $farm->checkExistence() ); + + if( strpos( phpversion(), 'hhvm' ) !== false ) { + return; # Multiple calls of 'include' do not check for file modification HHVM 3.5.0 https://github.com/facebook/hhvm/issues/4797 + } + $this->assertEquals( 'vstub2', $farm->getVariable( '$VERSION' ) ); $farm->updateVersionAfterMaintenance(); @@ -414,6 +419,11 @@ $this->assertTrue( is_file( self::$wgMediaWikiFarmConfigDir . '/deployments.php' ) ); $this->assertTrue( $farm->checkExistence() ); + + if( strpos( phpversion(), 'hhvm' ) !== false ) { + return; # Multiple calls of 'include' do not check for file modification HHVM 3.5.0 https://github.com/facebook/hhvm/issues/4797 + } + $this->assertEquals( 'vstub2', $farm->getVariable( '$VERSION' ) ); } diff --git a/tests/phpunit/data/config/badsyntax.json b/tests/phpunit/data/config/badsyntax.json deleted file mode 100644 index 761df94..0000000 --- a/tests/phpunit/data/config/badsyntax.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "element1", -} diff --git a/tests/phpunit/data/config/empty.json b/tests/phpunit/data/config/empty.json deleted file mode 100644 index 19765bd..0000000 --- a/tests/phpunit/data/config/empty.json +++ /dev/null @@ -1 +0,0 @@ -null -- To view, visit https://gerrit.wikimedia.org/r/324693 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I17604c11e773f74f2c8b7ccb6aa7919cb729d552 Gerrit-PatchSet: 7 Gerrit-Project: mediawiki/extensions/MediaWikiFarm Gerrit-Branch: master Gerrit-Owner: Seb35 <seb35wikipe...@gmail.com> Gerrit-Reviewer: Hashar <has...@free.fr> Gerrit-Reviewer: Seb35 <seb35wikipe...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits