Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tests and avoid PHP errors in them
Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Nov 23, 2021
commit 8b271b8a123f0f0cbf3a3d81cf9cf3f99a2e642e
7 changes: 5 additions & 2 deletions tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ protected function setUp(): void {
$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,
Expand Down
3 changes: 3 additions & 0 deletions tests/Core/Command/Log/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ protected function setUp(): void {
}

public function testEnable() {
$this->config->method('getSystemValue')->willReturnArgument(1);
$this->consoleInput->method('getOption')
->willReturnMap([
['enable', 'true']
Expand All @@ -63,6 +64,7 @@ public function testEnable() {
}

public function testChangeFile() {
$this->config->method('getSystemValue')->willReturnArgument(1);
$this->consoleInput->method('getOption')
->willReturnMap([
['file', '/foo/bar/file.log']
Expand All @@ -87,6 +89,7 @@ public function changeRotateSizeProvider() {
* @dataProvider changeRotateSizeProvider
*/
public function testChangeRotateSize($optionValue, $configValue) {
$this->config->method('getSystemValue')->willReturnArgument(1);
$this->consoleInput->method('getOption')
->willReturnMap([
['rotate-size', $optionValue]
Expand Down
7 changes: 6 additions & 1 deletion tests/Core/Command/Preview/RepairTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,14 @@ protected function setUp(): void {
$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) {
Expand Down
6 changes: 4 additions & 2 deletions tests/Core/Controller/AvatarControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ protected function setUp(): void {
$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 {
Expand Down Expand Up @@ -290,7 +292,7 @@ public function testPostAvatarNoPathOrImage() {
*/
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);

Expand Down Expand Up @@ -328,7 +330,7 @@ public function testPostAvatarInvalidFile() {
*/
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);

Expand Down
6 changes: 6 additions & 0 deletions tests/Core/Controller/CssControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public function testNoCssFile() {
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);
Expand All @@ -125,6 +127,8 @@ public function testGetFile() {
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);
Expand Down Expand Up @@ -153,6 +157,8 @@ public function testGetGzipFile() {
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);
Expand Down
2 changes: 2 additions & 0 deletions tests/Core/Controller/GuestAvatarControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ protected function setUp(): void {
$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,
Expand Down
6 changes: 6 additions & 0 deletions tests/Core/Controller/JsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public function testNoCssFile() {
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);
Expand All @@ -125,6 +127,8 @@ public function testGetFile() {
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);
Expand Down Expand Up @@ -153,6 +157,8 @@ public function testGetGzipFile() {
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);
Expand Down
2 changes: 2 additions & 0 deletions tests/Core/Controller/PreviewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ public function testValidPreview() {
->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);
Expand Down