Skip to content

Commit

Permalink
update testing structure and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul M. Jones committed Sep 4, 2014
1 parent 905b183 commit c6b4950
Show file tree
Hide file tree
Showing 28 changed files with 48 additions and 32 deletions.
1 change: 0 additions & 1 deletion .gitignore

This file was deleted.

4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ php:
- 5.5
- 5.6
- hhvm
before_script:
- cd tests/unit
script:
- phpunit -c tests/ --coverage-clover=coverage.clover
- ./phpunit.sh --coverage-clover=coverage.clover
after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ Alternatively, [download a release](https://github.com/auraphp/Aura.Di/releases)
[![Code Coverage](https://scrutinizer-ci.com/g/auraphp/Aura.Di/badges/coverage.png?b=develop-2)](https://scrutinizer-ci.com/g/auraphp/Aura.Di/)
[![Build Status](https://travis-ci.org/auraphp/Aura.Di.png?branch=develop-2)](https://travis-ci.org/auraphp/Aura.Di)

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`.)

[PHPUnit]: http://phpunit.de/manual/

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
Original file line number Diff line number Diff line change
@@ -1,33 +1,45 @@
<?php
spl_autoload_register(function ($class) {

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

// 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\Di';

// 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit c6b4950

Please sign in to comment.