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

Commit a5bccb3

Browse files
committed
Merge branch 'hotfix/updated-dependencies'
Close #21
2 parents 4c0fbc7 + 2cb8709 commit a5bccb3

File tree

6 files changed

+71
-23
lines changed

6 files changed

+71
-23
lines changed

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ before_install:
4747
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi
4848
- if [[ $ZEND_SERVICEMANAGER_VERSION != '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:$ZEND_SERVICEMANAGER_VERSION" ; fi
4949
- if [[ $ZEND_SERVICEMANAGER_VERSION == '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:^3.0.3" ; fi
50-
- if [[ $ZEND_SERVICEMANAGER_VERSION == '' ]]; then composer remove --dev --no-update zendframework/zend-progressbar ; fi
5150

5251
install:
5352
- travis_retry composer install --no-interaction --ignore-platform-reqs

CHANGELOG.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5-
## 2.6.1 - TBD
5+
## 2.6.1 - 2016-03-02
66

77
### Added
88

@@ -18,7 +18,10 @@ All notable changes to this project will be documented in this file, in reverse
1818

1919
### Fixed
2020

21-
- Nothing.
21+
- [#21](https://github.com/zendframework/zend-file/pull/21) updates the codebase
22+
to re-enable tests against zend-progressbar, and fixes static calls inside
23+
`Zend\File\Transfer\Adapter\Http::getProgress` for testing APC and/or
24+
uploadprogress availability to ensure they work correctly.
2225

2326
## 2.6.0 - 2016-02-17
2427

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
"require-dev": {
2020
"zendframework/zend-filter": "^2.6.1",
2121
"zendframework/zend-i18n": "^2.6",
22+
"zendframework/zend-progressbar": "^2.5.2",
2223
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3",
24+
"zendframework/zend-session": "^2.6.2",
2325
"zendframework/zend-validator": "^2.6",
24-
"zendframework/zend-progressbar": "~2.5",
2526
"fabpot/php-cs-fixer": "1.7.*",
2627
"phpunit/PHPUnit": "~4.0"
2728
},

src/Transfer/Adapter/Http.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public function isUploaded($files = null)
288288
*/
289289
public static function getProgress($id = null)
290290
{
291-
if (!static::isApcAvailable() && !static::isUploadProgressAvailable()) {
291+
if (!self::isApcAvailable() && !self::isUploadProgressAvailable()) {
292292
throw new Exception\PhpEnvironmentException('Neither APC nor UploadProgress extension installed');
293293
}
294294

@@ -332,18 +332,18 @@ public static function getProgress($id = null)
332332
}
333333

334334
if (!empty($id)) {
335-
if (static::isApcAvailable()) {
335+
if (self::isApcAvailable()) {
336336
$call = call_user_func(static::$callbackApc, ini_get('apc.rfc1867_prefix') . $id);
337337
if (is_array($call)) {
338338
$status = $call + $status;
339339
}
340-
} elseif (static::isUploadProgressAvailable()) {
340+
} elseif (self::isUploadProgressAvailable()) {
341341
$call = call_user_func(static::$callbackUploadProgress, $id);
342342
if (is_array($call)) {
343343
$status = $call + $status;
344-
$status['total'] = $status['bytes_total'];
345-
$status['current'] = $status['bytes_uploaded'];
346-
$status['rate'] = $status['speed_average'];
344+
$status['total'] = isset($status['bytes_total']) ? $status['bytes_total'] : $status['total'];
345+
$status['current'] = isset($status['bytes_uploaded']) ? $status['bytes_uploaded'] : $status['current'];
346+
$status['rate'] = isset($status['speed_average']) ? $status['speed_average'] : $status['rate'];
347347
if ($status['total'] == $status['current']) {
348348
$status['done'] = true;
349349
}

test/Transfer/Adapter/HttpTest.php

+27-7
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ public function testNoUploadInProgress()
241241
$this->assertContains('No upload in progress', $status);
242242
}
243243

244-
public function testUploadProgressFailure()
244+
public function testUploadProgressFailureForAPC()
245245
{
246-
if (!Adapter\Http::isApcAvailable() && !Adapter\Http::isUploadProgressAvailable()) {
247-
$this->markTestSkipped('Whether APC nor UploadExtension available');
246+
if (! Adapter\Http::isApcAvailable()) {
247+
$this->markTestSkipped('APC extension is unavailable');
248248
}
249249

250250
$_GET['progress_key'] = 'mykey';
@@ -255,10 +255,30 @@ public function testUploadProgressFailure()
255255
'rate' => 10,
256256
'id' => 'mykey',
257257
'done' => false,
258-
'message' => '100B - 100B'
259-
], $status);
258+
'message' => '100B - 100B',
259+
], $status);
260+
}
261+
262+
public function testUploadProgressFailureForUploadProgressExtension()
263+
{
264+
if (! Adapter\Http::isUploadProgressAvailable()) {
265+
$this->markTestSkipped('uploadprogress extension is unavailable');
266+
}
260267

268+
$_GET['progress_key'] = 'mykey';
261269
$this->adapter->switchApcToUP();
270+
271+
$status = HttpTestMockAdapter::getProgress();
272+
$this->assertEquals([
273+
'total' => 100,
274+
'current' => 90,
275+
'rate' => 10,
276+
'id' => 'mykey',
277+
'done' => false,
278+
'message' => '90B - 100B',
279+
], $status);
280+
281+
$this->adapter->forceUPFailure();
262282
$status = HttpTestMockAdapter::getProgress($status);
263283
$this->assertEquals([
264284
'total' => 100,
@@ -270,8 +290,8 @@ public function testUploadProgressFailure()
270290
'cancel_upload' => true,
271291
'message' => 'The upload has been canceled',
272292
'done' => true,
273-
'id' => 'mykey'
274-
], $status);
293+
'id' => 'mykey',
294+
], $status);
275295
}
276296

277297
public function testUploadProgressAdapter()

test/Transfer/Adapter/HttpTestMockAdapter.php

+31-6
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
*/
1919
class HttpTestMockAdapter extends Adapter\Http
2020
{
21+
private static $uploadProgressShouldFail;
22+
2123
public function __construct()
2224
{
23-
self::$callbackApc = ['ZendTest\File\Transfer\Adapter\HttpTestMockAdapter', 'apcTest'];
25+
static::$callbackApc = [HttpTestMockAdapter::class, 'apcTest'];
26+
self::$uploadProgressShouldFail = false;
2427
parent::__construct();
2528
}
2629

@@ -41,15 +44,32 @@ public static function isApcAvailable()
4144

4245
public static function apcTest($id)
4346
{
47+
if (! is_array($id)) {
48+
return [
49+
'total' => 100,
50+
'current' => 100,
51+
'rate' => 10,
52+
];
53+
}
54+
4455
return [
45-
'total' => 100,
46-
'current' => 100,
47-
'rate' => 10,
56+
'bytes_total' => 100,
57+
'bytes_uploaded' => 100,
58+
'speed_average' => 10,
59+
'cancel_upload' => true,
4860
];
4961
}
5062

5163
public static function uPTest($id)
5264
{
65+
if (! self::$uploadProgressShouldFail) {
66+
return [
67+
'total' => 100,
68+
'current' => 90,
69+
'rate' => 10,
70+
];
71+
}
72+
5373
return [
5474
'bytes_total' => 100,
5575
'bytes_uploaded' => 100,
@@ -60,7 +80,12 @@ public static function uPTest($id)
6080

6181
public function switchApcToUP()
6282
{
63-
self::$callbackApc = null;
64-
self::$callbackUploadProgress = ['ZendTest\File\Transfer\Adapter\HttpTestMockAdapter', 'uPTest'];
83+
static::$callbackApc = null;
84+
static::$callbackUploadProgress = [HttpTestMockAdapter::class, 'uPTest'];
85+
}
86+
87+
public function forceUPFailure()
88+
{
89+
self::$uploadProgressShouldFail = true;
6590
}
6691
}

0 commit comments

Comments
 (0)