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 0412cae commit 7f9a1b6
Show file tree
Hide file tree
Showing 53 changed files with 119 additions and 29 deletions.
6 changes: 2 additions & 4 deletions .gitignore
@@ -1,4 +1,2 @@
/tests/tmp
/vendor
/build
/composer.lock
/tests/container/vendor
/tests/container/composer.*
4 changes: 3 additions & 1 deletion .travis.yml
Expand Up @@ -3,8 +3,10 @@ php:
- 5.4
- 5.5
- 5.6
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
10 changes: 8 additions & 2 deletions README.md
Expand Up @@ -21,12 +21,18 @@ You don't need to run composer install in order to run the test suite.
[![Code Coverage](https://scrutinizer-ci.com/g/auraphp/Aura.Filter/badges/coverage.png?b=develop-2)](https://scrutinizer-ci.com/g/auraphp/Aura.Filter/)
[![Build Status](https://travis-ci.org/auraphp/Aura.Filter.png?branch=develop-2)](https://travis-ci.org/auraphp/Aura.Filter)

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/

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

This comment has been minimized.

Copy link
@harikt

harikt Sep 5, 2014

Member

@pmjones why do we want the users to run the phpunit.sh from unit ? Can't they just run the phpunit itself ?


[Aura.Di]: https://github.com/auraphp/Aura.Di
[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
55 changes: 34 additions & 21 deletions autoload.php
@@ -1,32 +1,45 @@
<?php
spl_autoload_register(function ($class) {

// what namespace prefix should be recognized?
$prefix = 'Aura\Filter\\';
// the package namespace
$ns = 'Aura\Filter';

// does the requested class match the namespace prefix?
$prefix_len = strlen($prefix);
if (substr($class, 0, $prefix_len) !== $prefix) {
return;
}
// 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 prefixes
foreach ($prefixes as $prefix => $dirs) {

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

// a partial filename
$part = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
// strip the prefix off the class
$class = substr($class, $prefix_len);

// directories where we can find classes
$dirs = array(
__DIR__ . DIRECTORY_SEPARATOR . 'src',
__DIR__ . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'src',
);
foreach ($dirs as $dir) {
$file = $dir . DIRECTORY_SEPARATOR . $part;
if (is_readable($file)) {
require $file;
// a partial filename
$part = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';

return;
// 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;
}
}
}

});
15 changes: 15 additions & 0 deletions tests/container/bootstrap.php
@@ -0,0 +1,15 @@
<?php
// turn on all errors
error_reporting(E_ALL);

// composer autoloader
$composer_autoload = __DIR__ . "/vendor/autoload.php";
if (! is_readable($composer_autoload)) {
echo "Did not find 'vendor/autoload.php'." . PHP_EOL;
echo "Try ./phpunit.sh instead of phpunit." . PHP_EOL;
exit(1);
}
require $composer_autoload;

// package autoloader
require dirname(dirname(__DIR__)) . '/autoload.php';
8 changes: 8 additions & 0 deletions tests/container/phpunit.sh
@@ -0,0 +1,8 @@
if [ -d vendor ]
then
composer update
else
composer require aura/di:dev-develop-2
fi
phpunit $@
exit $?
7 changes: 7 additions & 0 deletions tests/container/phpunit.xml
@@ -0,0 +1,7 @@
<phpunit bootstrap="./bootstrap.php">
<testsuites>
<testsuite>
<directory>./src</directory>
</testsuite>
</testsuites>
</phpunit>
23 changes: 23 additions & 0 deletions tests/container/src/CommonTest.php
@@ -0,0 +1,23 @@
<?php
namespace Aura\Filter\_Config;

use Aura\Di\ContainerAssertionsTrait;

class CommonTest extends \PHPUnit_Framework_TestCase
{
use ContainerAssertionsTrait;

public function setUp()
{
$this->setUpContainer(array(
'Aura\Filter\_Config\Common',
));
}

public function test()
{
$this->assertNewInstance('Aura\Filter\Rule\Any');
$this->assertNewInstance('Aura\Filter\RuleCollection');
$this->assertNewInstance('Aura\Filter\RuleLocator');
}
}
16 changes: 16 additions & 0 deletions tests/unit/bootstrap.php
@@ -0,0 +1,16 @@
<?php
// turn on all errors
error_reporting(E_ALL);

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

// default globals
if (is_readable(__DIR__ . '/globals.dist.php')) {
require __DIR__ . '/globals.dist.php';
}

// override globals
if (is_readable(__DIR__ . '/globals.php')) {
require __DIR__ . '/globals.php';
}
2 changes: 2 additions & 0 deletions tests/unit/phpunit.sh
@@ -0,0 +1,2 @@
phpunit $@
exit $?
2 changes: 1 addition & 1 deletion tests/phpunit.xml → tests/unit/phpunit.xml
@@ -1,4 +1,4 @@
<phpunit bootstrap="./../autoload.php">
<phpunit bootstrap="./bootstrap.php">
<testsuites>
<testsuite>
<directory>./src/</directory>
Expand Down
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.
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 7f9a1b6

Please sign in to comment.