diff --git a/.php_cs b/.php_cs deleted file mode 100644 index 8f4dd5a..0000000 --- a/.php_cs +++ /dev/null @@ -1,45 +0,0 @@ -in('src') - ->in('test') - ->notPath('TestAsset') - ->notPath('_files') - ->filter(function (SplFileInfo $file) { - if (strstr($file->getPath(), 'compatibility')) { - return false; - } - }); -$config = Symfony\CS\Config\Config::create(); -$config->level(null); -$config->fixers( - array( - 'braces', - 'duplicate_semicolon', - 'elseif', - 'empty_return', - 'encoding', - 'eof_ending', - 'function_call_space', - 'function_declaration', - 'indentation', - 'join_function', - 'line_after_namespace', - 'linefeed', - 'lowercase_keywords', - 'parenthesis', - 'multiple_use', - 'method_argument_space', - 'object_operator', - 'php_closing_tag', - 'remove_lines_between_uses', - 'short_array_syntax', - 'short_tag', - 'standardize_not_equal', - 'trailing_spaces', - 'unused_use', - 'visibility', - 'whitespacy_lines', - ) -); -$config->finder($finder); -return $config; diff --git a/.travis.yml b/.travis.yml index 6d28225..cae9c71 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,10 +26,10 @@ matrix: include: - php: 5.5 env: - - EXECUTE_CS_CHECK=true + - CS_CHECK=true - php: 5.6 env: - - EXECUTE_TEST_COVERALLS=true + - TEST_COVERAGE=true - DEPLOY_DOCS="$(if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then echo -n 'true' ; else echo -n 'false' ; fi)" - PATH="$HOME/.local/bin:$PATH" - php: 7 @@ -42,21 +42,20 @@ notifications: email: false before_install: - - if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi + - if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi - composer self-update - - if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi + - if [[ $TEST_COVERAGE == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi install: - travis_retry composer install --no-interaction --ignore-platform-reqs script: - - if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/phpunit --coverage-clover clover.xml ; fi - - if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then ./vendor/bin/phpunit ; fi - - if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run ; fi + - if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage ; else composer test ; fi + - if [[ $CS_CHECK == 'true' ]]; then composer cs-check ; fi - if [[ $DEPLOY_DOCS == "true" && "$TRAVIS_TEST_RESULT" == "0" ]]; then wget -O theme-installer.sh "https://raw.githubusercontent.com/zendframework/zf-mkdoc-theme/master/theme-installer.sh" ; chmod 755 theme-installer.sh ; ./theme-installer.sh ; fi after_success: - if [[ $DEPLOY_DOCS == "true" ]]; then echo "Preparing to build and deploy documentation" ; ./zf-mkdoc-theme/deploy.sh ; echo "Completed deploying documentation" ; fi after_script: - - if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/coveralls ; fi + - if [[ $TEST_COVERAGE == 'true' ]]; then composer upload-coverage ; fi diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 73308be..7aa55f2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -77,24 +77,24 @@ To do so: ## Running Coding Standards Checks -This component uses [php-cs-fixer](http://cs.sensiolabs.org/) for coding +This component uses [phpcs](https://github.com/squizlabs/PHP_CodeSniffer) for coding standards checks, and provides configuration for our selected checks. -`php-cs-fixer` is installed by default via Composer. +`phpcs` is installed by default via Composer. To run checks only: ```console -$ ./vendor/bin/php-cs-fixer fix . -v --diff --dry-run --config-file=.php_cs +$ composer cs-check ``` -To have `php-cs-fixer` attempt to fix problems for you, omit the `--dry-run` -flag: +`phpcs` also includes a tool for fixing most CS violations, `phpcbf`: + ```console -$ ./vendor/bin/php-cs-fixer fix . -v --diff --config-file=.php_cs +$ composer cs-fix ``` -If you allow php-cs-fixer to fix CS issues, please re-run the tests to ensure +If you allow `phpcbf` to fix CS issues, please re-run the tests to ensure they pass, and make sure you add and commit the changes after verification. ## Recommended Workflow for Contributions diff --git a/composer.json b/composer.json index 97a048f..aec3a32 100644 --- a/composer.json +++ b/composer.json @@ -19,8 +19,8 @@ "require-dev": { "zendframework/zend-json": "^2.6.1", "zendframework/zend-session": "^2.6.2", - "fabpot/php-cs-fixer": "1.7.*", - "phpunit/PHPUnit": "~4.0" + "phpunit/PHPUnit": "~4.0", + "zendframework/zend-coding-standard": "~1.0.0" }, "suggest": { "zendframework/zend-json": "Zend\\Json component", @@ -38,5 +38,16 @@ "psr-4": { "ZendTest\\ProgressBar\\": "test/" } + }, + "scripts": { + "check": [ + "@cs-check", + "@test" + ], + "cs-check": "phpcs", + "cs-fix": "phpcbf", + "test": "phpunit --colors=always", + "test-coverage": "phpunit --colors=always --coverage-clover clover.xml", + "upload-coverage": "coveralls -v" } } diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..9e6a751 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,8 @@ + + + + + + src + test + diff --git a/src/Adapter/Console.php b/src/Adapter/Console.php index c6c786b..09987dc 100644 --- a/src/Adapter/Console.php +++ b/src/Adapter/Console.php @@ -192,7 +192,7 @@ public function setOutputStream($resource) public function getOutputStream() { if ($this->outputStream === null) { - if (!defined('STDOUT')) { + if (! defined('STDOUT')) { $this->outputStream = fopen('php://stdout', 'w'); } else { return STDOUT; @@ -210,7 +210,7 @@ public function getOutputStream() */ public function setWidth($width = null) { - if ($width === null || !is_int($width)) { + if ($width === null || ! is_int($width)) { if (substr(PHP_OS, 0, 3) === 'WIN') { // We have to default to 79 on windows, because the windows // terminal always has a fixed width of 80 characters and the @@ -243,7 +243,8 @@ public function setWidth($width = null) * Set the elements to display with the progressbar * * @param array $elements - * @throws \Zend\ProgressBar\Adapter\Exception\InvalidArgumentException When an invalid element is found in the array + * @throws \Zend\ProgressBar\Adapter\Exception\InvalidArgumentException When an invalid element is found + * in the array * @return \Zend\ProgressBar\Adapter\Console */ public function setElements(array $elements) @@ -351,7 +352,7 @@ public function setFinishAction($action) self::FINISH_ACTION_EOL, self::FINISH_ACTION_NONE]; - if (!in_array($action, $allowedActions)) { + if (! in_array($action, $allowedActions)) { throw new Exception\InvalidArgumentException('Invalid finish action specified'); } @@ -394,14 +395,22 @@ public function notify($current, $max, $percent, $timeTaken, $timeRemaining, $te $doneWidth = min($visualWidth - $indicatorWidth, round($visualWidth * $percent)); if ($doneWidth > 0) { - $bar .= substr(str_repeat($this->barLeftChar, ceil($doneWidth / strlen($this->barLeftChar))), 0, $doneWidth); + $bar .= substr( + str_repeat($this->barLeftChar, ceil($doneWidth / strlen($this->barLeftChar))), + 0, + $doneWidth + ); } $bar .= $this->barIndicatorChar; $leftWidth = $visualWidth - $doneWidth - $indicatorWidth; if ($leftWidth > 0) { - $bar .= substr(str_repeat($this->barRightChar, ceil($leftWidth / strlen($this->barRightChar))), 0, $leftWidth); + $bar .= substr( + str_repeat($this->barRightChar, ceil($leftWidth / strlen($this->barRightChar))), + 0, + $leftWidth + ); } $bar .= ']'; @@ -485,8 +494,10 @@ public function finish() * * @return void */ + // @codingStandardsIgnoreStart protected function _calculateBarWidth() { + // @codingStandardsIgnoreEnd if (in_array(self::ELEMENT_BAR, $this->elements)) { $barWidth = $this->width; @@ -514,8 +525,10 @@ protected function _calculateBarWidth() * @param string $data * @return void */ + // @codingStandardsIgnoreStart protected function _outputData($data) { + // @codingStandardsIgnoreEnd fwrite($this->getOutputStream(), $data); } } diff --git a/src/Adapter/JsPull.php b/src/Adapter/JsPull.php index b349005..85a60ae 100644 --- a/src/Adapter/JsPull.php +++ b/src/Adapter/JsPull.php @@ -84,8 +84,10 @@ public function finish() * @param string $data * @return void */ + // @codingStandardsIgnoreStart protected function _outputData($data) { + // @codingStandardsIgnoreEnd echo $data; if ($this->exitAfterSend) { diff --git a/src/Adapter/JsPush.php b/src/Adapter/JsPush.php index 48753ee..284df24 100644 --- a/src/Adapter/JsPush.php +++ b/src/Adapter/JsPush.php @@ -113,8 +113,10 @@ public function finish() * @param string $data * @return void */ + // @codingStandardsIgnoreStart protected function _outputData($data) { + // @codingStandardsIgnoreEnd // 1024 padding is required for Safari, while 256 padding is required // for Internet Explorer. The
is required so Safari actually // executes the #', $output, $result); + $matches = preg_match('##', $output, $result); $this->assertEquals(1, $matches); $data = json_decode($result[1], true); @@ -37,22 +40,8 @@ public function testJson() $adapter->finish(); $output = $adapter->getLastOutput(); - $matches = preg_match('##', $output, $result); + $matches = preg_match('##', $output, $result); $this->assertEquals(1, $matches); } } - -class JsPushStub extends \Zend\ProgressBar\Adapter\JsPush -{ - protected $_lastOutput = null; - - public function getLastOutput() - { - return $this->_lastOutput; - } - - protected function _outputData($data) - { - $this->_lastOutput = $data; - } -} diff --git a/test/Adapter/MockupStream.php b/test/Adapter/MockupStream.php index cf6e5d7..a244c59 100644 --- a/test/Adapter/MockupStream.php +++ b/test/Adapter/MockupStream.php @@ -18,8 +18,10 @@ class MockupStream public static $tests = []; + // @codingStandardsIgnoreStart public function stream_open($path, $mode, $options, &$opened_path) { + // @codingStandardsIgnoreEnd $url = parse_url($path); $this->test = $url["host"]; $this->position = 0; @@ -28,15 +30,19 @@ public function stream_open($path, $mode, $options, &$opened_path) return true; } + // @codingStandardsIgnoreStart public function stream_read($count) { + // @codingStandardsIgnoreEnd $ret = substr(static::$tests[$this->test], $this->position, $count); $this->position += strlen($ret); return $ret; } + // @codingStandardsIgnoreStart public function stream_write($data) { + // @codingStandardsIgnoreEnd $left = substr(static::$tests[$this->test], 0, $this->position); $right = substr(static::$tests[$this->test], $this->position + strlen($data)); static::$tests[$this->test] = $left . $data . $right; @@ -44,18 +50,24 @@ public function stream_write($data) return strlen($data); } + // @codingStandardsIgnoreStart public function stream_tell() { + // @codingStandardsIgnoreEnd return $this->position; } + // @codingStandardsIgnoreStart public function stream_eof() { + // @codingStandardsIgnoreEnd return $this->position >= strlen(static::$tests[$this->test]); } + // @codingStandardsIgnoreStart public function stream_seek($offset, $whence) { + // @codingStandardsIgnoreEnd switch ($whence) { case SEEK_SET: if ($offset < strlen(static::$tests[$this->test]) && $offset >= 0) { diff --git a/test/ProgressBarTest.php b/test/ProgressBarTest.php index b5fe3ab..6b4840a 100644 --- a/test/ProgressBarTest.php +++ b/test/ProgressBarTest.php @@ -9,6 +9,9 @@ namespace ZendTest\ProgressBar; +use ZendTest\ProgressBar\TestAsset\MockUp; +use ZendTest\ProgressBar\TestAsset\Stub; + /** * @group Zend_ProgressBar */ @@ -84,100 +87,10 @@ public function testEtaZeroPercent() $this->assertEquals(null, $progressBar->getTimeRemaining()); } + // @codingStandardsIgnoreStart protected function _getProgressBar($min, $max, $persistenceNamespace = null) { + // @codingStandardsIgnoreEnd return new Stub(new MockUp(), $min, $max, $persistenceNamespace); } } - -class Stub extends \Zend\ProgressBar\ProgressBar -{ - public function sleep($seconds) - { - $this->startTime -= $seconds; - } - - public function getCurrent() - { - return $this->adapter->getCurrent(); - } - - public function getMax() - { - return $this->adapter->getMax(); - } - - public function getPercent() - { - return $this->adapter->getPercent(); - } - - public function getTimeTaken() - { - return $this->adapter->getTimeTaken(); - } - - public function getTimeRemaining() - { - return $this->adapter->getTimeRemaining(); - } - - public function getText() - { - return $this->adapter->getText(); - } -} - -class MockUp extends \Zend\ProgressBar\Adapter\AbstractAdapter -{ - protected $_current; - protected $_max; - protected $_percent; - protected $_timeTaken; - protected $_timeRemaining; - protected $_text; - - public function notify($current, $max, $percent, $timeTaken, $timeRemaining, $text) - { - $this->_current = $current; - $this->_max = $max; - $this->_percent = $percent; - $this->_timeTaken = $timeTaken; - $this->_timeRemaining = $timeRemaining; - $this->_text = $text; - } - - public function finish() - { - } - - public function getCurrent() - { - return $this->_current; - } - - public function getMax() - { - return $this->_max; - } - - public function getPercent() - { - return $this->_percent; - } - - public function getTimeTaken() - { - return $this->_timeTaken; - } - - public function getTimeRemaining() - { - return $this->_timeRemaining; - } - - public function getText() - { - return $this->_text; - } -} diff --git a/test/TestAsset/JsPullStub.php b/test/TestAsset/JsPullStub.php new file mode 100644 index 0000000..0afac37 --- /dev/null +++ b/test/TestAsset/JsPullStub.php @@ -0,0 +1,22 @@ +_lastOutput; + } + + // @codingStandardsIgnoreStart + protected function _outputData($data) + { + // @codingStandardsIgnoreEnd + $this->_lastOutput = $data; + } +} diff --git a/test/TestAsset/JsPushStub.php b/test/TestAsset/JsPushStub.php new file mode 100644 index 0000000..bccff41 --- /dev/null +++ b/test/TestAsset/JsPushStub.php @@ -0,0 +1,22 @@ +_lastOutput; + } + + // @codingStandardsIgnoreStart + protected function _outputData($data) + { + // @codingStandardsIgnoreEnd + $this->_lastOutput = $data; + } +} diff --git a/test/TestAsset/MockUp.php b/test/TestAsset/MockUp.php new file mode 100644 index 0000000..942d804 --- /dev/null +++ b/test/TestAsset/MockUp.php @@ -0,0 +1,59 @@ +_current = $current; + $this->_max = $max; + $this->_percent = $percent; + $this->_timeTaken = $timeTaken; + $this->_timeRemaining = $timeRemaining; + $this->_text = $text; + } + + public function finish() + { + } + + public function getCurrent() + { + return $this->_current; + } + + public function getMax() + { + return $this->_max; + } + + public function getPercent() + { + return $this->_percent; + } + + public function getTimeTaken() + { + return $this->_timeTaken; + } + + public function getTimeRemaining() + { + return $this->_timeRemaining; + } + + public function getText() + { + return $this->_text; + } +} diff --git a/test/TestAsset/Stub.php b/test/TestAsset/Stub.php new file mode 100644 index 0000000..4cc56a5 --- /dev/null +++ b/test/TestAsset/Stub.php @@ -0,0 +1,41 @@ +startTime -= $seconds; + } + + public function getCurrent() + { + return $this->adapter->getCurrent(); + } + + public function getMax() + { + return $this->adapter->getMax(); + } + + public function getPercent() + { + return $this->adapter->getPercent(); + } + + public function getTimeTaken() + { + return $this->adapter->getTimeTaken(); + } + + public function getTimeRemaining() + { + return $this->adapter->getTimeRemaining(); + } + + public function getText() + { + return $this->adapter->getText(); + } +} diff --git a/test/Upload/AbstractUploadHandlerTest.php b/test/Upload/AbstractUploadHandlerTest.php index e62c7e6..0f4ce58 100644 --- a/test/Upload/AbstractUploadHandlerTest.php +++ b/test/Upload/AbstractUploadHandlerTest.php @@ -144,7 +144,10 @@ public function testProgressBarUpdate($progressData) ->method('notify'); } $progressBar = new ProgressBar( - $adapterStub, 0, $progressData['total'], 'testSession' + $adapterStub, + 0, + $progressData['total'], + 'testSession' );