diff options
Diffstat (limited to 'tests/bootstrap.php')
| -rw-r--r-- | tests/bootstrap.php | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..f49f712 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,36 @@ +<?php + +declare(strict_types=1); + +/** + * Test bootstrap — registers a small PSR-4 autoloader so the library and its + * test fixtures can be loaded without requiring a Composer install. If + * vendor/autoload.php exists (Composer installed), prefer it. + */ +$vendorAutoload = dirname(__DIR__) . '/vendor/autoload.php'; + +if (is_file($vendorAutoload)) { + require $vendorAutoload; +} else { + spl_autoload_register(static function (string $class): void { + $prefixes = [ + 'BrettParson\\MiniRoute\\Tests\\' => __DIR__ . '/', + 'BrettParson\\MiniRoute\\' => dirname(__DIR__) . '/src/', + ]; + + foreach ($prefixes as $prefix => $baseDir) { + if (!str_starts_with($class, $prefix)) { + continue; + } + + $relative = substr($class, strlen($prefix)); + $file = $baseDir . str_replace('\\', '/', $relative) . '.php'; + + if (is_file($file)) { + require $file; + + return; + } + } + }); +} |
