summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2022-06-22 12:05:26 +0200
committerCarl Schwan <carl@carlschwan.eu>2022-07-14 17:20:51 +0200
commit19a36b58a69f9a8cc31da213657fdf828d9fdb3c (patch)
tree0a1c6b732a0b5548450ae3114e3fe8ebbaf6eb6d /tests
parentb282fe1e6f5587a6440d170df245ad5acb8dc976 (diff)
downloadnextcloud-server-19a36b58a69f9a8cc31da213657fdf828d9fdb3c.tar.gz
nextcloud-server-19a36b58a69f9a8cc31da213657fdf828d9fdb3c.zip
Add typing to SimpleFS
- Fix putContent sometimes return a bool and sometimes nothing Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Avatar/UserAvatarTest.php19
-rw-r--r--tests/lib/Preview/GeneratorTest.php8
2 files changed, 19 insertions, 8 deletions
diff --git a/tests/lib/Avatar/UserAvatarTest.php b/tests/lib/Avatar/UserAvatarTest.php
index dd5f25163f2..5e903007239 100644
--- a/tests/lib/Avatar/UserAvatarTest.php
+++ b/tests/lib/Avatar/UserAvatarTest.php
@@ -11,7 +11,6 @@ namespace Test\Avatar;
use OC\Files\SimpleFS\SimpleFolder;
use OC\User\User;
use OCP\Files\File;
-use OCP\Files\Folder;
use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\IConfig;
@@ -19,7 +18,7 @@ use OCP\IL10N;
use Psr\Log\LoggerInterface;
class UserAvatarTest extends \Test\TestCase {
- /** @var Folder | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var SimpleFolder | \PHPUnit\Framework\MockObject\MockObject */
private $folder;
/** @var \OC\Avatar\UserAvatar */
@@ -91,12 +90,13 @@ class UserAvatarTest extends \Test\TestCase {
->willReturnMap([
['avatar.jpg', true],
['avatar.128.jpg', true],
+ ['generated', false],
]);
$expected = new \OC_Image();
$expected->loadFromFile(\OC::$SERVERROOT . '/tests/data/testavatar.png');
- $file = $this->createMock(File::class);
+ $file = $this->createMock(ISimpleFile::class);
$file->method('getContent')->willReturn($expected->data());
$this->folder->method('getFile')->with('avatar.128.jpg')->willReturn($file);
@@ -107,12 +107,13 @@ class UserAvatarTest extends \Test\TestCase {
$this->folder->method('fileExists')
->willReturnMap([
['avatar.jpg', true],
+ ['generated', false],
]);
$expected = new \OC_Image();
$expected->loadFromFile(\OC::$SERVERROOT . '/tests/data/testavatar.png');
- $file = $this->createMock(File::class);
+ $file = $this->createMock(ISimpleFile::class);
$file->method('getContent')->willReturn($expected->data());
$this->folder->method('getFile')->with('avatar.jpg')->willReturn($file);
@@ -122,8 +123,10 @@ class UserAvatarTest extends \Test\TestCase {
public function testGetAvatarNoSizeMatch() {
$this->folder->method('fileExists')
->willReturnMap([
+ ['avatar.jpg', false],
['avatar.png', true],
['avatar.32.png', false],
+ ['generated', false],
]);
$expected = new \OC_Image();
@@ -132,7 +135,7 @@ class UserAvatarTest extends \Test\TestCase {
$expected2->loadFromFile(\OC::$SERVERROOT . '/tests/data/testavatar.png');
$expected2->resize(32);
- $file = $this->createMock(File::class);
+ $file = $this->createMock(ISimpleFile::class);
$file->method('getContent')->willReturn($expected->data());
$this->folder->method('getFile')
@@ -146,7 +149,7 @@ class UserAvatarTest extends \Test\TestCase {
}
);
- $newFile = $this->createMock(File::class);
+ $newFile = $this->createMock(ISimpleFile::class);
$newFile->expects($this->once())
->method('putContent')
->with($expected2->data());
@@ -202,12 +205,12 @@ class UserAvatarTest extends \Test\TestCase {
$this->folder->method('getDirectoryListing')
->willReturn([$avatarFileJPG, $avatarFilePNG, $resizedAvatarFile]);
- $generated = $this->createMock(File::class);
+ $generated = $this->createMock(ISimpleFile::class);
$this->folder->method('getFile')
->with('generated')
->willReturn($generated);
- $newFile = $this->createMock(File::class);
+ $newFile = $this->createMock(ISimpleFile::class);
$this->folder->expects($this->once())
->method('newFile')
->with('avatar.png')
diff --git a/tests/lib/Preview/GeneratorTest.php b/tests/lib/Preview/GeneratorTest.php
index 43f5c1e0d36..1e38afd7744 100644
--- a/tests/lib/Preview/GeneratorTest.php
+++ b/tests/lib/Preview/GeneratorTest.php
@@ -95,6 +95,7 @@ class GeneratorTest extends \Test\TestCase {
$maxPreview = $this->createMock(ISimpleFile::class);
$maxPreview->method('getName')
->willReturn('1000-1000-max.png');
+ $maxPreview->method('getSize')->willReturn(1000);
$maxPreview->method('getMimeType')
->willReturn('image/png');
@@ -102,6 +103,7 @@ class GeneratorTest extends \Test\TestCase {
->willReturn([$maxPreview]);
$previewFile = $this->createMock(ISimpleFile::class);
+ $previewFile->method('getSize')->willReturn(1000);
$previewFolder->method('getFile')
->with($this->equalTo('256-256.png'))
@@ -203,8 +205,10 @@ class GeneratorTest extends \Test\TestCase {
$maxPreview = $this->createMock(ISimpleFile::class);
$maxPreview->method('getName')->willReturn('2048-2048-max.png');
$maxPreview->method('getMimeType')->willReturn('image/png');
+ $maxPreview->method('getSize')->willReturn(1000);
$previewFile = $this->createMock(ISimpleFile::class);
+ $previewFile->method('getSize')->willReturn(1000);
$previewFolder->method('getDirectoryListing')
->willReturn([]);
@@ -313,6 +317,7 @@ class GeneratorTest extends \Test\TestCase {
$maxPreview = $this->createMock(ISimpleFile::class);
$maxPreview->method('getName')
->willReturn('2048-2048-max.png');
+ $maxPreview->method('getSize')->willReturn(1000);
$maxPreview->method('getMimeType')
->willReturn('image/png');
@@ -320,6 +325,7 @@ class GeneratorTest extends \Test\TestCase {
->willReturn([$maxPreview]);
$preview = $this->createMock(ISimpleFile::class);
+ $preview->method('getSize')->willReturn(1000);
$previewFolder->method('getFile')
->with($this->equalTo('1024-512-crop.png'))
->willReturn($preview);
@@ -471,6 +477,7 @@ class GeneratorTest extends \Test\TestCase {
->willReturn($maxX . '-' . $maxY . '-max.png');
$maxPreview->method('getMimeType')
->willReturn('image/png');
+ $maxPreview->method('getSize')->willReturn(1000);
$previewFolder->method('getDirectoryListing')
->willReturn([$maxPreview]);
@@ -490,6 +497,7 @@ class GeneratorTest extends \Test\TestCase {
->willReturn($image);
$preview = $this->createMock(ISimpleFile::class);
+ $preview->method('getSize')->willReturn(1000);
$previewFolder->method('newFile')
->with($this->equalTo($filename))
->willReturn($preview);