mirror of
https://github.com/nextcloud/server.git
synced 2026-06-10 09:13:19 -04:00
Fix tests and avoid PHP errors in them
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
cd72045433
commit
8b271b8a12
8 changed files with 34 additions and 5 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue