Jeroen De Dauw has submitted this change and it was merged.
Change subject: Added phpunit config file and bootstrap
......................................................................
Added phpunit config file and bootstrap
Change-Id: I6076028e193a8921059ef310dde5dc36b5a705c1
---
M ParserHooks.php
A phpunit.xml.dist
R src/ParserHooks/FunctionRunner.php
R src/ParserHooks/HookDefinition.php
R src/ParserHooks/HookHandler.php
R src/ParserHooks/HookRegistrant.php
A tests/bootstrap.php
A tests/evilMediaWikiBootstrap.php
M tests/phpunit/HookDefinitionTest.php
9 files changed, 116 insertions(+), 5 deletions(-)
Approvals:
Jeroen De Dauw: Verified; Looks good to me, approved
diff --git a/ParserHooks.php b/ParserHooks.php
index e8a0d0b..0f4320f 100644
--- a/ParserHooks.php
+++ b/ParserHooks.php
@@ -48,7 +48,7 @@
if ( $namespaceSegments[0] === 'ParserHooks' ) {
if ( count( $namespaceSegments ) === 1 || $namespaceSegments[1]
!== 'Tests' ) {
- require_once __DIR__ . '/includes/' . $fileName;
+ require_once __DIR__ . '/src/' . $fileName;
}
}
} );
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
new file mode 100644
index 0000000..051c31f
--- /dev/null
+++ b/phpunit.xml.dist
@@ -0,0 +1,20 @@
+<phpunit backupGlobals="false"
+ backupStaticAttributes="false"
+ bootstrap="tests/bootstrap.php"
+ cacheTokens="false"
+ colors="true"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ stopOnError="false"
+ stopOnFailure="false"
+ stopOnIncomplete="false"
+ stopOnSkipped="false"
+ strict="true"
+ verbose="true">
+ <testsuites>
+ <testsuite name="ParserHooks">
+ <directory>tests/phpunit</directory>
+ </testsuite>
+ </testsuites>
+</phpunit>
diff --git a/includes/FunctionRunner.php b/src/ParserHooks/FunctionRunner.php
similarity index 100%
rename from includes/FunctionRunner.php
rename to src/ParserHooks/FunctionRunner.php
diff --git a/includes/HookDefinition.php b/src/ParserHooks/HookDefinition.php
similarity index 100%
rename from includes/HookDefinition.php
rename to src/ParserHooks/HookDefinition.php
diff --git a/includes/HookHandler.php b/src/ParserHooks/HookHandler.php
similarity index 100%
rename from includes/HookHandler.php
rename to src/ParserHooks/HookHandler.php
diff --git a/includes/HookRegistrant.php b/src/ParserHooks/HookRegistrant.php
similarity index 100%
rename from includes/HookRegistrant.php
rename to src/ParserHooks/HookRegistrant.php
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
new file mode 100644
index 0000000..7ede240
--- /dev/null
+++ b/tests/bootstrap.php
@@ -0,0 +1,17 @@
+<?php
+
+/**
+ * PHPUnit bootstrap file for the ParserHooks extension.
+ *
+ * @since 0.1
+ *
+ * @file
+ * @ingroup ParserHooks
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+
+require_once( __DIR__ . '/evilMediaWikiBootstrap.php' );
+
+require_once( __DIR__ . '/../ParserHooks.php' );
diff --git a/tests/evilMediaWikiBootstrap.php b/tests/evilMediaWikiBootstrap.php
new file mode 100644
index 0000000..b8bad0b
--- /dev/null
+++ b/tests/evilMediaWikiBootstrap.php
@@ -0,0 +1,65 @@
+<?php
+
+define( 'MEDIAWIKI', true );
+
+global $IP;
+$IP = getenv( 'MW_INSTALL_PATH' );
+
+if ( $IP === false ) {
+ $IP = dirname( __FILE__ ) . '/../../..';
+}
+
+$self = 'foobar';
+
+// Detect compiled mode
+# Get the MWInit class
+require_once "$IP/includes/Init.php";
+require_once "$IP/includes/AutoLoader.php";
+# Stub the profiler
+require_once "$IP/includes/profiler/Profiler.php";
+
+# Start the profiler
+$wgProfiler = array();
+if ( file_exists( "$IP/StartProfiler.php" ) ) {
+ require "$IP/StartProfiler.php";
+}
+
+// Some other requires
+require_once "$IP/includes/Defines.php";
+
+require_once MWInit::compiledPath( 'includes/DefaultSettings.php' );
+
+foreach ( get_defined_vars() as $key => $var ) {
+ if ( !array_key_exists( $key, $GLOBALS ) ) {
+ $GLOBALS[$key] = $var;
+ }
+}
+
+if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
+ # Use a callback function to configure MediaWiki
+ MWFunction::call( MW_CONFIG_CALLBACK );
+} else {
+ // Require the configuration (probably LocalSettings.php)
+ require loadSettings();
+}
+
+// Some last includes
+require_once MWInit::compiledPath( 'includes/Setup.php' );
+
+// Much much faster startup than creating a title object
+$wgTitle = null;
+
+
+function loadSettings() {
+ global $wgCommandLineMode, $IP;
+
+ $settingsFile = "$IP/LocalSettings.php";
+
+ if ( !is_readable( $settingsFile ) ) {
+ $this->error( "A copy of your installation's
LocalSettings.php\n" .
+ "must exist and be readable in the source directory.\n"
.
+ "Use --conf to specify it.", true );
+ }
+ $wgCommandLineMode = true;
+ return $settingsFile;
+}
\ No newline at end of file
diff --git a/tests/phpunit/HookDefinitionTest.php
b/tests/phpunit/HookDefinitionTest.php
index c40a402..7d1bafa 100644
--- a/tests/phpunit/HookDefinitionTest.php
+++ b/tests/phpunit/HookDefinitionTest.php
@@ -30,7 +30,7 @@
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
*/
-class HookDefinitionTest extends \MediaWikiTestCase {
+class HookDefinitionTest extends \PHPUnit_Framework_TestCase {
public function namesProvider() {
return $this->arrayWrap( array(
@@ -54,7 +54,7 @@
$this->assertInternalType( 'array', $obtainedNames );
$this->assertContainsOnly( 'string', $obtainedNames );
- $this->assertArrayEquals( (array)$names, $obtainedNames );
+ $this->assertEquals( (array)$names, $obtainedNames );
}
public function parametersProvider() {
@@ -71,7 +71,7 @@
public function testGetParameters( array $parameters ) {
$definition = new \ParserHooks\HookDefinition( 'foo',
$parameters );
- $this->assertArrayEquals( $parameters,
$definition->getParameters() );
+ $this->assertEquals( $parameters, $definition->getParameters()
);
}
public function defaultParametersProvider() {
@@ -96,7 +96,16 @@
$this->assertInternalType( 'array', $obtainedDefaultParams );
$this->assertContainsOnly( 'string', $obtainedDefaultParams );
- $this->assertArrayEquals( (array)$defaultParameters,
$obtainedDefaultParams );
+ $this->assertEquals( (array)$defaultParameters,
$obtainedDefaultParams );
+ }
+
+ protected function arrayWrap( array $elements ) {
+ return array_map(
+ function( $element ) {
+ return array( $element );
+ },
+ $elements
+ );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/72461
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6076028e193a8921059ef310dde5dc36b5a705c1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ParserHooks
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits