Permalink
Browse files

give skelgen its own bootstrap

  • Loading branch information...
1 parent b59833a commit 922aaa5f7b5e908a4fd5d2c0ff0c1ee93b24ac3e @pmjones pmjones committed Nov 21, 2012
Showing with 34 additions and 2 deletions.
  1. +2 −2 cli/make-test
  2. +32 −0 scripts/skelgen-bootstrap.php
View
@@ -65,8 +65,8 @@ $test_class = $src_class . 'Test';
// the bootstrap file for loading classes as needed
$bootstrap = dirname(__DIR__) . DIRECTORY_SEPARATOR
- . 'tests' . DIRECTORY_SEPARATOR
- . 'bootstrap.php';
+ . 'scripts' . DIRECTORY_SEPARATOR
+ . 'skelgen-bootstrap.php';
// create and run the phpunit-skelgen command
$cmd = "phpunit-skelgen --bootstrap $bootstrap --test -- $src_class $src_file $test_class $test_file";
@@ -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.