Skip to content

Commit

Permalink
Merge pull request #230 from JeroenDeDauw/suchunit
Browse files Browse the repository at this point in the history
Allow running the unit tests without MediaWiki
  • Loading branch information
JeroenDeDauw committed Sep 13, 2016
2 parents 7567178 + 7e2169a commit 298fc2e
Show file tree
Hide file tree
Showing 20 changed files with 39 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -50,6 +50,10 @@ install and running

php phpunit.php -c ../../extensions/Maps/

You can run the MediaWiki independent tests by running `composer unit` in the root directory of Maps.
All tests in `tests/phpunit` are MediaWiki independent, with those depending on MediaWiki residing in
`tests/Integration`.

## Credits to other projects

### jQuery
Expand Down
13 changes: 8 additions & 5 deletions composer.json
Expand Up @@ -46,15 +46,17 @@
},
"classmap": [
"includes/",
"Maps.hooks.php",
"tests/phpunit/elements/",
"tests/phpunit/parserhooks/ParserHookTest.php"
"Maps.hooks.php"
]
},
"autoload-dev": {
"psr-4": {
"Maps\\Tests\\TestDoubles\\": "tests/TestDoubles/"
}
},
"classmap": [
"tests/phpunit/elements/",
"tests/Integration/parserhooks/ParserHookTest.php"
]
},
"extra": {
"branch-alias": {
Expand All @@ -65,6 +67,7 @@
"process-timeout": 0
},
"scripts":{
"phpunit": "php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist"
"phpunit": "php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist",
"unit-test": "php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist tests/phpunit"
}
}
1 change: 1 addition & 0 deletions phpunit.xml.dist
@@ -1,5 +1,6 @@
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
cacheTokens="false"
colors="true"
convertErrorsToExceptions="true"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 26 additions & 1 deletion tests/bootstrap.php
@@ -1,5 +1,9 @@
<?php

if ( defined( 'MEDIAWIKI' ) ) {
return;
}

if ( PHP_SAPI !== 'cli' ) {
die( 'Not an entry point' );
}
Expand All @@ -11,4 +15,25 @@
die( 'You need to install this package with Composer before you can run the tests' );
}

require_once __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../vendor/composer/ClassLoader.php';

call_user_func( function() {
$loader = new \Composer\Autoload\ClassLoader();

foreach ( require __DIR__ . '/../vendor/composer/autoload_namespaces.php' as $namespace => $path ) {
$loader->set( $namespace, $path );
}

foreach ( require __DIR__ . '/../vendor/composer/autoload_psr4.php' as $namespace => $path ) {
$loader->setPsr4( $namespace, $path );
}

$classMap = require __DIR__ . '/../vendor/composer/autoload_classmap.php';

if ( $classMap ) {
$loader->addClassMap( $classMap );
}

$loader->register( true );
} );

0 comments on commit 298fc2e

Please sign in to comment.