From 865e4ab0ec380b9cd22946233ab685220aaf991f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 5 Jan 2021 08:53:21 +0100 Subject: [PATCH 1/2] Fix writeStream mocking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- tests/lib/Files/ViewTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php index 139516ba37..161e796697 100644 --- a/tests/lib/Files/ViewTest.php +++ b/tests/lib/Files/ViewTest.php @@ -1163,7 +1163,7 @@ class ViewTest extends \Test\TestCase { /** @var \PHPUnit\Framework\MockObject\MockObject|Temporary $storage2 */ $storage2 = $this->getMockBuilder(TemporaryNoCross::class) ->setConstructorArgs([[]]) - ->setMethods(['fopen']) + ->setMethods(['fopen', 'writeStream']) ->getMock(); $storage2->method('writeStream') From 8d9fa73371df5f9dbcdd0b552ad6000cff1ceeb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 5 Jan 2021 09:12:11 +0100 Subject: [PATCH 2/2] Properly handle result when copying with failure and throw in tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/private/Files/Storage/Common.php | 4 ++-- tests/lib/Files/ViewTest.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index cba8afa176..7240a57f93 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -688,9 +688,9 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage { $result = $this->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, true); if ($result) { if ($sourceStorage->is_dir($sourceInternalPath)) { - $result &= $sourceStorage->rmdir($sourceInternalPath); + $result = $result && $sourceStorage->rmdir($sourceInternalPath); } else { - $result &= $sourceStorage->unlink($sourceInternalPath); + $result = $result && $sourceStorage->unlink($sourceInternalPath); } } return $result; diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php index 161e796697..c110d80d02 100644 --- a/tests/lib/Files/ViewTest.php +++ b/tests/lib/Files/ViewTest.php @@ -17,6 +17,7 @@ use OC\Files\View; use OCP\Constants; use OCP\Files\Config\IMountProvider; use OCP\Files\FileInfo; +use OCP\Files\GenericFileException; use OCP\Files\Storage\IStorage; use OCP\Lock\ILockingProvider; use OCP\Lock\LockedException; @@ -1167,7 +1168,7 @@ class ViewTest extends \Test\TestCase { ->getMock(); $storage2->method('writeStream') - ->willReturn(0); + ->willThrowException(new GenericFileException("Failed to copy stream")); $storage1->mkdir('sub'); $storage1->file_put_contents('foo.txt', '0123456789ABCDEFGH');