From 81c342ca84a7c666980f17c62bf89c81b70104f9 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Wed, 10 Aug 2016 11:08:36 +0900 Subject: [PATCH 1/8] autoload-dev load for dev-only functions --- composer.json | 3 +++ tests/Fake/Provide/Transfer/FakeHttpResponder.php | 3 --- tests/functions.php | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 tests/functions.php diff --git a/composer.json b/composer.json index d5e5108c..294daaf5 100644 --- a/composer.json +++ b/composer.json @@ -31,5 +31,8 @@ "psr-4": { "BEAR\\Sunday\\": "src/" } + }, + "autoload-dev": { + "files": ["tests/functions.php"] } } diff --git a/tests/Fake/Provide/Transfer/FakeHttpResponder.php b/tests/Fake/Provide/Transfer/FakeHttpResponder.php index 36f79559..8e5eba9f 100644 --- a/tests/Fake/Provide/Transfer/FakeHttpResponder.php +++ b/tests/Fake/Provide/Transfer/FakeHttpResponder.php @@ -9,9 +9,6 @@ use BEAR\Resource\ResourceObject; -require_once __DIR__ . '/header.php'; -require_once __DIR__ . '/http_response_code.php'; - class FakeHttpResponder extends HttpResponder { public static $code; diff --git a/tests/functions.php b/tests/functions.php new file mode 100644 index 00000000..067d779e --- /dev/null +++ b/tests/functions.php @@ -0,0 +1,4 @@ + Date: Wed, 10 Aug 2016 11:10:15 +0900 Subject: [PATCH 2/8] unset unused arguments --- tests/Fake/Provide/Transfer/header.php | 7 ++----- tests/Fake/Provide/Transfer/http_response_code.php | 1 + 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/Fake/Provide/Transfer/header.php b/tests/Fake/Provide/Transfer/header.php index 907e404b..f9504adc 100644 --- a/tests/Fake/Provide/Transfer/header.php +++ b/tests/Fake/Provide/Transfer/header.php @@ -7,10 +7,7 @@ */ namespace BEAR\Sunday\Provide\Transfer; -function header( - $string, - $replace = true, - $http_response_code = null -) { +function header($string, $replace = true, $http_response_code = null) { + unset($string, $replace, $http_response_code); FakeHttpResponder::$headers[] = func_get_args(); } diff --git a/tests/Fake/Provide/Transfer/http_response_code.php b/tests/Fake/Provide/Transfer/http_response_code.php index 3dd4dd94..69e1a2e2 100644 --- a/tests/Fake/Provide/Transfer/http_response_code.php +++ b/tests/Fake/Provide/Transfer/http_response_code.php @@ -4,5 +4,6 @@ function http_response_code($int) { + unset($int); FakeHttpResponder::$code = func_get_args(); } From e9e98acf9539c47a2cff09c9b1bb32c33f84f077 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Mon, 3 Oct 2016 18:21:31 +0900 Subject: [PATCH 3/8] fix red test only php7 failed. https://travis-ci.org/koriym/BEAR.Sunday/jobs/164567979 --- tests/Fake/Provide/Transfer/header.php | 2 +- tests/Fake/Provide/Transfer/http_response_code.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Fake/Provide/Transfer/header.php b/tests/Fake/Provide/Transfer/header.php index f9504adc..cf30608f 100644 --- a/tests/Fake/Provide/Transfer/header.php +++ b/tests/Fake/Provide/Transfer/header.php @@ -8,6 +8,6 @@ namespace BEAR\Sunday\Provide\Transfer; function header($string, $replace = true, $http_response_code = null) { - unset($string, $replace, $http_response_code); FakeHttpResponder::$headers[] = func_get_args(); + unset($string, $replace, $http_response_code); } diff --git a/tests/Fake/Provide/Transfer/http_response_code.php b/tests/Fake/Provide/Transfer/http_response_code.php index 69e1a2e2..b5c414ad 100644 --- a/tests/Fake/Provide/Transfer/http_response_code.php +++ b/tests/Fake/Provide/Transfer/http_response_code.php @@ -4,6 +4,6 @@ function http_response_code($int) { - unset($int); FakeHttpResponder::$code = func_get_args(); + unset($int); } From 06882bdf2bd96ba5611d246ecfdbe973a98e634d Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Mon, 3 Oct 2016 18:21:47 +0900 Subject: [PATCH 4/8] update meta files --- .php_cs | 3 +++ .travis.yml | 12 +++++++----- phpcs.xml | 9 ++------- phpmd.xml | 33 ++++++++++++++------------------- 4 files changed, 26 insertions(+), 31 deletions(-) diff --git a/.php_cs b/.php_cs index 31ee793b..ff96ac7a 100644 --- a/.php_cs +++ b/.php_cs @@ -11,6 +11,8 @@ $config = Symfony\CS\Config\Config::create() 'no_blank_lines_after_class_opening', 'no_empty_lines_after_phpdocs', 'operators_spaces', + 'duplicate_semicolon', + 'namespace_no_leading_whitespace', 'phpdoc_indent', 'phpdoc_no_empty_return', 'phpdoc_no_package', @@ -23,6 +25,7 @@ $config = Symfony\CS\Config\Config::create() 'remove_lines_between_uses', 'return', 'single_array_no_trailing_comma', + 'single_quote', 'spaces_before_semicolon', 'spaces_cast', 'standardize_not_equal', diff --git a/.travis.yml b/.travis.yml index b3985e42..73394967 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,17 @@ -sudo: false language: php php: - - 5.5 - 5.6 + - 7.0 - hhvm - - 7 +sudo: false +cache: + directories: + - $HOME/.composer/cache before_script: - composer self-update - composer install script: - - phpunit --coverage-clover=coverage.clover + - phpunit after_script: - wget https://scrutinizer-ci.com/ocular.phar - - php ocular.phar code-coverage:upload --format=php-clover coverage.clover + - if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi diff --git a/phpcs.xml b/phpcs.xml index 4c9e459e..76dc14b7 100755 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,13 +1,12 @@ - The coding standard used for applications using BEAR.Sunday Framework. + + - - @@ -15,10 +14,6 @@ - - - src - tests diff --git a/phpmd.xml b/phpmd.xml index d33710cd..8d483397 100644 --- a/phpmd.xml +++ b/phpmd.xml @@ -1,24 +1,12 @@ - - - - - - - - - - - - - - - + + + @@ -28,10 +16,14 @@ - + - + + + + + @@ -41,10 +33,13 @@ + + + - + From 0e33ed1f8b75bac69a0da7ecaa7beab4faec6061 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Mon, 3 Oct 2016 18:27:33 +0900 Subject: [PATCH 5/8] add qa command --- composer.json | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/composer.json b/composer.json index 294daaf5..5addd964 100644 --- a/composer.json +++ b/composer.json @@ -34,5 +34,24 @@ }, "autoload-dev": { "files": ["tests/functions.php"] + }, + "scripts" :{ + "test": [ + "phpmd src text ./phpmd.xml", + "phpcs src tests", + "phpunit" + ], + "cs-fix": [ + "php-cs-fixer fix --config-file=./.php_cs", + "phpcbf src" + ], + "build": [ + "rm -rf ./build; mkdir -p ./build/logs ./build/pdepend ./build/api", + "pdepend --jdepend-xml=./build/logs/jdepend.xml --jdepend-chart=./build/pdepend/dependencies.svg --overview-pyramid=./build/pdepend/overview-pyramid.svg src", + "phploc --log-csv ./build/logs/phploc.csv src", + "phpcs --report=checkstyle --report-file=./build/logs/checkstyle.xml --standard=phpcs.xml src", + "apigen generate -s src -d build/api", + "@test" + ] } } From 4291d695df442f603180ce957369862cb360cb6c Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Mon, 3 Oct 2016 18:35:54 +0900 Subject: [PATCH 6/8] extract fake classes --- tests/Fake/Inject/DummyLogger.php | 36 +++++++++++++ tests/Fake/Inject/PsrLoggerApplication.php | 13 +++++ tests/Fake/Inject/PsrLoggerModule.php | 13 +++++ .../Fake/Inject/ResourceInjectApplication.php | 13 +++++ tests/Inject/PsrLoggerInjectTest.php | 51 ------------------- tests/Inject/ResourceInjectTest.php | 10 ---- 6 files changed, 75 insertions(+), 61 deletions(-) create mode 100644 tests/Fake/Inject/DummyLogger.php create mode 100644 tests/Fake/Inject/PsrLoggerApplication.php create mode 100644 tests/Fake/Inject/PsrLoggerModule.php create mode 100644 tests/Fake/Inject/ResourceInjectApplication.php diff --git a/tests/Fake/Inject/DummyLogger.php b/tests/Fake/Inject/DummyLogger.php new file mode 100644 index 00000000..1d34103c --- /dev/null +++ b/tests/Fake/Inject/DummyLogger.php @@ -0,0 +1,36 @@ +logger; + } +} diff --git a/tests/Fake/Inject/PsrLoggerModule.php b/tests/Fake/Inject/PsrLoggerModule.php new file mode 100644 index 00000000..1857e6c6 --- /dev/null +++ b/tests/Fake/Inject/PsrLoggerModule.php @@ -0,0 +1,13 @@ +bind('Psr\Log\LoggerInterface')->to(__NAMESPACE__ . '\DummyLogger'); + } +} diff --git a/tests/Fake/Inject/ResourceInjectApplication.php b/tests/Fake/Inject/ResourceInjectApplication.php new file mode 100644 index 00000000..7c06284c --- /dev/null +++ b/tests/Fake/Inject/ResourceInjectApplication.php @@ -0,0 +1,13 @@ +resource; + } +} diff --git a/tests/Inject/PsrLoggerInjectTest.php b/tests/Inject/PsrLoggerInjectTest.php index 40243acc..cebad568 100644 --- a/tests/Inject/PsrLoggerInjectTest.php +++ b/tests/Inject/PsrLoggerInjectTest.php @@ -2,59 +2,8 @@ namespace BEAR\Sunday\Inject; -use Psr\Log\LoggerInterface; -use Ray\Di\AbstractModule; use Ray\Di\Injector; -class PsrLoggerApplication -{ - use PsrLoggerInject; - - public function returnDependency() - { - return $this->logger; - } -} - -class DummyLogger implements LoggerInterface -{ - public function emergency($message, array $context = []) - { - } - public function alert($message, array $context = []) - { - } - public function critical($message, array $context = []) - { - } - public function error($message, array $context = []) - { - } - public function warning($message, array $context = []) - { - } - public function notice($message, array $context = []) - { - } - public function info($message, array $context = []) - { - } - public function debug($message, array $context = []) - { - } - public function log($level, $message, array $context = []) - { - } -} - -class PsrLoggerModule extends AbstractModule -{ - protected function configure() - { - $this->bind('Psr\Log\LoggerInterface')->to(__NAMESPACE__ . '\DummyLogger'); - } -} - class PsrLoggerInjectTest extends \PHPUnit_Framework_TestCase { public function testInjectTrait() diff --git a/tests/Inject/ResourceInjectTest.php b/tests/Inject/ResourceInjectTest.php index f29eea3e..7d5870f6 100644 --- a/tests/Inject/ResourceInjectTest.php +++ b/tests/Inject/ResourceInjectTest.php @@ -6,16 +6,6 @@ use BEAR\Sunday\Module\Resource\ResourceModule; use Ray\Di\Injector; -class ResourceInjectApplication -{ - use ResourceInject; - - public function returnDependency() - { - return $this->resource; - } -} - class ResourceInjectTest extends \PHPUnit_Framework_TestCase { public function testInjectTrait() From 9be64b021968fe6ca160b3b032e71488a98c91c9 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Mon, 3 Oct 2016 18:36:18 +0900 Subject: [PATCH 7/8] fix phpcs --- tests/Fake/Provide/Transfer/header.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Fake/Provide/Transfer/header.php b/tests/Fake/Provide/Transfer/header.php index cf30608f..0cd98271 100644 --- a/tests/Fake/Provide/Transfer/header.php +++ b/tests/Fake/Provide/Transfer/header.php @@ -7,7 +7,9 @@ */ namespace BEAR\Sunday\Provide\Transfer; -function header($string, $replace = true, $http_response_code = null) { +function header($string, $replace = true, $http_response_code = null) +{ FakeHttpResponder::$headers[] = func_get_args(); + unset($string, $replace, $http_response_code); } From fa9eb3784b2aae9af870d3d2b62035a06fa8f978 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Wed, 5 Oct 2016 15:27:18 +0900 Subject: [PATCH 8/8] update LICENSE --- LICENSE | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/LICENSE b/LICENSE index 5200beeb..dd5c9de9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,23 +1,21 @@ -Copyright (c) 2012-2016, Akihito Koriyama -All rights reserved. +The MIT License (MIT) -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: +Copyright (c) 2012-2016 Akihito Koriyama -- Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: -- Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE.