mirror of
https://github.com/nextcloud/server.git
synced 2026-02-03 20:41:22 -05:00
Merge pull request #55371 from nextcloud/carl/remove-oc-helper-streamCopy
refactor: Remove OC_Helper::streamCopy
This commit is contained in:
commit
10e3192c2f
4 changed files with 34 additions and 58 deletions
|
|
@ -105,18 +105,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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue