From 7f9a1b644d5c35c8b1dde358e1f3b42a589230a1 Mon Sep 17 00:00:00 2001 From: "Paul M. Jones" Date: Thu, 4 Sep 2014 15:20:21 -0500 Subject: [PATCH] update testing structure and readme --- .gitignore | 6 +- .travis.yml | 4 +- README.md | 10 +++- autoload.php | 55 ++++++++++++------- tests/container/bootstrap.php | 15 +++++ tests/container/phpunit.sh | 8 +++ tests/container/phpunit.xml | 7 +++ tests/container/src/CommonTest.php | 23 ++++++++ tests/unit/bootstrap.php | 16 ++++++ tests/unit/phpunit.sh | 2 + tests/{ => unit}/phpunit.xml | 2 +- tests/{ => unit}/src/AbstractRuleTest.php | 0 tests/{ => unit}/src/Rule/AllTest.php | 0 tests/{ => unit}/src/Rule/AlnumTest.php | 0 tests/{ => unit}/src/Rule/AlphaTest.php | 0 tests/{ => unit}/src/Rule/AnyTest.php | 0 tests/{ => unit}/src/Rule/BetweenTest.php | 0 tests/{ => unit}/src/Rule/BlankTest.php | 0 tests/{ => unit}/src/Rule/BoolTest.php | 0 tests/{ => unit}/src/Rule/ClosureTest.php | 0 tests/{ => unit}/src/Rule/CreditCardTest.php | 0 tests/{ => unit}/src/Rule/DateTimeTest.php | 0 tests/{ => unit}/src/Rule/EmailTest.php | 0 .../{ => unit}/src/Rule/EqualToFieldTest.php | 0 .../{ => unit}/src/Rule/EqualToValueTest.php | 0 tests/{ => unit}/src/Rule/FloatTest.php | 0 tests/{ => unit}/src/Rule/Hex.php | 0 tests/{ => unit}/src/Rule/HexTest.php | 0 tests/{ => unit}/src/Rule/InKeysTest.php | 0 tests/{ => unit}/src/Rule/InValuesTest.php | 0 tests/{ => unit}/src/Rule/IntTest.php | 0 tests/{ => unit}/src/Rule/Ipv4Test.php | 0 tests/{ => unit}/src/Rule/IsbnTest.php | 0 tests/{ => unit}/src/Rule/LocaleTest.php | 0 tests/{ => unit}/src/Rule/MaxTest.php | 0 tests/{ => unit}/src/Rule/MethodTest.php | 0 tests/{ => unit}/src/Rule/MinTest.php | 0 tests/{ => unit}/src/Rule/MockUpload.php | 0 tests/{ => unit}/src/Rule/MockValue.php | 0 tests/{ => unit}/src/Rule/RegexTest.php | 0 .../src/Rule/StrictEqualToFieldTest.php | 0 .../src/Rule/StrictEqualToValueTest.php | 0 tests/{ => unit}/src/Rule/StringTest.php | 0 .../{ => unit}/src/Rule/StrlenBetweenTest.php | 0 tests/{ => unit}/src/Rule/StrlenMaxTest.php | 0 tests/{ => unit}/src/Rule/StrlenMinTest.php | 0 tests/{ => unit}/src/Rule/StrlenTest.php | 0 tests/{ => unit}/src/Rule/TrimTest.php | 0 tests/{ => unit}/src/Rule/UploadTest.php | 0 tests/{ => unit}/src/Rule/UrlTest.php | 0 tests/{ => unit}/src/Rule/WordTest.php | 0 tests/{ => unit}/src/RuleCollectionTest.php | 0 tests/{ => unit}/src/RuleLocatorTest.php | 0 53 files changed, 119 insertions(+), 29 deletions(-) create mode 100644 tests/container/bootstrap.php create mode 100755 tests/container/phpunit.sh create mode 100644 tests/container/phpunit.xml create mode 100644 tests/container/src/CommonTest.php create mode 100644 tests/unit/bootstrap.php create mode 100755 tests/unit/phpunit.sh rename tests/{ => unit}/phpunit.xml (76%) rename tests/{ => unit}/src/AbstractRuleTest.php (100%) rename tests/{ => unit}/src/Rule/AllTest.php (100%) rename tests/{ => unit}/src/Rule/AlnumTest.php (100%) rename tests/{ => unit}/src/Rule/AlphaTest.php (100%) rename tests/{ => unit}/src/Rule/AnyTest.php (100%) rename tests/{ => unit}/src/Rule/BetweenTest.php (100%) rename tests/{ => unit}/src/Rule/BlankTest.php (100%) rename tests/{ => unit}/src/Rule/BoolTest.php (100%) rename tests/{ => unit}/src/Rule/ClosureTest.php (100%) rename tests/{ => unit}/src/Rule/CreditCardTest.php (100%) rename tests/{ => unit}/src/Rule/DateTimeTest.php (100%) rename tests/{ => unit}/src/Rule/EmailTest.php (100%) rename tests/{ => unit}/src/Rule/EqualToFieldTest.php (100%) rename tests/{ => unit}/src/Rule/EqualToValueTest.php (100%) rename tests/{ => unit}/src/Rule/FloatTest.php (100%) rename tests/{ => unit}/src/Rule/Hex.php (100%) rename tests/{ => unit}/src/Rule/HexTest.php (100%) rename tests/{ => unit}/src/Rule/InKeysTest.php (100%) rename tests/{ => unit}/src/Rule/InValuesTest.php (100%) rename tests/{ => unit}/src/Rule/IntTest.php (100%) rename tests/{ => unit}/src/Rule/Ipv4Test.php (100%) rename tests/{ => unit}/src/Rule/IsbnTest.php (100%) rename tests/{ => unit}/src/Rule/LocaleTest.php (100%) rename tests/{ => unit}/src/Rule/MaxTest.php (100%) rename tests/{ => unit}/src/Rule/MethodTest.php (100%) rename tests/{ => unit}/src/Rule/MinTest.php (100%) rename tests/{ => unit}/src/Rule/MockUpload.php (100%) rename tests/{ => unit}/src/Rule/MockValue.php (100%) rename tests/{ => unit}/src/Rule/RegexTest.php (100%) rename tests/{ => unit}/src/Rule/StrictEqualToFieldTest.php (100%) rename tests/{ => unit}/src/Rule/StrictEqualToValueTest.php (100%) rename tests/{ => unit}/src/Rule/StringTest.php (100%) rename tests/{ => unit}/src/Rule/StrlenBetweenTest.php (100%) rename tests/{ => unit}/src/Rule/StrlenMaxTest.php (100%) rename tests/{ => unit}/src/Rule/StrlenMinTest.php (100%) rename tests/{ => unit}/src/Rule/StrlenTest.php (100%) rename tests/{ => unit}/src/Rule/TrimTest.php (100%) rename tests/{ => unit}/src/Rule/UploadTest.php (100%) rename tests/{ => unit}/src/Rule/UrlTest.php (100%) rename tests/{ => unit}/src/Rule/WordTest.php (100%) rename tests/{ => unit}/src/RuleCollectionTest.php (100%) rename tests/{ => unit}/src/RuleLocatorTest.php (100%) diff --git a/.gitignore b/.gitignore index 1b44d290..d2dde8a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ -/tests/tmp -/vendor -/build -/composer.lock +/tests/container/vendor +/tests/container/composer.* diff --git a/.travis.yml b/.travis.yml index b2d48ae0..86037fdc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/README.md b/README.md index 3e120b55..730fd84a 100644 --- a/README.md +++ b/README.md @@ -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`.) + +[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 diff --git a/autoload.php b/autoload.php index 03f89f2d..e0a1bc65 100644 --- a/autoload.php +++ b/autoload.php @@ -1,32 +1,45 @@ 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; + } } } + }); diff --git a/tests/container/bootstrap.php b/tests/container/bootstrap.php new file mode 100644 index 00000000..241d8f36 --- /dev/null +++ b/tests/container/bootstrap.php @@ -0,0 +1,15 @@ + + + + ./src + + + diff --git a/tests/container/src/CommonTest.php b/tests/container/src/CommonTest.php new file mode 100644 index 00000000..f017e90d --- /dev/null +++ b/tests/container/src/CommonTest.php @@ -0,0 +1,23 @@ +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'); + } +} diff --git a/tests/unit/bootstrap.php b/tests/unit/bootstrap.php new file mode 100644 index 00000000..e142b596 --- /dev/null +++ b/tests/unit/bootstrap.php @@ -0,0 +1,16 @@ + + ./src/ diff --git a/tests/src/AbstractRuleTest.php b/tests/unit/src/AbstractRuleTest.php similarity index 100% rename from tests/src/AbstractRuleTest.php rename to tests/unit/src/AbstractRuleTest.php diff --git a/tests/src/Rule/AllTest.php b/tests/unit/src/Rule/AllTest.php similarity index 100% rename from tests/src/Rule/AllTest.php rename to tests/unit/src/Rule/AllTest.php diff --git a/tests/src/Rule/AlnumTest.php b/tests/unit/src/Rule/AlnumTest.php similarity index 100% rename from tests/src/Rule/AlnumTest.php rename to tests/unit/src/Rule/AlnumTest.php diff --git a/tests/src/Rule/AlphaTest.php b/tests/unit/src/Rule/AlphaTest.php similarity index 100% rename from tests/src/Rule/AlphaTest.php rename to tests/unit/src/Rule/AlphaTest.php diff --git a/tests/src/Rule/AnyTest.php b/tests/unit/src/Rule/AnyTest.php similarity index 100% rename from tests/src/Rule/AnyTest.php rename to tests/unit/src/Rule/AnyTest.php diff --git a/tests/src/Rule/BetweenTest.php b/tests/unit/src/Rule/BetweenTest.php similarity index 100% rename from tests/src/Rule/BetweenTest.php rename to tests/unit/src/Rule/BetweenTest.php diff --git a/tests/src/Rule/BlankTest.php b/tests/unit/src/Rule/BlankTest.php similarity index 100% rename from tests/src/Rule/BlankTest.php rename to tests/unit/src/Rule/BlankTest.php diff --git a/tests/src/Rule/BoolTest.php b/tests/unit/src/Rule/BoolTest.php similarity index 100% rename from tests/src/Rule/BoolTest.php rename to tests/unit/src/Rule/BoolTest.php diff --git a/tests/src/Rule/ClosureTest.php b/tests/unit/src/Rule/ClosureTest.php similarity index 100% rename from tests/src/Rule/ClosureTest.php rename to tests/unit/src/Rule/ClosureTest.php diff --git a/tests/src/Rule/CreditCardTest.php b/tests/unit/src/Rule/CreditCardTest.php similarity index 100% rename from tests/src/Rule/CreditCardTest.php rename to tests/unit/src/Rule/CreditCardTest.php diff --git a/tests/src/Rule/DateTimeTest.php b/tests/unit/src/Rule/DateTimeTest.php similarity index 100% rename from tests/src/Rule/DateTimeTest.php rename to tests/unit/src/Rule/DateTimeTest.php diff --git a/tests/src/Rule/EmailTest.php b/tests/unit/src/Rule/EmailTest.php similarity index 100% rename from tests/src/Rule/EmailTest.php rename to tests/unit/src/Rule/EmailTest.php diff --git a/tests/src/Rule/EqualToFieldTest.php b/tests/unit/src/Rule/EqualToFieldTest.php similarity index 100% rename from tests/src/Rule/EqualToFieldTest.php rename to tests/unit/src/Rule/EqualToFieldTest.php diff --git a/tests/src/Rule/EqualToValueTest.php b/tests/unit/src/Rule/EqualToValueTest.php similarity index 100% rename from tests/src/Rule/EqualToValueTest.php rename to tests/unit/src/Rule/EqualToValueTest.php diff --git a/tests/src/Rule/FloatTest.php b/tests/unit/src/Rule/FloatTest.php similarity index 100% rename from tests/src/Rule/FloatTest.php rename to tests/unit/src/Rule/FloatTest.php diff --git a/tests/src/Rule/Hex.php b/tests/unit/src/Rule/Hex.php similarity index 100% rename from tests/src/Rule/Hex.php rename to tests/unit/src/Rule/Hex.php diff --git a/tests/src/Rule/HexTest.php b/tests/unit/src/Rule/HexTest.php similarity index 100% rename from tests/src/Rule/HexTest.php rename to tests/unit/src/Rule/HexTest.php diff --git a/tests/src/Rule/InKeysTest.php b/tests/unit/src/Rule/InKeysTest.php similarity index 100% rename from tests/src/Rule/InKeysTest.php rename to tests/unit/src/Rule/InKeysTest.php diff --git a/tests/src/Rule/InValuesTest.php b/tests/unit/src/Rule/InValuesTest.php similarity index 100% rename from tests/src/Rule/InValuesTest.php rename to tests/unit/src/Rule/InValuesTest.php diff --git a/tests/src/Rule/IntTest.php b/tests/unit/src/Rule/IntTest.php similarity index 100% rename from tests/src/Rule/IntTest.php rename to tests/unit/src/Rule/IntTest.php diff --git a/tests/src/Rule/Ipv4Test.php b/tests/unit/src/Rule/Ipv4Test.php similarity index 100% rename from tests/src/Rule/Ipv4Test.php rename to tests/unit/src/Rule/Ipv4Test.php diff --git a/tests/src/Rule/IsbnTest.php b/tests/unit/src/Rule/IsbnTest.php similarity index 100% rename from tests/src/Rule/IsbnTest.php rename to tests/unit/src/Rule/IsbnTest.php diff --git a/tests/src/Rule/LocaleTest.php b/tests/unit/src/Rule/LocaleTest.php similarity index 100% rename from tests/src/Rule/LocaleTest.php rename to tests/unit/src/Rule/LocaleTest.php diff --git a/tests/src/Rule/MaxTest.php b/tests/unit/src/Rule/MaxTest.php similarity index 100% rename from tests/src/Rule/MaxTest.php rename to tests/unit/src/Rule/MaxTest.php diff --git a/tests/src/Rule/MethodTest.php b/tests/unit/src/Rule/MethodTest.php similarity index 100% rename from tests/src/Rule/MethodTest.php rename to tests/unit/src/Rule/MethodTest.php diff --git a/tests/src/Rule/MinTest.php b/tests/unit/src/Rule/MinTest.php similarity index 100% rename from tests/src/Rule/MinTest.php rename to tests/unit/src/Rule/MinTest.php diff --git a/tests/src/Rule/MockUpload.php b/tests/unit/src/Rule/MockUpload.php similarity index 100% rename from tests/src/Rule/MockUpload.php rename to tests/unit/src/Rule/MockUpload.php diff --git a/tests/src/Rule/MockValue.php b/tests/unit/src/Rule/MockValue.php similarity index 100% rename from tests/src/Rule/MockValue.php rename to tests/unit/src/Rule/MockValue.php diff --git a/tests/src/Rule/RegexTest.php b/tests/unit/src/Rule/RegexTest.php similarity index 100% rename from tests/src/Rule/RegexTest.php rename to tests/unit/src/Rule/RegexTest.php diff --git a/tests/src/Rule/StrictEqualToFieldTest.php b/tests/unit/src/Rule/StrictEqualToFieldTest.php similarity index 100% rename from tests/src/Rule/StrictEqualToFieldTest.php rename to tests/unit/src/Rule/StrictEqualToFieldTest.php diff --git a/tests/src/Rule/StrictEqualToValueTest.php b/tests/unit/src/Rule/StrictEqualToValueTest.php similarity index 100% rename from tests/src/Rule/StrictEqualToValueTest.php rename to tests/unit/src/Rule/StrictEqualToValueTest.php diff --git a/tests/src/Rule/StringTest.php b/tests/unit/src/Rule/StringTest.php similarity index 100% rename from tests/src/Rule/StringTest.php rename to tests/unit/src/Rule/StringTest.php diff --git a/tests/src/Rule/StrlenBetweenTest.php b/tests/unit/src/Rule/StrlenBetweenTest.php similarity index 100% rename from tests/src/Rule/StrlenBetweenTest.php rename to tests/unit/src/Rule/StrlenBetweenTest.php diff --git a/tests/src/Rule/StrlenMaxTest.php b/tests/unit/src/Rule/StrlenMaxTest.php similarity index 100% rename from tests/src/Rule/StrlenMaxTest.php rename to tests/unit/src/Rule/StrlenMaxTest.php diff --git a/tests/src/Rule/StrlenMinTest.php b/tests/unit/src/Rule/StrlenMinTest.php similarity index 100% rename from tests/src/Rule/StrlenMinTest.php rename to tests/unit/src/Rule/StrlenMinTest.php diff --git a/tests/src/Rule/StrlenTest.php b/tests/unit/src/Rule/StrlenTest.php similarity index 100% rename from tests/src/Rule/StrlenTest.php rename to tests/unit/src/Rule/StrlenTest.php diff --git a/tests/src/Rule/TrimTest.php b/tests/unit/src/Rule/TrimTest.php similarity index 100% rename from tests/src/Rule/TrimTest.php rename to tests/unit/src/Rule/TrimTest.php diff --git a/tests/src/Rule/UploadTest.php b/tests/unit/src/Rule/UploadTest.php similarity index 100% rename from tests/src/Rule/UploadTest.php rename to tests/unit/src/Rule/UploadTest.php diff --git a/tests/src/Rule/UrlTest.php b/tests/unit/src/Rule/UrlTest.php similarity index 100% rename from tests/src/Rule/UrlTest.php rename to tests/unit/src/Rule/UrlTest.php diff --git a/tests/src/Rule/WordTest.php b/tests/unit/src/Rule/WordTest.php similarity index 100% rename from tests/src/Rule/WordTest.php rename to tests/unit/src/Rule/WordTest.php diff --git a/tests/src/RuleCollectionTest.php b/tests/unit/src/RuleCollectionTest.php similarity index 100% rename from tests/src/RuleCollectionTest.php rename to tests/unit/src/RuleCollectionTest.php diff --git a/tests/src/RuleLocatorTest.php b/tests/unit/src/RuleLocatorTest.php similarity index 100% rename from tests/src/RuleLocatorTest.php rename to tests/unit/src/RuleLocatorTest.php