diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2021-10-25 16:16:55 +0200 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2021-11-23 09:29:01 +0100 |
commit | 8b271b8a123f0f0cbf3a3d81cf9cf3f99a2e642e (patch) | |
tree | 2a9aab48581704506965f8ff7628d25e13fa0042 /tests/Core | |
parent | cd72045433eafc8f73a620239dc5afa6a0a6d84d (diff) | |
download | nextcloud-server-8b271b8a123f0f0cbf3a3d81cf9cf3f99a2e642e.tar.gz nextcloud-server-8b271b8a123f0f0cbf3a3d81cf9cf3f99a2e642e.zip |
Fix tests and avoid PHP errors in them
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'tests/Core')
-rw-r--r-- | tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php | 7 | ||||
-rw-r--r-- | tests/Core/Command/Log/FileTest.php | 3 | ||||
-rw-r--r-- | tests/Core/Command/Preview/RepairTest.php | 7 | ||||
-rw-r--r-- | tests/Core/Controller/AvatarControllerTest.php | 6 | ||||
-rw-r--r-- | tests/Core/Controller/CssControllerTest.php | 6 | ||||
-rw-r--r-- | tests/Core/Controller/GuestAvatarControllerTest.php | 2 | ||||
-rw-r--r-- | tests/Core/Controller/JsControllerTest.php | 6 | ||||
-rw-r--r-- | tests/Core/Controller/PreviewControllerTest.php | 2 |
8 files changed, 34 insertions, 5 deletions
diff --git a/tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php b/tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php index 02cc824ee0c..fc916ad4099 100644 --- a/tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php +++ b/tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php @@ -74,9 +74,12 @@ class ChangeKeyStorageRootTest extends TestCase { $this->outputInterface = $this->getMockBuilder(OutputInterface::class)->getMock(); $this->userInterface = $this->getMockBuilder(UserInterface::class)->getMock(); - $outputFormatterInterface = $this->getMockBuilder(OutputFormatterInterface::class)->getMock(); + /* We need format method to return a string */ + $outputFormatter = $this->createMock(OutputFormatterInterface::class); + $outputFormatter->method('format')->willReturnArgument(0); + $this->outputInterface->expects($this->any())->method('getFormatter') - ->willReturn($outputFormatterInterface); + ->willReturn($outputFormatter); $this->changeKeyStorageRoot = new ChangeKeyStorageRoot( $this->view, diff --git a/tests/Core/Command/Log/FileTest.php b/tests/Core/Command/Log/FileTest.php index 1a8a86759f5..103888de287 100644 --- a/tests/Core/Command/Log/FileTest.php +++ b/tests/Core/Command/Log/FileTest.php @@ -51,6 +51,7 @@ class FileTest extends TestCase { } public function testEnable() { + $this->config->method('getSystemValue')->willReturnArgument(1); $this->consoleInput->method('getOption') ->willReturnMap([ ['enable', 'true'] @@ -63,6 +64,7 @@ class FileTest extends TestCase { } public function testChangeFile() { + $this->config->method('getSystemValue')->willReturnArgument(1); $this->consoleInput->method('getOption') ->willReturnMap([ ['file', '/foo/bar/file.log'] @@ -87,6 +89,7 @@ class FileTest extends TestCase { * @dataProvider changeRotateSizeProvider */ public function testChangeRotateSize($optionValue, $configValue) { + $this->config->method('getSystemValue')->willReturnArgument(1); $this->consoleInput->method('getOption') ->willReturnMap([ ['rotate-size', $optionValue] diff --git a/tests/Core/Command/Preview/RepairTest.php b/tests/Core/Command/Preview/RepairTest.php index c37e57f848c..a6591745817 100644 --- a/tests/Core/Command/Preview/RepairTest.php +++ b/tests/Core/Command/Preview/RepairTest.php @@ -68,9 +68,14 @@ class RepairTest extends TestCase { $this->output->expects($this->any()) ->method('section') ->willReturn($this->output); + + /* We need format method to return a string */ + $outputFormatter = $this->createMock(OutputFormatterInterface::class); + $outputFormatter->method('format')->willReturnArgument(0); + $this->output->expects($this->any()) ->method('getFormatter') - ->willReturn($this->getMockBuilder(OutputFormatterInterface::class)->getMock()); + ->willReturn($outputFormatter); $this->output->expects($this->any()) ->method('writeln') ->willReturnCallback(function ($line) use ($self) { diff --git a/tests/Core/Controller/AvatarControllerTest.php b/tests/Core/Controller/AvatarControllerTest.php index d6c4ea6217c..35d89c24a45 100644 --- a/tests/Core/Controller/AvatarControllerTest.php +++ b/tests/Core/Controller/AvatarControllerTest.php @@ -119,6 +119,8 @@ class AvatarControllerTest extends \Test\TestCase { $this->avatarFile->method('getContent')->willReturn('image data'); $this->avatarFile->method('getMimeType')->willReturn('image type'); $this->avatarFile->method('getEtag')->willReturn('my etag'); + $this->avatarFile->method('getName')->willReturn('my name'); + $this->avatarFile->method('getMTime')->willReturn(42); } protected function tearDown(): void { @@ -290,7 +292,7 @@ class AvatarControllerTest extends \Test\TestCase { */ public function testPostAvatarFile() { //Create temp file - $fileName = tempnam(null, "avatarTest"); + $fileName = tempnam('', "avatarTest"); $copyRes = copy(\OC::$SERVERROOT.'/tests/data/testimage.jpg', $fileName); $this->assertTrue($copyRes); @@ -328,7 +330,7 @@ class AvatarControllerTest extends \Test\TestCase { */ public function testPostAvatarFileGif() { //Create temp file - $fileName = tempnam(null, "avatarTest"); + $fileName = tempnam('', "avatarTest"); $copyRes = copy(\OC::$SERVERROOT.'/tests/data/testimage.gif', $fileName); $this->assertTrue($copyRes); diff --git a/tests/Core/Controller/CssControllerTest.php b/tests/Core/Controller/CssControllerTest.php index 1179bc0c070..d2a791ec1b0 100644 --- a/tests/Core/Controller/CssControllerTest.php +++ b/tests/Core/Controller/CssControllerTest.php @@ -102,6 +102,8 @@ class CssControllerTest extends TestCase { public function testGetFile() { $folder = $this->createMock(ISimpleFolder::class); $file = $this->createMock(ISimpleFile::class); + $file->method('getName')->willReturn('my name'); + $file->method('getMTime')->willReturn(42); $this->appData->method('getFolder') ->with('myapp') ->willReturn($folder); @@ -125,6 +127,8 @@ class CssControllerTest extends TestCase { public function testGetGzipFile() { $folder = $this->createMock(ISimpleFolder::class); $gzipFile = $this->createMock(ISimpleFile::class); + $gzipFile->method('getName')->willReturn('my name'); + $gzipFile->method('getMTime')->willReturn(42); $this->appData->method('getFolder') ->with('myapp') ->willReturn($folder); @@ -153,6 +157,8 @@ class CssControllerTest extends TestCase { public function testGetGzipFileNotFound() { $folder = $this->createMock(ISimpleFolder::class); $file = $this->createMock(ISimpleFile::class); + $file->method('getName')->willReturn('my name'); + $file->method('getMTime')->willReturn(42); $this->appData->method('getFolder') ->with('myapp') ->willReturn($folder); diff --git a/tests/Core/Controller/GuestAvatarControllerTest.php b/tests/Core/Controller/GuestAvatarControllerTest.php index 8870faac4c7..e14a5416c49 100644 --- a/tests/Core/Controller/GuestAvatarControllerTest.php +++ b/tests/Core/Controller/GuestAvatarControllerTest.php @@ -56,6 +56,8 @@ class GuestAvatarControllerTest extends \Test\TestCase { $this->avatar = $this->getMockBuilder(IAvatar::class)->getMock(); $this->avatarManager = $this->getMockBuilder(IAvatarManager::class)->getMock(); $this->file = $this->getMockBuilder(ISimpleFile::class)->getMock(); + $this->file->method('getName')->willReturn('my name'); + $this->file->method('getMTime')->willReturn(42); $this->guestAvatarController = new GuestAvatarController( 'core', $this->request, diff --git a/tests/Core/Controller/JsControllerTest.php b/tests/Core/Controller/JsControllerTest.php index 01228a6a93e..3f76e19efc9 100644 --- a/tests/Core/Controller/JsControllerTest.php +++ b/tests/Core/Controller/JsControllerTest.php @@ -102,6 +102,8 @@ class JsControllerTest extends TestCase { public function testGetFile() { $folder = $this->createMock(ISimpleFolder::class); $file = $this->createMock(ISimpleFile::class); + $file->method('getName')->willReturn('my name'); + $file->method('getMTime')->willReturn(42); $this->appData->method('getFolder') ->with('myapp') ->willReturn($folder); @@ -125,6 +127,8 @@ class JsControllerTest extends TestCase { public function testGetGzipFile() { $folder = $this->createMock(ISimpleFolder::class); $gzipFile = $this->createMock(ISimpleFile::class); + $gzipFile->method('getName')->willReturn('my name'); + $gzipFile->method('getMTime')->willReturn(42); $this->appData->method('getFolder') ->with('myapp') ->willReturn($folder); @@ -153,6 +157,8 @@ class JsControllerTest extends TestCase { public function testGetGzipFileNotFound() { $folder = $this->createMock(ISimpleFolder::class); $file = $this->createMock(ISimpleFile::class); + $file->method('getName')->willReturn('my name'); + $file->method('getMTime')->willReturn(42); $this->appData->method('getFolder') ->with('myapp') ->willReturn($folder); diff --git a/tests/Core/Controller/PreviewControllerTest.php b/tests/Core/Controller/PreviewControllerTest.php index e1d1529c655..704ddade7a4 100644 --- a/tests/Core/Controller/PreviewControllerTest.php +++ b/tests/Core/Controller/PreviewControllerTest.php @@ -212,6 +212,8 @@ class PreviewControllerTest extends \Test\TestCase { ->willReturn(true); $preview = $this->createMock(ISimpleFile::class); + $preview->method('getName')->willReturn('my name'); + $preview->method('getMTime')->willReturn(42); $this->previewManager->method('getPreview') ->with($this->equalTo($file), 10, 10, false, $this->equalTo('myMode')) ->willReturn($preview); |