From 54ffc719b215264970f3b2daea4a1037296365fd Mon Sep 17 00:00:00 2001 From: Christopher Martin Date: Fri, 5 Oct 2012 20:56:42 -0400 Subject: [PATCH 1/5] Unit test for AbstractUploadHandler --- src/Upload/AbstractUploadHandler.php | 2 +- test/Upload/AbstractUploadHandlerTest.php | 171 ++++++++++++++++++++++ 2 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 test/Upload/AbstractUploadHandlerTest.php diff --git a/src/Upload/AbstractUploadHandler.php b/src/Upload/AbstractUploadHandler.php index bcd3e60..822f000 100644 --- a/src/Upload/AbstractUploadHandler.php +++ b/src/Upload/AbstractUploadHandler.php @@ -132,7 +132,7 @@ public function getProgress($id) return $status; } $status = $newStatus; - if (!empty($status['done'])) { + if ('' === $status['message']) { $status['message'] = $this->toByteString($status['current']) . " - " . $this->toByteString($status['total']); } diff --git a/test/Upload/AbstractUploadHandlerTest.php b/test/Upload/AbstractUploadHandlerTest.php new file mode 100644 index 0000000..a10a61f --- /dev/null +++ b/test/Upload/AbstractUploadHandlerTest.php @@ -0,0 +1,171 @@ + 1000, + 'current' => 500, + 'rate' => 0, + 'message' => '', + 'done' => false, + ); + $stub = $this->getMockForAbstractClass( + 'Zend\ProgressBar\Upload\AbstractUploadHandler' + ); + $stub->expects($this->any()) + ->method('getUploadProgress') + ->will($this->returnValue($progressData)); + + $progressData['id'] = '123'; + $progressData['message'] = '500B - 1000B'; + $this->assertEquals($progressData, $stub->getProgress('123')); + } + + /** + * @return void + */ + public function testGetNoFileInProgress() + { + $status = array( + 'total' => 0, + 'current' => 0, + 'rate' => 0, + 'message' => 'No upload in progress', + 'done' => true + ); + $stub = $this->getMockForAbstractClass( + 'Zend\ProgressBar\Upload\AbstractUploadHandler' + ); + $stub->expects($this->any()) + ->method('getUploadProgress') + ->will($this->returnValue(false)); + $this->assertEquals($status, $stub->getProgress('123')); + } + + /** + * @return array + */ + public function progressDataProvider() + { + return array( + array(array( + 'total' => 1000, + 'current' => 200, + 'rate' => 0, + 'message' => '', + 'done' => false, + )), + array(array( + 'total' => 1000, + 'current' => 600, + 'rate' => 300, + 'message' => '', + 'done' => false, + )), + array(array( + 'total' => 1000, + 'current' => 1000, + 'rate' => 500, + 'message' => '', + 'done' => true, + )), + ); + } + + /** + * @dataProvider progressDataProvider + * @param array $progressData + * @return void + */ + public function testProgressAdapterNotify($progressData) + { + $adapterStub = $this->getMockForAbstractClass( + 'Zend\ProgressBar\Adapter\AbstractAdapter' + ); + if ($progressData['done']) { + $adapterStub->expects($this->once()) + ->method('finish'); + } else { + $adapterStub->expects($this->once()) + ->method('notify'); + } + + $stub = $this->getMockForAbstractClass( + 'Zend\ProgressBar\Upload\AbstractUploadHandler' + ); + $stub->expects($this->once()) + ->method('getUploadProgress') + ->will($this->returnValue($progressData)); + $stub->setOptions(array( + 'session_namespace' => 'testSession', + 'progress_adapter' => $adapterStub, + )); + + $this->assertEquals('testSession', $stub->getSessionNamespace()); + $this->assertEquals($adapterStub, $stub->getProgressAdapter()); + + $this->assertNotEmpty($stub->getProgress('123')); + } + + /** + * @dataProvider progressDataProvider + * @param array $progressData + * @return void + */ + public function testProgressBarUpdate($progressData) + { + $adapterStub = $this->getMockForAbstractClass( + 'Zend\ProgressBar\Adapter\AbstractAdapter' + ); + if ($progressData['done']) { + $adapterStub->expects($this->once()) + ->method('finish'); + } else { + $adapterStub->expects($this->once()) + ->method('notify'); + } + $progressBar = new ProgressBar( + $adapterStub, 0, $progressData['total'], 'testSession' + ); + + + $stub = $this->getMockForAbstractClass( + 'Zend\ProgressBar\Upload\AbstractUploadHandler' + ); + $stub->expects($this->once()) + ->method('getUploadProgress') + ->will($this->returnValue($progressData)); + $stub->setOptions(array( + 'session_namespace' => 'testSession', + 'progress_adapter' => $progressBar, + )); + + $this->assertEquals('testSession', $stub->getSessionNamespace()); + $this->assertEquals($progressBar, $stub->getProgressAdapter()); + + $this->assertNotEmpty($stub->getProgress('123')); + } +} From 73bca441bcab209da8a27cab7b51b4e55dcca3da Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Thu, 29 Nov 2012 22:14:56 +0100 Subject: [PATCH 2/5] Updated Zend\Feed to use StringUtils --- src/Adapter/Console.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Adapter/Console.php b/src/Adapter/Console.php index e379809..1e577f2 100644 --- a/src/Adapter/Console.php +++ b/src/Adapter/Console.php @@ -12,6 +12,7 @@ use Zend\ProgressBar\Adapter\Exception; use Zend\Stdlib\ErrorHandler; +use Zend\Stdlib\StringUtils; /** * Zend_ProgressBar_Adapter_Console offers a text-based progressbar for console @@ -438,7 +439,13 @@ public function notify($current, $max, $percent, $timeTaken, $timeRemaining, $te break; case self::ELEMENT_TEXT: - $renderedElements[] = \Zend\Text\MultiByte::strPad(substr($text, 0, $this->textWidth), $this->textWidth, ' ', STR_PAD_RIGHT, $this->charset); + $renderedElements[] = StringUtils::getWrapper($this->charset)->strPad( + substr($text, 0, $this->textWidth), + $this->textWidth, + ' ', + \STR_PAD_RIGHT, + $this->charset + ); break; } } From 75e507566b112b2b1faa1187223e20c7fe32f3a9 Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Mon, 31 Dec 2012 17:50:03 +0100 Subject: [PATCH 3/5] Updated consumers after API changes --- src/Adapter/Console.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Adapter/Console.php b/src/Adapter/Console.php index 1e577f2..50a52e3 100644 --- a/src/Adapter/Console.php +++ b/src/Adapter/Console.php @@ -443,8 +443,7 @@ public function notify($current, $max, $percent, $timeTaken, $timeRemaining, $te substr($text, 0, $this->textWidth), $this->textWidth, ' ', - \STR_PAD_RIGHT, - $this->charset + \STR_PAD_RIGHT ); break; } From fa968aa61c246730732d9c80f241b89ec34b9878 Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Sun, 6 Jan 2013 15:24:40 +0100 Subject: [PATCH 4/5] Global namespace not needed for constants --- src/Adapter/Console.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adapter/Console.php b/src/Adapter/Console.php index 50a52e3..42eaacf 100644 --- a/src/Adapter/Console.php +++ b/src/Adapter/Console.php @@ -443,7 +443,7 @@ public function notify($current, $max, $percent, $timeTaken, $timeRemaining, $te substr($text, 0, $this->textWidth), $this->textWidth, ' ', - \STR_PAD_RIGHT + STR_PAD_RIGHT ); break; } From 20f8d57f696cfe204fe95f16cacdf18fb1f4b367 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 1 May 2013 16:42:36 -0500 Subject: [PATCH 5/5] [2.2.0rc1] Release preparation - Updated all component composer.json files to reflect new branch aliases - Updated changelog - Updated readme --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 3474767..8e75fb1 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.1-dev", - "dev-develop": "2.2-dev" + "dev-master": "2.2-dev", + "dev-develop": "2.3-dev" } }, "homepage": "https://github.com/zendframework/zend-progress-bar",