Skip to content
This repository has been archived by the owner on Sep 20, 2019. It is now read-only.

Commit

Permalink
Improve autoloading code
Browse files Browse the repository at this point in the history
* Removed custom autoloaders
* Use Composer classmap (psr-0 would require making the dir structure deeper)
* Updated TravisCI config
  • Loading branch information
JeroenDeDauw committed Nov 9, 2013
1 parent 4b778a8 commit 40513fa
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 95 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -35,6 +35,7 @@ script:
- if [ "$TESTSUITE" == "MediaWiki" ] ; then phpunit --coverage-clover build/logs/clover.xml ; fi

after_script:
- composer require satooshi/php-coveralls dev-master
- php vendor/bin/coveralls -v

notifications:
Expand Down
8 changes: 4 additions & 4 deletions WikibaseDatabase.mw.php
Expand Up @@ -12,6 +12,10 @@
die( 'Not an entry point.' );
}

if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
require_once( __DIR__ . '/vendor/autoload.php' );
}

$GLOBALS['wgExtensionCredits']['wikibase'][] = array(
'path' => __DIR__,
'name' => 'Wikibase Database',
Expand All @@ -26,10 +30,6 @@

$GLOBALS['wgExtensionMessagesFiles']['WikibaseDatabase'] = __DIR__ . '/WikibaseDatabase.i18n.php';

if ( defined( 'MW_PHPUNIT_TEST' ) ) {
require_once __DIR__ . '/tests/testLoader.php';
}

/**
* Hook to add PHPUnit test cases.
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UnitTestsList
Expand Down
52 changes: 8 additions & 44 deletions WikibaseDatabase.php
Expand Up @@ -3,54 +3,18 @@
/**
* Entry point of the Wikibase Database component.
*
* @codeCoverageIgnore
*
* @licence GNU GPL v2+
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/

if ( defined( 'WIKIBASE_DATABASE_VERSION' ) ) {
// Do not initialize more then once.
return;
}

define( 'WIKIBASE_DATABASE_VERSION', '0.1' );

spl_autoload_register( function ( $className ) {
$className = ltrim( $className, '\\' );
$fileName = '';
$namespace = '';

if ( $lastNsPos = strripos( $className, '\\') ) {
$namespace = substr( $className, 0, $lastNsPos );
$className = substr( $className, $lastNsPos + 1 );
$fileName = str_replace( '\\', '/', $namespace ) . '/';
}

$fileName .= str_replace( '_', '/', $className ) . '.php';

$namespaceSegments = explode( '\\', $namespace );

$inQueryEngineNamespace = count( $namespaceSegments ) > 1
&& $namespaceSegments[0] === 'Wikibase'
&& $namespaceSegments[1] === 'Database';
if ( !defined( 'WIKIBASE_DATABASE_VERSION' ) ) {
define( 'WIKIBASE_DATABASE_VERSION', '0.2 alpha' );

if ( $inQueryEngineNamespace ) {
$inTestNamespace = count( $namespaceSegments ) > 2 && $namespaceSegments[2] === 'Tests';

if ( !$inTestNamespace ) {
$pathParts = explode( '/', $fileName );
array_shift( $pathParts );
array_shift( $pathParts );
$fileName = implode( '/', $pathParts );

require_once __DIR__ . '/src/' . $fileName;
}
if ( defined( 'MEDIAWIKI' ) ) {
call_user_func( function() {
require_once __DIR__ . '/WikibaseDatabase.mw.php';
} );
}
} );

// @codeCoverageIgnoreStart
if ( defined( 'MEDIAWIKI' ) ) {
call_user_func( function() {
require_once __DIR__ . '/WikibaseDatabase.mw.php';
} );
}
// @codeCoverageIgnoreEnd
6 changes: 3 additions & 3 deletions composer.json
Expand Up @@ -28,10 +28,10 @@
"require": {
"php": ">=5.3.2"
},
"require-dev": {
"satooshi/php-coveralls": "dev-master"
},
"autoload": {
"classmap": [
"src"
],
"files" : [
"WikibaseDatabase.php"
]
Expand Down
8 changes: 5 additions & 3 deletions tests/bootstrap.php
Expand Up @@ -9,10 +9,12 @@
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/

if ( !is_readable( __DIR__ . '/../vendor/autoload.php' ) ) {
die( 'You need to install this package with Composer before you can run the tests' );
}

if ( !in_array( '--testsuite=WikibaseDatabaseStandalone', $GLOBALS['argv'] ) ) {
require_once( __DIR__ . '/evilMediaWikiBootstrap.php' );
}

require_once( __DIR__ . '/../WikibaseDatabase.php' );

require_once( __DIR__ . '/testLoader.php' );
require_once( __DIR__ . '/../vendor/autoload.php' );
41 changes: 0 additions & 41 deletions tests/testLoader.php

This file was deleted.

1 comment on commit 40513fa

@addshore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell this commit has broken WikibaseDatabase for me.....
Classes dont seem to get loaded when running tests...

Please sign in to comment.