From 3482ddf3b66eec3aa824b4b897f0d0d3df340bdb Mon Sep 17 00:00:00 2001 From: "Paul M. Jones" Date: Thu, 4 Sep 2014 16:07:20 -0500 Subject: [PATCH] update testing structure and readme --- .gitignore | 4 -- .travis.yml | 6 +- README.md | 5 +- autoload.php | 66 +++++++++++-------- tests/{ => unit}/bootstrap.php | 2 +- tests/unit/phpunit.sh | 2 + tests/{ => unit}/phpunit.xml | 0 .../src/AbstractExtendedPdoTest.php | 0 .../{ => unit}/src/ConnectionLocatorTest.php | 0 tests/{ => unit}/src/DecoratedPdoTest.php | 0 tests/{ => unit}/src/ExtendedPdoTest.php | 0 tests/{ => unit}/src/FakeObject.php | 0 tests/{ => unit}/src/PdoDependent.php | 0 tests/{ => unit}/src/ProfilerTest.php | 0 14 files changed, 48 insertions(+), 37 deletions(-) delete mode 100644 .gitignore rename tests/{ => unit}/bootstrap.php (84%) create mode 100755 tests/unit/phpunit.sh rename tests/{ => unit}/phpunit.xml (100%) rename tests/{ => unit}/src/AbstractExtendedPdoTest.php (100%) rename tests/{ => unit}/src/ConnectionLocatorTest.php (100%) rename tests/{ => unit}/src/DecoratedPdoTest.php (100%) rename tests/{ => unit}/src/ExtendedPdoTest.php (100%) rename tests/{ => unit}/src/FakeObject.php (100%) rename tests/{ => unit}/src/PdoDependent.php (100%) rename tests/{ => unit}/src/ProfilerTest.php (100%) diff --git a/.gitignore b/.gitignore deleted file mode 100644 index ddea57b4..00000000 --- a/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -tests/tmp -tests/globals.php -/nbproject/ -/.idea/ diff --git a/.travis.yml b/.travis.yml index 42d94911..fad7c255 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,14 @@ language: php -env: - - DB=sqlite php: - 5.3 - 5.4 - 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 diff --git a/README.md b/README.md index b2ca0343..340a7070 100644 --- a/README.md +++ b/README.md @@ -57,12 +57,13 @@ Alternatively, [download a release](https://github.com/auraphp/Aura.Sql/releases [![Code Coverage](https://scrutinizer-ci.com/g/auraphp/Aura.Sql/badges/coverage.png?b=develop-2)](https://scrutinizer-ci.com/g/auraphp/Aura.Sql/) [![Build Status](https://travis-ci.org/auraphp/Aura.Sql.png?branch=develop-2)](https://travis-ci.org/auraphp/Aura.Sql) -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 diff --git a/autoload.php b/autoload.php index 485acb91..2e87a71c 100644 --- a/autoload.php +++ b/autoload.php @@ -1,33 +1,45 @@ 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; + } } } + }); diff --git a/tests/bootstrap.php b/tests/unit/bootstrap.php similarity index 84% rename from tests/bootstrap.php rename to tests/unit/bootstrap.php index 298b50d4..e142b596 100644 --- a/tests/bootstrap.php +++ b/tests/unit/bootstrap.php @@ -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')) { diff --git a/tests/unit/phpunit.sh b/tests/unit/phpunit.sh new file mode 100755 index 00000000..aae18c29 --- /dev/null +++ b/tests/unit/phpunit.sh @@ -0,0 +1,2 @@ +phpunit $@ +exit $? diff --git a/tests/phpunit.xml b/tests/unit/phpunit.xml similarity index 100% rename from tests/phpunit.xml rename to tests/unit/phpunit.xml diff --git a/tests/src/AbstractExtendedPdoTest.php b/tests/unit/src/AbstractExtendedPdoTest.php similarity index 100% rename from tests/src/AbstractExtendedPdoTest.php rename to tests/unit/src/AbstractExtendedPdoTest.php diff --git a/tests/src/ConnectionLocatorTest.php b/tests/unit/src/ConnectionLocatorTest.php similarity index 100% rename from tests/src/ConnectionLocatorTest.php rename to tests/unit/src/ConnectionLocatorTest.php diff --git a/tests/src/DecoratedPdoTest.php b/tests/unit/src/DecoratedPdoTest.php similarity index 100% rename from tests/src/DecoratedPdoTest.php rename to tests/unit/src/DecoratedPdoTest.php diff --git a/tests/src/ExtendedPdoTest.php b/tests/unit/src/ExtendedPdoTest.php similarity index 100% rename from tests/src/ExtendedPdoTest.php rename to tests/unit/src/ExtendedPdoTest.php diff --git a/tests/src/FakeObject.php b/tests/unit/src/FakeObject.php similarity index 100% rename from tests/src/FakeObject.php rename to tests/unit/src/FakeObject.php diff --git a/tests/src/PdoDependent.php b/tests/unit/src/PdoDependent.php similarity index 100% rename from tests/src/PdoDependent.php rename to tests/unit/src/PdoDependent.php diff --git a/tests/src/ProfilerTest.php b/tests/unit/src/ProfilerTest.php similarity index 100% rename from tests/src/ProfilerTest.php rename to tests/unit/src/ProfilerTest.php