Skip to content

Commit

Permalink
major reorg of testing dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul M. Jones committed Sep 3, 2014
1 parent 63d1abc commit 31f7e8a
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 31 deletions.
1 change: 0 additions & 1 deletion .gitignore

This file was deleted.

11 changes: 9 additions & 2 deletions README.md
Expand Up @@ -22,12 +22,19 @@ Alternatively, [download a release](https://github.com/auraphp/Aura.Autoload/rel
[![Code Coverage](https://scrutinizer-ci.com/g/auraphp/Aura.Autoload/badges/coverage.png?b=develop-2)](https://scrutinizer-ci.com/g/auraphp/Aura.Autoload/)
[![Build Status](https://travis-ci.org/auraphp/Aura.Autoload.png?branch=develop-2)](https://travis-ci.org/auraphp/Aura.Autoload)

To run the [PHPUnit][] tests at the command line, go to the _tests_ directory and issue `phpunit`.
To run the unit tests at the command line, go to the _tests/unit_ directory and issue `./phpunit.sh`. (This requires [PHPUnit][] to be available as `phpunit`.)

To run the unit tests at the command line, go to the _tests/unit_ directory and issue `./phpunit.sh`. (This requires [PHPUnit][] to be available as `phpunit`.)

To run the [Aura.Di][] container configuration tests at the command line, go to the _tests/container_ directory and issue `./phpunit.sh`. (This requires [PHPUnit][] to be available as `phpunit` and [Composer][] to be available as `composer`.)

[Aura.Di]: https://github.com/auraphp/Aura.Di
[PHPUnit]: http://phpunit.de/manual/
[Composer]: http://getcomposer.org/

This library attempts to comply with [PSR-1][], [PSR-2][], and [PSR-4][]. If
you notice compliance oversights, please send a patch via pull request.

[PHPUnit]: http://phpunit.de/manual/
[PSR-1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md
[PSR-2]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
[PSR-4]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md
Expand Down
66 changes: 39 additions & 27 deletions autoload.php
@@ -1,33 +1,45 @@
<?php
spl_autoload_register(function ($class) {

// what namespace prefix should be recognized?
$prefix = 'Aura\Autoload\\';

// does the requested class match the namespace prefix?
$prefix_len = strlen($prefix);
if (substr($class, 0, $prefix_len) !== $prefix) {
return;
}

// strip the prefix off the class
$class = substr($class, $prefix_len);

// a partial filename
$part = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';

// directories where we can find classes
$dirs = array(
__DIR__ . DIRECTORY_SEPARATOR . 'src',
__DIR__ . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'src',

// the package namespace
$ns = 'Aura\Autoload';

// what prefixes should be recognized?
$prefixes = array(
"{$ns}\_Config\\" => array(
__DIR__ . '/config',
__DIR__ . '/tests/container/src',
),
"{$ns}\\" => array(
__DIR__ . '/src',
__DIR__ . '/tests/unit/src',
),
);

// go through the directories to find classes
foreach ($dirs as $dir) {
$file = $dir . DIRECTORY_SEPARATOR . $part;
if (is_readable($file)) {
require $file;
return;

// go through the prefixes
foreach ($prefixes as $prefix => $dirs) {

// does the requested class match the namespace prefix?
$prefix_len = strlen($prefix);
if (substr($class, 0, $prefix_len) !== $prefix) {
continue;
}

// strip the prefix off the class
$class = substr($class, $prefix_len);

// a partial filename
$part = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';

// go through the directories to find classes
foreach ($dirs as $dir) {
$dir = str_replace('/', DIRECTORY_SEPARATOR, $dir);
$file = $dir . DIRECTORY_SEPARATOR . $part;
if (is_readable($file)) {
require $file;
return;
}
}
}

});
2 changes: 1 addition & 1 deletion tests/bootstrap.php → tests/unit/bootstrap.php
Expand Up @@ -3,7 +3,7 @@
error_reporting(E_ALL);

// autoloader
require dirname(__DIR__) . '/autoload.php';
require dirname(dirname(__DIR__)) . '/autoload.php';

// default globals
if (is_readable(__DIR__ . '/globals.dist.php')) {
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/phpunit.sh
@@ -0,0 +1,2 @@
phpunit $@
exit $?
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 31f7e8a

Please sign in to comment.