Skip to content

Commit

Permalink
Restore ability to run tests independently from MW
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenDeDauw committed May 17, 2018
1 parent cc19223 commit 2ca48cf
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -8,4 +8,6 @@ vendor/
extensions/

composer.phar
composer.lock
composer.lock

phpunit.phar
11 changes: 8 additions & 3 deletions README.md
Expand Up @@ -60,12 +60,17 @@ Maps has been maintained since 2009 and is installed on over 1000 public wikis.

As setup, run `composer install` inside of the Maps root directory.

You can run the MediaWiki independent tests by changing into the Maps root directory and running
You can run the MediaWiki independent tests by executing phpunit in the root directory of maps:

phpunit

php vendor/bin/phpunit

This is possible without having a MediaWiki installation or webserver. A clone of the Maps code suffices.

If you do not have PHPUnit installed, you can download the .phar into the root directory and execute it there:

wget -O phpunit.phar https://phar.phpunit.de/phpunit-7.phar
php phpunit.phar

To run the tests with MediaWiki, change into `tests/phpunit` of your MediaWiki installation and run

php phpunit.php --wiki wiki -c ../../extensions/Maps/phpunit.xml.dist
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/parsers/DistanceParserTest.php
Expand Up @@ -44,7 +44,7 @@ public function validInputProvider() {
public function testGivenInvalidInput_exceptionIsThrown( $input ) {
$parser = new DistanceParser();

$this->setExpectedException( ParseException::class );
$this->expectException( ParseException::class );
$parser->parse( $input );
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/parsers/WmsOverlayParserTest.php
Expand Up @@ -48,7 +48,7 @@ public function testWhenStyleNameIsSpecified_getStyleNameReturnsIt() {
public function testWhenThereAreLessThanTwoSegments_parseExceptionIsThrown() {
$parser = new WmsOverlayParser();

$this->setExpectedException( ParseException::class );
$this->expectException( ParseException::class );
$parser->parse( 'Such' );
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Elements/BaseElementTest.php
Expand Up @@ -80,7 +80,7 @@ public function testGivenValidArguments_constructorDoesNotThrowException() {
* @since 3.0
*/
public function testGivenInvalidArguments_constructorThrowsException() {
$this->setExpectedException( InvalidArgumentException::class );
$this->expectException( InvalidArgumentException::class );
call_user_func_array( [ $this, 'newInstance' ], func_get_args() );
}

Expand Down
22 changes: 15 additions & 7 deletions tests/bootstrap.php
@@ -1,18 +1,26 @@
<?php

// If testing against an older version of MediaWiki, define
// an empty trait to avoid fatal errors.
if ( !trait_exists( PHPUnit4And6Compat::class ) ) {
trait PHPUnit4And6Compat {
}
if ( PHP_SAPI !== 'cli' ) {
die( 'Not an entry point' );
}

if ( defined( 'MEDIAWIKI' ) ) {
// If testing against an older version of MediaWiki, define
// an empty trait to avoid fatal errors.
if ( !trait_exists( PHPUnit4And6Compat::class ) ) {
trait PHPUnit4And6Compat {
public function expectException( string $exception ) {
$this->setExpectedException( $exception );
}
}
}

return;
}

if ( PHP_SAPI !== 'cli' ) {
die( 'Not an entry point' );
if ( !trait_exists( PHPUnit4And6Compat::class ) ) {
trait PHPUnit4And6Compat {
}
}

error_reporting( -1 );
Expand Down

0 comments on commit 2ca48cf

Please sign in to comment.