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
diff --git a/src/Upload/AbstractUploadHandler.php b/src/Upload/AbstractUploadHandler.php
index cc2f38a..56415f1 100644
--- a/src/Upload/AbstractUploadHandler.php
+++ b/src/Upload/AbstractUploadHandler.php
@@ -36,7 +36,7 @@ abstract class AbstractUploadHandler implements UploadHandlerInterface
*/
public function __construct($options = [])
{
- if (!empty($options)) {
+ if (! empty($options)) {
$this->setOptions($options);
}
}
@@ -54,7 +54,7 @@ public function setOptions($options)
{
if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
- } elseif (!is_array($options)) {
+ } elseif (! is_array($options)) {
throw new Exception\InvalidArgumentException(
'The options parameter must be an array or a Traversable'
);
@@ -141,7 +141,7 @@ public function getProgress($id)
$this->setProgressAdapter($adapter);
}
- if (!$adapter instanceof ProgressBar) {
+ if (! $adapter instanceof ProgressBar) {
throw new Exception\RuntimeException('Unknown Adapter type given');
}
@@ -170,7 +170,7 @@ abstract protected function getUploadProgress($id);
protected function toByteString($size)
{
$sizes = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
- for ($i=0; $size >= 1024 && $i < 9; $i++) {
+ for ($i = 0; $size >= 1024 && $i < 9; $i++) {
$size /= 1024;
}
diff --git a/src/Upload/ApcProgress.php b/src/Upload/ApcProgress.php
index 73f20d2..37eb993 100644
--- a/src/Upload/ApcProgress.php
+++ b/src/Upload/ApcProgress.php
@@ -23,12 +23,12 @@ class ApcProgress extends AbstractUploadHandler
*/
protected function getUploadProgress($id)
{
- if (!$this->isApcAvailable()) {
+ if (! $this->isApcAvailable()) {
throw new Exception\PhpEnvironmentException('APC extension is not installed');
}
$uploadInfo = apc_fetch(ini_get('apc.rfc1867_prefix') . $id);
- if (!is_array($uploadInfo)) {
+ if (! is_array($uploadInfo)) {
return false;
}
@@ -40,7 +40,7 @@ protected function getUploadProgress($id)
'done' => false
];
$status = $uploadInfo + $status;
- if (!empty($status['cancel_upload'])) {
+ if (! empty($status['cancel_upload'])) {
$status['done'] = true;
$status['message'] = 'The upload has been canceled';
}
diff --git a/src/Upload/SessionProgress.php b/src/Upload/SessionProgress.php
index d7e874a..0b4a924 100644
--- a/src/Upload/SessionProgress.php
+++ b/src/Upload/SessionProgress.php
@@ -23,7 +23,7 @@ class SessionProgress extends AbstractUploadHandler
*/
protected function getUploadProgress($id)
{
- if (!$this->isSessionUploadProgressAvailable()) {
+ if (! $this->isSessionUploadProgressAvailable()) {
throw new Exception\PhpEnvironmentException(
'Session Upload Progress is not available'
);
@@ -31,7 +31,7 @@ protected function getUploadProgress($id)
$sessionKey = ini_get('session.upload_progress.prefix') . $id;
$uploadInfo = (isset($_SESSION[$sessionKey])) ? $_SESSION[$sessionKey] : null;
- if (!is_array($uploadInfo)) {
+ if (! is_array($uploadInfo)) {
return false;
}
@@ -49,7 +49,7 @@ protected function getUploadProgress($id)
$time = time() - $status['start_time'];
$status['rate'] = ($time > 0) ? $status['bytes_processed'] / $time : 0;
- if (!empty($status['cancel_upload'])) {
+ if (! empty($status['cancel_upload'])) {
$status['done'] = true;
$status['message'] = 'The upload has been canceled';
}
diff --git a/src/Upload/UploadProgress.php b/src/Upload/UploadProgress.php
index dcedbdd..c4e5d0a 100644
--- a/src/Upload/UploadProgress.php
+++ b/src/Upload/UploadProgress.php
@@ -23,14 +23,14 @@ class UploadProgress extends AbstractUploadHandler
*/
protected function getUploadProgress($id)
{
- if (!$this->isUploadProgressAvailable()) {
+ if (! $this->isUploadProgressAvailable()) {
throw new Exception\PhpEnvironmentException(
'UploadProgress extension is not installed'
);
}
$uploadInfo = uploadprogress_get_info($id);
- if (!is_array($uploadInfo)) {
+ if (! is_array($uploadInfo)) {
return false;
}
diff --git a/test/Adapter/ConsoleStub.php b/test/Adapter/ConsoleStub.php
index 26b7552..f9219f5 100644
--- a/test/Adapter/ConsoleStub.php
+++ b/test/Adapter/ConsoleStub.php
@@ -20,8 +20,10 @@ public function getLastOutput()
return $this->lastOutput;
}
+ // @codingStandardsIgnoreStart
protected function _outputData($data)
{
+ // @codingStandardsIgnoreEnd
$this->lastOutput = $data;
}
diff --git a/test/Adapter/ConsoleTest.php b/test/Adapter/ConsoleTest.php
index d5aeca7..0a32535 100644
--- a/test/Adapter/ConsoleTest.php
+++ b/test/Adapter/ConsoleTest.php
@@ -12,8 +12,6 @@
use Zend\ProgressBar\Adapter;
use Zend\Stdlib\StringUtils;
-require_once 'MockupStream.php';
-
/**
* @group Zend_ProgressBar
*/
@@ -80,7 +78,10 @@ public function testFixedWidth()
public function testInvalidElement()
{
- $this->setExpectedException('Zend\ProgressBar\Adapter\Exception\InvalidArgumentException', 'Invalid element found');
+ $this->setExpectedException(
+ 'Zend\ProgressBar\Adapter\Exception\InvalidArgumentException',
+ 'Invalid element found'
+ );
$adapter = new ConsoleStub(['width' => 30, 'elements' => ['foo']]);
}
@@ -127,7 +128,7 @@ public function testEtaOnly()
public function testCustomOrder()
{
- $adapter = new ConsoleStub(['width' => 25, 'elements' => [Adapter\Console::ELEMENT_ETA,
+ $adapter = new ConsoleStub(['width' => 25, 'elements' => [Adapter\Console::ELEMENT_ETA,
Adapter\Console::ELEMENT_PERCENT,
Adapter\Console::ELEMENT_BAR]]);
$adapter->notify(0, 100, 0, 0, null, null);
@@ -137,7 +138,9 @@ public function testCustomOrder()
public function testBarStyleIndicator()
{
- $adapter = new ConsoleStub(['width' => 20, 'elements' => [Adapter\Console::ELEMENT_BAR], 'barIndicatorChar' => '>']);
+ $adapter = new ConsoleStub(
+ ['width' => 20, 'elements' => [Adapter\Console::ELEMENT_BAR], 'barIndicatorChar' => '>']
+ );
$adapter->notify(10, 100, .1, 0, null, null);
$this->assertContains('[##>---------------]', $adapter->getLastOutput());
@@ -145,7 +148,9 @@ public function testBarStyleIndicator()
public function testBarStyleIndicatorWide()
{
- $adapter = new ConsoleStub(['width' => 20, 'elements' => [Adapter\Console::ELEMENT_BAR], 'barIndicatorChar' => '[]']);
+ $adapter = new ConsoleStub(
+ ['width' => 20, 'elements' => [Adapter\Console::ELEMENT_BAR], 'barIndicatorChar' => '[]']
+ );
$adapter->notify(10, 100, .1, 0, null, null);
$this->assertContains('[##[]--------------]', $adapter->getLastOutput());
@@ -153,7 +158,9 @@ public function testBarStyleIndicatorWide()
public function testBarStyleLeftRightNormal()
{
- $adapter = new ConsoleStub(['width' => 20, 'elements' => [Adapter\Console::ELEMENT_BAR], 'barLeftChar' => '+', 'barRightChar' => ' ']);
+ $adapter = new ConsoleStub(
+ ['width' => 20, 'elements' => [Adapter\Console::ELEMENT_BAR], 'barLeftChar' => '+', 'barRightChar' => ' ']
+ );
$adapter->notify(10, 100, .1, 0, null, null);
$this->assertContains('[++ ]', $adapter->getLastOutput());
@@ -161,7 +168,9 @@ public function testBarStyleLeftRightNormal()
public function testBarStyleLeftRightWide()
{
- $adapter = new ConsoleStub(['width' => 20, 'elements' => [Adapter\Console::ELEMENT_BAR], 'barLeftChar' => '+-', 'barRightChar' => '=-']);
+ $adapter = new ConsoleStub(
+ ['width' => 20, 'elements' => [Adapter\Console::ELEMENT_BAR], 'barLeftChar' => '+-', 'barRightChar' => '=-']
+ );
$adapter->notify(10, 100, .1, 0, null, null);
$this->assertContains('[+-=-=-=-=-=-=-=-=-]', $adapter->getLastOutput());
@@ -169,7 +178,13 @@ public function testBarStyleLeftRightWide()
public function testBarStyleLeftIndicatorRightWide()
{
- $adapter = new ConsoleStub(['width' => 20, 'elements' => [Adapter\Console::ELEMENT_BAR], 'barLeftChar' => '+-', 'barIndicatorChar' => '[]', 'barRightChar' => '=-']);
+ $adapter = new ConsoleStub([
+ 'width' => 20,
+ 'elements' => [Adapter\Console::ELEMENT_BAR],
+ 'barLeftChar' => '+-',
+ 'barIndicatorChar' => '[]',
+ 'barRightChar' => '=-'
+ ]);
$adapter->notify(10, 100, .1, 0, null, null);
$this->assertContains('[+-[]=-=-=-=-=-=-=-]', $adapter->getLastOutput());
@@ -199,7 +214,9 @@ public function testEtaHighValue()
public function testTextElementDefaultLength()
{
- $adapter = new ConsoleStub(['width' => 100, 'elements' => [Adapter\Console::ELEMENT_TEXT, Adapter\Console::ELEMENT_BAR]]);
+ $adapter = new ConsoleStub(
+ ['width' => 100, 'elements' => [Adapter\Console::ELEMENT_TEXT, Adapter\Console::ELEMENT_BAR]]
+ );
$adapter->notify(0, 100, 0, 0, null, 'foobar');
$this->assertContains('foobar [', $adapter->getLastOutput());
@@ -207,7 +224,11 @@ public function testTextElementDefaultLength()
public function testTextElementCustomLength()
{
- $adapter = new ConsoleStub(['width' => 100, 'elements' => [Adapter\Console::ELEMENT_TEXT, Adapter\Console::ELEMENT_BAR], 'textWidth' => 10]);
+ $adapter = new ConsoleStub([
+ 'width' => 100,
+ 'elements' => [Adapter\Console::ELEMENT_TEXT, Adapter\Console::ELEMENT_BAR],
+ 'textWidth' => 10
+ ]);
$adapter->notify(0, 100, 0, 0, null, 'foobar');
$this->assertContains('foobar [', $adapter->getLastOutput());
@@ -275,7 +296,10 @@ public function testSetBarLeftChar()
{
$adapter = new Adapter\Console();
- $this->setExpectedException('Zend\ProgressBar\Adapter\Exception\InvalidArgumentException', 'Character may not be empty');
+ $this->setExpectedException(
+ 'Zend\ProgressBar\Adapter\Exception\InvalidArgumentException',
+ 'Character may not be empty'
+ );
$adapter->setBarLeftChar(null);
}
@@ -283,7 +307,10 @@ public function testSetBarRightChar()
{
$adapter = new Adapter\Console();
- $this->setExpectedException('Zend\ProgressBar\Adapter\Exception\InvalidArgumentException', 'Character may not be empty');
+ $this->setExpectedException(
+ 'Zend\ProgressBar\Adapter\Exception\InvalidArgumentException',
+ 'Character may not be empty'
+ );
$adapter->setBarRightChar(null);
}
@@ -291,7 +318,10 @@ public function testSetInvalidFinishAction()
{
$adapter = new Adapter\Console();
- $this->setExpectedException('Zend\ProgressBar\Adapter\Exception\InvalidArgumentException', 'Invalid finish action specified');
+ $this->setExpectedException(
+ 'Zend\ProgressBar\Adapter\Exception\InvalidArgumentException',
+ 'Invalid finish action specified'
+ );
$adapter->setFinishAction('CUSTOM_FINISH_ACTION');
}
@@ -305,8 +335,10 @@ public function testMultibyteTruncateFixedWidth()
Adapter\Console::ELEMENT_BAR,
Adapter\Console::ELEMENT_ETA,
Adapter\Console::ELEMENT_TEXT]]);
- $adapter->notify(21, 100, .21, 60, 60, 'ChineseTest 這是多字節長度裁剪的測試。我們希望能有超過20名中國字符的長字符串');
+ // @codingStandardsIgnoreStart
+ $adapter->notify( 21, 100, .21, 60, 60, 'ChineseTest 這是多字節長度裁剪的測試。我們希望能有超過20名中國字符的長字符串');
$this->assertEquals(' 21% [##-------] ETA 00:01:00 ChineseTest 這是多字節長度裁', $adapter->getLastOutput());
+ // @codingStandardsIgnoreEnd
$wrapper = StringUtils::getWrapper($adapter->getCharset());
$this->assertEquals($outputWidth, $wrapper->strlen($adapter->getLastOutput()));
diff --git a/test/Adapter/JsPullTest.php b/test/Adapter/JsPullTest.php
index 41ee516..ae9b18f 100644
--- a/test/Adapter/JsPullTest.php
+++ b/test/Adapter/JsPullTest.php
@@ -9,6 +9,8 @@
namespace ZendTest\ProgressBar\Adapter;
+use ZendTest\ProgressBar\TestAsset\JsPullStub;
+
/**
* @group Zend_ProgressBar
*/
@@ -38,18 +40,3 @@ public function testJson()
$this->assertTrue($data['finished']);
}
}
-
-class JsPullStub extends \Zend\ProgressBar\Adapter\JsPull
-{
- protected $_lastOutput = null;
-
- public function getLastOutput()
- {
- return $this->_lastOutput;
- }
-
- protected function _outputData($data)
- {
- $this->_lastOutput = $data;
- }
-}
diff --git a/test/Adapter/JsPushTest.php b/test/Adapter/JsPushTest.php
index 2b2d21e..9bc6d49 100644
--- a/test/Adapter/JsPushTest.php
+++ b/test/Adapter/JsPushTest.php
@@ -9,6 +9,8 @@
namespace ZendTest\ProgressBar\Adapter;
+use ZendTest\ProgressBar\TestAsset\JsPushStub;
+
/**
* @group Zend_ProgressBar
*/
@@ -22,7 +24,8 @@ public function testJson()
$adapter->notify(0, 2, 0.5, 1, 1, 'status');
$output = $adapter->getLastOutput();
- $matches = preg_match('##', $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'
);