Skip to content

Commit

Permalink
Updated autoloader to support test cases, and bootstrapper to support…
Browse files Browse the repository at this point in the history
… composer autoloader
  • Loading branch information
tedivm committed Dec 5, 2013
1 parent e6eb65f commit bcf57ce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
14 changes: 10 additions & 4 deletions autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@
* file that was distributed with this source code.
*/

spl_autoload_register(function($class)
{
$file = __DIR__.'/src/'.strtr($class, '\\', '/').'.php';
spl_autoload_register(function($class) {
$base = '/src/';

if (strpos($class, 'Fetch\Test') === 0) {
$base = '/tests/';
}

$file = __DIR__.$base.strtr($class, '\\', '/').'.php';
if (file_exists($file)) {
require $file;

return true;
}
});
});
29 changes: 14 additions & 15 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@

error_reporting(-1);

spl_autoload_register(function($class) {
if (0 === strpos($class, 'Fetch\\Test\\')) {
$file = __DIR__ . '/../tests/' . str_replace('\\', '/', $class) . '.php';
if (file_exists($file)) {
require_once $file;
return true;
}
} elseif (0 === strpos($class, 'Fetch\\')) {
$file = __DIR__ . '/../src/' . str_replace('\\', '/', $class) . '.php';
if (file_exists($file)) {
require_once $file;
return true;
}
}
});
$filename = __DIR__ .'/../vendor/autoload.php';

if (!file_exists($filename)) {
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" . PHP_EOL;
echo " You need to execute `composer install` before running the tests. " . PHP_EOL;
echo " Vendors are required for complete test execution. " . PHP_EOL;
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" . PHP_EOL . PHP_EOL;
$filename = __DIR__ .'/../autoload.php';
require_once $filename;
}else{
$loader = require_once $filename;
$loader->add('Fetch\\Test', __DIR__);
}

0 comments on commit bcf57ce

Please sign in to comment.