diff options
| author | Brett Parson <brett@brett-parson.com> | 2026-08-21 13:55:37 -0500 |
|---|---|---|
| committer | Brett Parson <brett@brett-parson.com> | 2026-08-21 14:00:11 -0500 |
| commit | d039a5d62a9ac6ababae70d9d96422ca59f2b2d4 (patch) | |
| tree | f0db4750a571e8040a5da02cc7190079c0d62914 /tests/bootstrap.php | |
| parent | 0de77a6334cee1f6e15f7e0fd35602514560be33 (diff) | |
| download | miniroute-d039a5d62a9ac6ababae70d9d96422ca59f2b2d4.tar.gz miniroute-d039a5d62a9ac6ababae70d9d96422ca59f2b2d4.zip | |
Scaffold miniroute routing/middleware kernel
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; + } + } + }); +} |
