Skip to content

Commit b3d347d

Browse files
committed
Better autoloading for PHPUnit
1 parent 7dcbe38 commit b3d347d

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
},
2121
"autoload": {
2222
"psr-0": {
23-
"PHPFUI": "src/",
24-
"badPHP": "tests/"
23+
"PHPFUI": "src/"
2524
}
2625
}
2726
}

tests/bootstrap.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
<?php
2-
32
error_reporting(E_ALL);
43

5-
$vendorDir = __DIR__ . '/../../vendor';
4+
function classNameExists(string $className) : string
5+
{
6+
$path = __DIR__ . "/{$className}.php";
7+
$path = str_replace('\\', '/', $path);
8+
return file_exists($path) ? $path : '';
9+
}
10+
11+
function autoload($className) : void
12+
{
13+
$path = classNameExists($className);
14+
15+
if ($path)
16+
{
17+
/** @noinspection PhpIncludeInspection */
18+
include $path;
19+
}
20+
}
21+
spl_autoload_register('autoload');
622

7-
if (file_exists($file = $vendorDir . '/autoload.php')) {
8-
require_once $file;
9-
} elseif (file_exists($file = './vendor/autoload.php')) {
10-
require_once $file;
11-
} else {
12-
throw new \RuntimeException('Composer autoload file not found');
13-
}
23+
require_once 'vendor/autoload.php';

0 commit comments

Comments
 (0)