Skip to content

Commit 6775834

Browse files
committed
Add lib/autoload.php to allow manual (i.e. without composer) installation.
The custom autoloader created by this commit translates class names into filesystem locations by a simple rule: it replaces backslashes with frontslashes, and adds ".php" on the end. Two locations are searched for this class implementation file: first we check under lib/, then under test/. The existing test/bootstrap.php checked for vendor/autoload.php and would show an error to the user if it did not exist. Now that we have our own autoloader, we can just use that instead. So, test/bootstrap.php was removed, and phpunit.xml.dist was pointed at the new lib/autoload.php for its bootstrap code. Thanks to Artur Weigandt for the implementation of the autoloader.
1 parent 8a3a597 commit 6775834

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

lib/autoload.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/* An autoloader for Redmine\Foo classes. This should be require()d by
4+
* the user before attempting to instantiate any of the Redmine
5+
* classes.
6+
*/
7+
8+
spl_autoload_register(function ($class) {
9+
/* All of the classes have names like "Redmine\Foo", so we need to
10+
* replace the backslashes with frontslashes if we want the name
11+
* to map directly to a location in the filesystem.
12+
*/
13+
$class = str_replace('\\', '/', $class);
14+
15+
/* First, check under the current directory. It is important that
16+
* we look here first, so that we don't waste time searching for
17+
* test classes in the common case.
18+
*/
19+
$path = dirname(__FILE__) . '/' . $class . '.php';
20+
if (file_exists($path)){
21+
require_once($path);
22+
}
23+
24+
/* If we didn't find what we're looking for already, maybe it's
25+
* a test class?
26+
*/
27+
$path = dirname(__FILE__) . '/../test/' . $class . '.php';
28+
if (file_exists($path)){
29+
require_once($path);
30+
}
31+
});

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
processIsolation="false"
1010
stopOnFailure="false"
1111
syntaxCheck="false"
12-
bootstrap="test/bootstrap.php"
12+
bootstrap="lib/autoload.php"
1313
>
1414
<testsuites>
1515
<testsuite name="php-redmine-api Test Suite">

test/bootstrap.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)