Skip to content

Commit

Permalink
Refactor autolading
Browse files Browse the repository at this point in the history
Tidy up logic a bit.
  • Loading branch information
tomkyle committed Aug 11, 2024
1 parent d86f39b commit d5ae6e5
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions bin/frt
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@ use tomkyle\FindRunTest\SymfonyConsoleWrapper;
use tomkyle\FindRunTest\PhpUnitRunner;

if (isset($_composer_autoload_path)) {
require $_composer_autoload_path;
$root_path = dirname(realpath($_composer_autoload_path), 2);
$autoload = realpath($_composer_autoload_path);
} else {
$possible_autoloaders = array_map(static fn($rp) => $rp . '/vendor/autoload.php', [ dirname(__DIR__, 4), dirname(__DIR__,2), dirname(__DIR__)]);
$existing_autoloaders = array_filter($possible_autoloaders, static fn($rp) => is_file($rp));
if (empty($existing_autoloaders)) {
fwrite(STDERR, "Could not locate autoloader.\n");
exit(1);
}
$possible_autoloaders = array_map(static fn($path) => $path . '/vendor/autoload.php', [
dirname(__DIR__, 2),
dirname(__DIR__, 4)
]);
$existing_autoloaders = array_filter($possible_autoloaders, static fn($path) => is_file($path));
$autoload = current($existing_autoloaders);
require $autoload;
$root_path = dirname($autoload, 2);
}

if (empty($autoload)) {
fwrite(STDERR, "Could not locate autoloader.\n");
exit(1);
}

require $autoload;
$root_path = dirname($autoload, 2);
$tests_dir = $root_path . '/tests';

(new SingleCommandApplication())
Expand Down

0 comments on commit d5ae6e5

Please sign in to comment.