Skip to content

Commit

Permalink
Setup CI testing (#23)
Browse files Browse the repository at this point in the history
* Initial test setup
* Fix extension.json for manifest v2
* Run analysis on installed extension
  • Loading branch information
s7eph4n authored Aug 24, 2019
1 parent f254df9 commit dcfdcc3
Show file tree
Hide file tree
Showing 9 changed files with 440 additions and 24 deletions.
63 changes: 63 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
build:
# The build contains everything related to running test, deployment and analysis commands.
services:
mariadb: 10

dependencies:
override:
- true # do not install any dependencies
tests:
override:
- ~/build/tests/setup/run-tests.sh

nodes:
code-analysis-and-test-mw-master:
environment:
php: 7.3
variables:
MW: master
SBU: composer
tests:
override:
- command: ~/build/tests/setup/run-tests.sh --coverage-clover ~/coverage.xml
coverage:
file: ~/coverage.xml
format: clover
- command: phpcs-run
use_website_config: true
- php-scrutinizer-run --enable-security-analysis
test-mw-min-version:
environment:
php: 7.0
variables:
MW: 1.31.0
SBU: download
test-mw-1.31:
environment:
php: 7.1
variables:
MW: 1.31.3
SBU: composer
test-mw-1.32:
environment:
php: 7.2
variables:
MW: 1.32.3
SBU: download
test-mw-1.33:
environment:
php: 7.2
variables:
MW: 1.33.0
SBU: download

filter:
# The filter section defines which files are analyzed, where dependencies are located and which files should be completely ignored.
dependency_paths:
- mw
excluded_paths:
- mw/extensions

build_failure_conditions: {}
# The build failure conditions section allows you to define failure conditions where a build should be failed based on findings in the analysis.
# Findings can be that code coverage has decreased below a certain point, or that new issues have been found, etc.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
"irc": "irc://irc.freenode.org/mediawiki"
},
"require": {
"mediawiki/mediawiki": ">=1.31",
"php": ">=7.0",
"mediawiki/mediawiki": ">=1.31"
"composer/installers": "1.*,>=1.0.1"
},
"extra": {
"branch-alias": {
Expand Down
4 changes: 3 additions & 1 deletion extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
},
"config": {
"SimpleBatchUploadMaxFilesPerBatch": {
"*": 1000
"value":{
"*": 1000
}
}
},
"AutoloadNamespaces": {
Expand Down
26 changes: 26 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
cacheTokens="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
strict="true"
verbose="true">
<!--bootstrap="tests/bootstrap.php"-->
<testsuites>
<testsuite name="extension-simple-batch-upload">
<directory>tests/phpunit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
2 changes: 1 addition & 1 deletion release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Changes:
* Raise minimum required versions to
* MediaWiki 1.31
* PHP 7.0
* Use MW autoloader (replaces Composer autoloader)
* Add CI testing

### SimpleBatchUpload 1.4.0

Expand Down
58 changes: 37 additions & 21 deletions src/SimpleBatchUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* File containing the SimpleBatchUpload class
*
* @copyright (C) 2016 - 2017, Stephan Gambke
* @copyright (C) 2016 - 2019, Stephan Gambke
* @license GNU General Public License, version 2 (or any later version)
*
* This software is free software; you can redistribute it and/or
Expand All @@ -22,6 +22,9 @@

namespace SimpleBatchUpload;

use MediaWiki\MediaWikiServices;
use Parser;

/**
* Class ExtensionManager
*
Expand All @@ -37,26 +40,39 @@ class SimpleBatchUpload {
public static function initCallback() {

$simpleBatchUpload = new self();
$simpleBatchUpload->registerEarlyConfiguration( $GLOBALS );
}

$configuration = $simpleBatchUpload->getConfiguration();

self::mergeConfiguration( $configuration );
/**
* @param $targetConfiguration
*/
public function registerEarlyConfiguration( &$targetConfiguration ){
$sourceConfiguration = $this->getEarlyConfiguration();
$this->mergeConfiguration( $sourceConfiguration, $targetConfiguration );
}

/**
* @param $targetConfiguration
*/
public function registerLateConfiguration( &$targetConfiguration ){
$sourceConfiguration = $this->getLateConfiguration();
$this->mergeConfiguration( $sourceConfiguration, $targetConfiguration );
}

/**
* @param $configuration
* @param array $targetConfiguration
*/
public static function mergeConfiguration( $configuration ) {
foreach ( $configuration as $varname => $value ) {
$GLOBALS[ $varname ] = array_replace_recursive( $GLOBALS[ $varname ], $value );
protected function mergeConfiguration( $sourceConfiguration, &$targetConfiguration ) {
foreach ( $sourceConfiguration as $varname => $value ) {
$targetConfiguration[ $varname ] = array_key_exists( $varname, $targetConfiguration )?array_replace_recursive( $targetConfiguration[ $varname ], $value ):$value;
}
}

/**
* @return array
*/
public function getConfiguration() {
protected function getEarlyConfiguration(): array {

$configuration = [];

Expand All @@ -70,7 +86,18 @@ public function getConfiguration() {
$configuration[ 'wgHooks' ][ 'SetupAfterCache' ][ 'ext.simplebatchupload' ] = [ $this, 'onSetupAfterCache'];

return $configuration;
}


/**
* @return array
*/
protected function getLateConfiguration(): array {

$configuration = [];
$configuration[ 'wgResourceModules' ] = $this->getUploadSupportModuleDefinition() + $this->getUploadModuleDefinition();

return $configuration;
}

/**
Expand All @@ -80,7 +107,7 @@ public function getConfiguration() {
* @throws \MWException
*/
public function registerParserFunction( &$parser ) {
$parser->setFunctionHook( 'batchupload', [ new UploadButtonRenderer(), 'renderParserFunction' ], SFH_OBJECT_ARGS );
$parser->setFunctionHook( 'batchupload', [ new UploadButtonRenderer(), 'renderParserFunction' ], Parser::SFH_OBJECT_ARGS );
return true;
}

Expand Down Expand Up @@ -150,10 +177,7 @@ public function onMakeGlobalVariablesScript( &$vars, $out ) {
}

public function onSetupAfterCache() {

$configuration = [ 'wgResourceModules' => $this->getUploadSupportModuleDefinition() + $this->getUploadModuleDefinition() ];
self::mergeConfiguration( $configuration );

$this->registerLateConfiguration( $GLOBALS );
}

/**
Expand All @@ -167,12 +191,4 @@ public function getMaxFilesPerBatchConfig() {

return $this->maxFilesPerBatchConfig;
}

/**
* @param $maxFilesPerBatchConfig
*/
public function setMaxFilesPerBatchConfig( $maxFilesPerBatchConfig ) {
$this->maxFilesPerBatchConfig = $maxFilesPerBatchConfig;
}

}
Loading

0 comments on commit dcfdcc3

Please sign in to comment.