Fix tests and avoid PHP errors in them

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
Côme Chilliet 2021-10-25 16:16:55 +02:00
parent cd72045433
commit 8b271b8a12
No known key found for this signature in database
GPG key ID: A3E2F658B28C760A
8 changed files with 34 additions and 5 deletions

View file

@ -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,

View file

@ -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]

View file

@ -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) {

View file

@ -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);

View file

@ -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);

View file

@ -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,

View file

@ -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);

View file

@ -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);