Skip to content

Commit

Permalink
give skelgen its own bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul M. Jones committed Nov 21, 2012
1 parent b59833a commit 922aaa5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cli/make-test
Expand Up @@ -65,8 +65,8 @@ $test_class = $src_class . 'Test';


// the bootstrap file for loading classes as needed // the bootstrap file for loading classes as needed
$bootstrap = dirname(__DIR__) . DIRECTORY_SEPARATOR $bootstrap = dirname(__DIR__) . DIRECTORY_SEPARATOR
. 'tests' . DIRECTORY_SEPARATOR . 'scripts' . DIRECTORY_SEPARATOR
. 'bootstrap.php'; . 'skelgen-bootstrap.php';


// create and run the phpunit-skelgen command // create and run the phpunit-skelgen command
$cmd = "phpunit-skelgen --bootstrap $bootstrap --test -- $src_class $src_file $test_class $test_file"; $cmd = "phpunit-skelgen --bootstrap $bootstrap --test -- $src_class $src_file $test_class $test_file";
Expand Down
32 changes: 32 additions & 0 deletions scripts/skelgen-bootstrap.php
@@ -0,0 +1,32 @@
<?php
spl_autoload_register(function($class) {

// split the class into namespace parts
$parts = explode('\\', $class);
if (count($parts) == 1) {
return;
}

// the eventual filename
$file = implode(DIRECTORY_SEPARATOR, $parts) . '.php';

// the package dir for the class
$dir = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . "{$parts[0]}.{$parts[1]}";

// look for a package src file
$tmp = $dir . DIRECTORY_SEPARATOR . 'src'. DIRECTORY_SEPARATOR . $file;
if (is_readable($tmp)) {
require_once $tmp;
return;
}

// look in the include-path
$dirs = explode(PATH_SEPARATOR, get_include_path());
foreach ($dirs as $dir) {
$tmp = $dir . DIRECTORY_SEPARATOR . $file;
if (is_readable($tmp)) {
require_once $tmp;
return;
}
}
});

0 comments on commit 922aaa5

Please sign in to comment.