Skip to content

Commit

Permalink
Improve testing infrastructure
Browse files Browse the repository at this point in the history
* 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"
  facebook/hhvm#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
  • Loading branch information
Seb35 committed Dec 5, 2016
1 parent c47521d commit 74cef8c
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 17 deletions.
18 changes: 6 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/MediaWikiFarm.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,9 @@ function __construct( $host, $configDir, $codeDir = null, $cacheDir = false, $pa
}

# 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' );
Expand Down
1 change: 0 additions & 1 deletion tests/phpunit/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ function testLoadingMechanisms() {
$farm->checkExistence();
$farm->getMediaWikiConfig();
$settings = $farm->getConfiguration( 'settings' );
#$this->assertEquals( [], $settings );
$extensions = $farm->getConfiguration( 'extensions' );
$skins = $farm->getConfiguration( 'skins' );
$this->assertTrue( $settings['wgUseExtensionTestExtensionBiLoading'] );
Expand Down
17 changes: 17 additions & 0 deletions tests/phpunit/MediaWikiFarmTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -76,6 +83,10 @@ static function setUpBeforeClass() {

# 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" );
}

/**
Expand All @@ -101,6 +112,12 @@ static function tearDownAfterClass() {
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();
}
Expand Down
10 changes: 10 additions & 0 deletions tests/phpunit/MultiversionInstallationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@ function testDeploymedVersions3() {

$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();
Expand Down Expand Up @@ -414,6 +419,11 @@ function testDeploymedVersions4() {

$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' ) );
}

Expand Down
3 changes: 0 additions & 3 deletions tests/phpunit/data/config/badsyntax.json

This file was deleted.

1 change: 0 additions & 1 deletion tests/phpunit/data/config/empty.json

This file was deleted.

0 comments on commit 74cef8c

Please sign in to comment.