Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/updated-dependencies'
Browse files Browse the repository at this point in the history
Close #21
  • Loading branch information
weierophinney committed Mar 2, 2016
2 parents 4c0fbc7 + 2cb8709 commit a5bccb3
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 23 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
12 changes: 6 additions & 6 deletions src/Transfer/Adapter/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down Expand Up @@ -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;
}
Expand Down
34 changes: 27 additions & 7 deletions test/Transfer/Adapter/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand All @@ -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()
Expand Down
37 changes: 31 additions & 6 deletions test/Transfer/Adapter/HttpTestMockAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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,
Expand All @@ -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;
}
}

0 comments on commit a5bccb3

Please sign in to comment.