|
1 |
| -<?php |
| 1 | +<?php declare(strict_types=1); |
2 | 2 | /**
|
3 |
| - * phpunit |
| 3 | + * phpunit --bootstrap tests/boot.php tests |
4 | 4 | */
|
5 | 5 |
|
6 |
| -error_reporting(E_ALL); |
7 |
| -ini_set('display_errors', 'On'); |
| 6 | +error_reporting(E_ALL | E_STRICT); |
8 | 7 | date_default_timezone_set('Asia/Shanghai');
|
9 | 8 |
|
10 |
| -spl_autoload_register(static function ($class) { |
11 |
| - $file = null; |
| 9 | +$libDir = dirname(__DIR__); |
| 10 | +$npMap = [ |
| 11 | + 'Toolkit\\FsUtil\\Example\\' => $libDir . '/example/', |
| 12 | + 'Toolkit\\FsUtilTest\\' => $libDir . '/test/', |
| 13 | + 'Toolkit\\FsUtil\\' => $libDir . '/src/', |
| 14 | +]; |
12 | 15 |
|
13 |
| - if (0 === strpos($class, 'Toolkit\FsUtil\Example\\')) { |
14 |
| - $path = str_replace('\\', '/', substr($class, strlen('Toolkit\FsUtil\Example\\'))); |
15 |
| - $file = dirname(__DIR__) . "/example/{$path}.php"; |
16 |
| - } elseif (0 === strpos($class, 'Toolkit\FsUtilTest\\')) { |
17 |
| - $path = str_replace('\\', '/', substr($class, strlen('Toolkit\FsUtilTest\\'))); |
18 |
| - $file = __DIR__ . "/{$path}.php"; |
19 |
| - } elseif (0 === strpos($class, 'Toolkit\FsUtil\\')) { |
20 |
| - $path = str_replace('\\', '/', substr($class, strlen('Toolkit\FsUtil\\'))); |
21 |
| - $file = dirname(__DIR__) . "/src/{$path}.php"; |
22 |
| - } |
| 16 | +spl_autoload_register(static function ($class) use ($npMap) { |
| 17 | + foreach ($npMap as $np => $dir) { |
| 18 | + $file = $dir . str_replace('\\', '/', substr($class, strlen($np))) . '.php'; |
23 | 19 |
|
24 |
| - if ($file && is_file($file)) { |
25 |
| - include $file; |
| 20 | + if (file_exists($file)) { |
| 21 | + include $file; |
| 22 | + } |
26 | 23 | }
|
27 | 24 | });
|
28 | 25 |
|
|
31 | 28 | } elseif (is_file(dirname(__DIR__) . '/vendor/autoload.php')) {
|
32 | 29 | require dirname(__DIR__) . '/vendor/autoload.php';
|
33 | 30 | }
|
34 |
| - |
0 commit comments