From 703e7506dd7544271090711baa5ba35721b66599 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20M=C3=BCller?= Date: Mon, 14 Oct 2013 21:33:23 +0200 Subject: [PATCH] streamCopy() should return proper structure. Callers of streamCopy() expect an array to be returned containing count and result. Conflicts: lib/helper.php tests/lib/helper.php --- lib/helper.php | 6 +++--- tests/lib/helper.php | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/lib/helper.php b/lib/helper.php index ddd6ce9a149..e78428eebca 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -517,11 +517,11 @@ class OC_Helper { * copy the contents of one stream to another * @param resource $source * @param resource $target - * @return int the number of bytes copied + * @return array the number of bytes copied and result */ public static function streamCopy($source, $target) { - if(!$source or !$target) { - return false; + if (!$source or !$target) { + return array(0, false); } $result = true; $count = 0; diff --git a/tests/lib/helper.php b/tests/lib/helper.php index 336e8f8b3c5..7de63b74b49 100644 --- a/tests/lib/helper.php +++ b/tests/lib/helper.php @@ -137,4 +137,38 @@ class Test_Helper extends PHPUnit_Framework_TestCase { $result = OC_Helper::recursiveArraySearch($haystack, "NotFound"); $this->assertFalse($result); } + + /** + * @dataProvider streamCopyDataProvider + */ + public function testStreamCopy($expectedCount, $expectedResult, $source, $target) { + + if (is_string($source)) { + $source = fopen($source, 'r'); + } + if (is_string($target)) { + $target = fopen($target, 'w'); + } + + list($count, $result) = \OC_Helper::streamCopy($source, $target); + + if (is_resource($source)) { + fclose($source); + } + if (is_resource($target)) { + fclose($target); + } + + $this->assertSame($expectedCount, $count); + $this->assertSame($expectedResult, $result); + } + + + function streamCopyDataProvider() { + return array( + array(0, false, false, false), + array(0, false, \OC::$SERVERROOT . '/tests/data/lorem.txt', false), + array(446, true, \OC::$SERVERROOT . '/tests/data/lorem.txt', \OC::$SERVERROOT . '/tests/data/lorem-copy.txt'), + ); + } } -- 2.39.5