diff --git a/.travis.yml b/.travis.yml index 026eadb..34dad1d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,7 +47,6 @@ before_install: - if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi - if [[ $ZEND_SERVICEMANAGER_VERSION != '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:$ZEND_SERVICEMANAGER_VERSION" ; fi - if [[ $ZEND_SERVICEMANAGER_VERSION == '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:^3.0.3" ; fi - - if [[ $ZEND_SERVICEMANAGER_VERSION == '' ]]; then composer remove --dev --no-update zendframework/zend-progressbar ; fi install: - travis_retry composer install --no-interaction --ignore-platform-reqs diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dd56cb..6f9e66d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. -## 2.6.1 - TBD +## 2.6.1 - 2016-03-02 ### Added @@ -18,7 +18,10 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- Nothing. +- [#21](https://github.com/zendframework/zend-file/pull/21) updates the codebase + to re-enable tests against zend-progressbar, and fixes static calls inside + `Zend\File\Transfer\Adapter\Http::getProgress` for testing APC and/or + uploadprogress availability to ensure they work correctly. ## 2.6.0 - 2016-02-17 diff --git a/composer.json b/composer.json index c765b7b..d2f4f5e 100644 --- a/composer.json +++ b/composer.json @@ -19,9 +19,10 @@ "require-dev": { "zendframework/zend-filter": "^2.6.1", "zendframework/zend-i18n": "^2.6", + "zendframework/zend-progressbar": "^2.5.2", "zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3", + "zendframework/zend-session": "^2.6.2", "zendframework/zend-validator": "^2.6", - "zendframework/zend-progressbar": "~2.5", "fabpot/php-cs-fixer": "1.7.*", "phpunit/PHPUnit": "~4.0" }, diff --git a/src/Transfer/Adapter/Http.php b/src/Transfer/Adapter/Http.php index d0136ed..96e26cd 100644 --- a/src/Transfer/Adapter/Http.php +++ b/src/Transfer/Adapter/Http.php @@ -288,7 +288,7 @@ public function isUploaded($files = null) */ public static function getProgress($id = null) { - if (!static::isApcAvailable() && !static::isUploadProgressAvailable()) { + if (!self::isApcAvailable() && !self::isUploadProgressAvailable()) { throw new Exception\PhpEnvironmentException('Neither APC nor UploadProgress extension installed'); } @@ -332,18 +332,18 @@ public static function getProgress($id = null) } if (!empty($id)) { - if (static::isApcAvailable()) { + if (self::isApcAvailable()) { $call = call_user_func(static::$callbackApc, ini_get('apc.rfc1867_prefix') . $id); if (is_array($call)) { $status = $call + $status; } - } elseif (static::isUploadProgressAvailable()) { + } elseif (self::isUploadProgressAvailable()) { $call = call_user_func(static::$callbackUploadProgress, $id); if (is_array($call)) { $status = $call + $status; - $status['total'] = $status['bytes_total']; - $status['current'] = $status['bytes_uploaded']; - $status['rate'] = $status['speed_average']; + $status['total'] = isset($status['bytes_total']) ? $status['bytes_total'] : $status['total']; + $status['current'] = isset($status['bytes_uploaded']) ? $status['bytes_uploaded'] : $status['current']; + $status['rate'] = isset($status['speed_average']) ? $status['speed_average'] : $status['rate']; if ($status['total'] == $status['current']) { $status['done'] = true; } diff --git a/test/Transfer/Adapter/HttpTest.php b/test/Transfer/Adapter/HttpTest.php index 0fcaf92..8cff5ad 100644 --- a/test/Transfer/Adapter/HttpTest.php +++ b/test/Transfer/Adapter/HttpTest.php @@ -241,10 +241,10 @@ public function testNoUploadInProgress() $this->assertContains('No upload in progress', $status); } - public function testUploadProgressFailure() + public function testUploadProgressFailureForAPC() { - if (!Adapter\Http::isApcAvailable() && !Adapter\Http::isUploadProgressAvailable()) { - $this->markTestSkipped('Whether APC nor UploadExtension available'); + if (! Adapter\Http::isApcAvailable()) { + $this->markTestSkipped('APC extension is unavailable'); } $_GET['progress_key'] = 'mykey'; @@ -255,10 +255,30 @@ public function testUploadProgressFailure() 'rate' => 10, 'id' => 'mykey', 'done' => false, - 'message' => '100B - 100B' - ], $status); + 'message' => '100B - 100B', + ], $status); + } + + public function testUploadProgressFailureForUploadProgressExtension() + { + if (! Adapter\Http::isUploadProgressAvailable()) { + $this->markTestSkipped('uploadprogress extension is unavailable'); + } + $_GET['progress_key'] = 'mykey'; $this->adapter->switchApcToUP(); + + $status = HttpTestMockAdapter::getProgress(); + $this->assertEquals([ + 'total' => 100, + 'current' => 90, + 'rate' => 10, + 'id' => 'mykey', + 'done' => false, + 'message' => '90B - 100B', + ], $status); + + $this->adapter->forceUPFailure(); $status = HttpTestMockAdapter::getProgress($status); $this->assertEquals([ 'total' => 100, @@ -270,8 +290,8 @@ public function testUploadProgressFailure() 'cancel_upload' => true, 'message' => 'The upload has been canceled', 'done' => true, - 'id' => 'mykey' - ], $status); + 'id' => 'mykey', + ], $status); } public function testUploadProgressAdapter() diff --git a/test/Transfer/Adapter/HttpTestMockAdapter.php b/test/Transfer/Adapter/HttpTestMockAdapter.php index 5a15b4b..ff1ddef 100644 --- a/test/Transfer/Adapter/HttpTestMockAdapter.php +++ b/test/Transfer/Adapter/HttpTestMockAdapter.php @@ -18,9 +18,12 @@ */ class HttpTestMockAdapter extends Adapter\Http { + private static $uploadProgressShouldFail; + public function __construct() { - self::$callbackApc = ['ZendTest\File\Transfer\Adapter\HttpTestMockAdapter', 'apcTest']; + static::$callbackApc = [HttpTestMockAdapter::class, 'apcTest']; + self::$uploadProgressShouldFail = false; parent::__construct(); } @@ -41,15 +44,32 @@ public static function isApcAvailable() public static function apcTest($id) { + if (! is_array($id)) { + return [ + 'total' => 100, + 'current' => 100, + 'rate' => 10, + ]; + } + return [ - 'total' => 100, - 'current' => 100, - 'rate' => 10, + 'bytes_total' => 100, + 'bytes_uploaded' => 100, + 'speed_average' => 10, + 'cancel_upload' => true, ]; } public static function uPTest($id) { + if (! self::$uploadProgressShouldFail) { + return [ + 'total' => 100, + 'current' => 90, + 'rate' => 10, + ]; + } + return [ 'bytes_total' => 100, 'bytes_uploaded' => 100, @@ -60,7 +80,12 @@ public static function uPTest($id) public function switchApcToUP() { - self::$callbackApc = null; - self::$callbackUploadProgress = ['ZendTest\File\Transfer\Adapter\HttpTestMockAdapter', 'uPTest']; + static::$callbackApc = null; + static::$callbackUploadProgress = [HttpTestMockAdapter::class, 'uPTest']; + } + + public function forceUPFailure() + { + self::$uploadProgressShouldFail = true; } }