diff --git a/lib/private/legacy/OC_Helper.php b/lib/private/legacy/OC_Helper.php index 4388f775623..abd2dc9cd78 100644 --- a/lib/private/legacy/OC_Helper.php +++ b/lib/private/legacy/OC_Helper.php @@ -117,18 +117,6 @@ class OC_Helper { return false; } - /** - * copy the contents of one stream to another - * - * @param resource $source - * @param resource $target - * @return array the number of bytes copied and result - * @deprecated 5.0.0 - Use \OCP\Files::streamCopy - */ - public static function streamCopy($source, $target) { - return \OCP\Files::streamCopy($source, $target, true); - } - /** * Adds a suffix to the name in case the file exists * diff --git a/tests/lib/Files/Storage/Wrapper/QuotaTest.php b/tests/lib/Files/Storage/Wrapper/QuotaTest.php index 2878fe6ca92..f83f9ed7f6b 100644 --- a/tests/lib/Files/Storage/Wrapper/QuotaTest.php +++ b/tests/lib/Files/Storage/Wrapper/QuotaTest.php @@ -115,7 +115,7 @@ class QuotaTest extends \Test\Files\Storage\Storage { $instance = $this->getLimitedStorage(16); $inputStream = fopen('data://text/plain,foobarqwerty', 'r'); $outputStream = $instance->fopen('files/foo', 'w+'); - [$count, $result] = \OC_Helper::streamCopy($inputStream, $outputStream); + [$count, $result] = Files::streamCopy($inputStream, $outputStream, true); $this->assertEquals(12, $count); $this->assertTrue($result); fclose($inputStream); @@ -126,7 +126,7 @@ class QuotaTest extends \Test\Files\Storage\Storage { $instance = $this->getLimitedStorage(9); $inputStream = fopen('data://text/plain,foobarqwerty', 'r'); $outputStream = $instance->fopen('files/foo', 'w+'); - [$count, $result] = \OC_Helper::streamCopy($inputStream, $outputStream); + [$count, $result] = Files::streamCopy($inputStream, $outputStream, true); $this->assertEquals(9, $count); $this->assertFalse($result); fclose($inputStream); diff --git a/tests/lib/FilesTest.php b/tests/lib/FilesTest.php index 2ba6ce2666b..5b1bc59d2d9 100644 --- a/tests/lib/FilesTest.php +++ b/tests/lib/FilesTest.php @@ -39,4 +39,36 @@ class FilesTest extends TestCase { Files::rmdirr($baseDir); $this->assertFalse(file_exists($baseDir)); } + + #[\PHPUnit\Framework\Attributes\DataProvider('streamCopyDataProvider')] + public function testStreamCopy($expectedCount, $expectedResult, $source, $target): void { + if (is_string($source)) { + $source = fopen($source, 'r'); + } + if (is_string($target)) { + $target = fopen($target, 'w'); + } + + [$count, $result] = Files::streamCopy($source, $target, true); + + if (is_resource($source)) { + fclose($source); + } + if (is_resource($target)) { + fclose($target); + } + + $this->assertSame($expectedCount, $count); + $this->assertSame($expectedResult, $result); + } + + + public static function streamCopyDataProvider(): array { + return [ + [0, false, false, false], + [0, false, \OC::$SERVERROOT . '/tests/data/lorem.txt', false], + [filesize(\OC::$SERVERROOT . '/tests/data/lorem.txt'), true, \OC::$SERVERROOT . '/tests/data/lorem.txt', \OC::$SERVERROOT . '/tests/data/lorem-copy.txt'], + [3670, true, \OC::$SERVERROOT . '/tests/data/testimage.png', \OC::$SERVERROOT . '/tests/data/testimage-copy.png'], + ]; + } } diff --git a/tests/lib/LegacyHelperTest.php b/tests/lib/LegacyHelperTest.php index c18f929e40c..0123cab2e39 100644 --- a/tests/lib/LegacyHelperTest.php +++ b/tests/lib/LegacyHelperTest.php @@ -12,18 +12,6 @@ use OC\Files\View; use OC_Helper; class LegacyHelperTest extends \Test\TestCase { - /** @var string */ - private $originalWebRoot; - - protected function setUp(): void { - $this->originalWebRoot = \OC::$WEBROOT; - } - - protected function tearDown(): void { - // Reset webRoot - \OC::$WEBROOT = $this->originalWebRoot; - } - public function testBuildNotExistingFileNameForView(): void { $viewMock = $this->createMock(View::class); $this->assertEquals('/filename', OC_Helper::buildNotExistingFileNameForView('/', 'filename', $viewMock)); @@ -115,36 +103,4 @@ class LegacyHelperTest extends \Test\TestCase { ]); $this->assertEquals('dir/filename(1) (2) (4).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (2) (3).ext', $viewMock)); } - - #[\PHPUnit\Framework\Attributes\DataProvider('streamCopyDataProvider')] - public function testStreamCopy($expectedCount, $expectedResult, $source, $target): void { - if (is_string($source)) { - $source = fopen($source, 'r'); - } - if (is_string($target)) { - $target = fopen($target, 'w'); - } - - [$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); - } - - - public static function streamCopyDataProvider(): array { - return [ - [0, false, false, false], - [0, false, \OC::$SERVERROOT . '/tests/data/lorem.txt', false], - [filesize(\OC::$SERVERROOT . '/tests/data/lorem.txt'), true, \OC::$SERVERROOT . '/tests/data/lorem.txt', \OC::$SERVERROOT . '/tests/data/lorem-copy.txt'], - [3670, true, \OC::$SERVERROOT . '/tests/data/testimage.png', \OC::$SERVERROOT . '/tests/data/testimage-copy.png'], - ]; - } }