Skip to content

Commit

Permalink
Fix many tests and warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
  • Loading branch information
CarlSchwan committed Jul 18, 2022
1 parent 06e1aa9 commit d24ef26
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 21 deletions.
15 changes: 9 additions & 6 deletions apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ class ExpireTrashTest extends TestCase {
/** @var IJobList|MockObject */
private $jobList;

/** @var LoggerInterface|MockObject */
private $logger;

/** @var ITimeFactory|MockObject */
private $time;

Expand All @@ -61,8 +58,10 @@ protected function setUp(): void {
$this->userManager = $this->createMock(IUserManager::class);
$this->expiration = $this->createMock(Expiration::class);
$this->jobList = $this->createMock(IJobList::class);
$this->logger = $this->createMock(ILogger::class);

$this->time = $this->createMock(ITimeFactory::class);
$this->time->method('getTime')
->willReturn(99999999999);

$this->jobList->expects($this->once())
->method('setLastRun');
Expand All @@ -71,8 +70,12 @@ protected function setUp(): void {
}

public function testConstructAndRun(): void {
$job = new ExpireTrash($this->config, $this->userManager, $this->expiration);
$job->execute($this->jobList, $this->logger);
$this->config->method('getAppValue')
->with('files_trashbin', 'background_job_expire_trash', 'yes')
->willReturn('yes');

$job = new ExpireTrash($this->config, $this->userManager, $this->expiration, $this->time);
$job->start($this->jobList);
}

public function testBackgroundJobDeactivated(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
Expand Down Expand Up @@ -68,7 +67,12 @@ public function testBackgroundJobDeactivated(): void {
$this->expiration->expects($this->never())
->method('getMaxAgeAsTimestamp');

$job = new ExpireVersions($this->config, $this->userManager, $this->expiration, $this->createMock(ITimeFactory::class));
$timeFactory = $this->createMock(ITimeFactory::class);
$timeFactory->method('getTime')
->with()
->willReturn(99999999999);

$job = new ExpireVersions($this->config, $this->userManager, $this->expiration, $timeFactory);
$job->start($this->jobList);
}
}
29 changes: 18 additions & 11 deletions apps/updatenotification/tests/Settings/AdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@
use OCP\IDateTimeFormatter;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\L10N\ILanguageIterator;
use OCP\Support\Subscription\IRegistry;
use OCP\UserInterface;
use OCP\User\Backend\ICountUsersBackend;
use OCP\Util;
use Test\TestCase;
use OCP\IUserManager;
use OC\User\Backend;
use Psr\Log\LoggerInterface;
use Test\TestCase;

class AdminTest extends TestCase {
/** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */
Expand Down Expand Up @@ -89,9 +92,9 @@ protected function setUp(): void {
}

public function testGetFormWithUpdate() {
$backend1 = $this->createMock(UserInterface::class);
$backend2 = $this->createMock(UserInterface::class);
$backend3 = $this->createMock(UserInterface::class);
$backend1 = $this->createMock(CountUsersBackend::class);
$backend2 = $this->createMock(CountUsersBackend::class);
$backend3 = $this->createMock(CountUsersBackend::class);
$backend1
->expects($this->once())
->method('implementsActions')
Expand Down Expand Up @@ -213,9 +216,9 @@ public function testGetFormWithUpdate() {
}

public function testGetFormWithUpdateAndChangedUpdateServer() {
$backend1 = $this->createMock(UserInterface::class);
$backend2 = $this->createMock(UserInterface::class);
$backend3 = $this->createMock(UserInterface::class);
$backend1 = $this->createMock(CountUsersBackend::class);
$backend2 = $this->createMock(CountUsersBackend::class);
$backend3 = $this->createMock(CountUsersBackend::class);
$backend1
->expects($this->once())
->method('implementsActions')
Expand Down Expand Up @@ -337,9 +340,9 @@ public function testGetFormWithUpdateAndChangedUpdateServer() {
}

public function testGetFormWithUpdateAndCustomersUpdateServer() {
$backend1 = $this->createMock(UserInterface::class);
$backend2 = $this->createMock(UserInterface::class);
$backend3 = $this->createMock(UserInterface::class);
$backend1 = $this->createMock(CountUsersBackend::class);
$backend2 = $this->createMock(CountUsersBackend::class);
$backend3 = $this->createMock(CountUsersBackend::class);
$backend1
->expects($this->once())
->method('implementsActions')
Expand Down Expand Up @@ -543,3 +546,7 @@ public function testFilterChanges($changes, $userLang, $expectation) {
$this->assertSame($expectation, $result);
}
}

abstract class CountUsersBackend implements UserInterface, ICountUsersBackend {

}
3 changes: 2 additions & 1 deletion tests/Core/Controller/AvatarControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function is_uploaded_file($filename) {
use OC\Core\Controller\AvatarController;
use OCP\AppFramework\Http;
use OCP\Files\File;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
Expand Down Expand Up @@ -115,7 +116,7 @@ protected function setUp(): void {
$this->userManager->method('get')
->willReturnMap([['userId', $this->userMock]]);

$this->avatarFile = $this->getMockBuilder('OCP\Files\File')->getMock();
$this->avatarFile = $this->getMockBuilder(ISimpleFile::class)->getMock();
$this->avatarFile->method('getContent')->willReturn('image data');
$this->avatarFile->method('getMimeType')->willReturn('image type');
$this->avatarFile->method('getEtag')->willReturn('my etag');
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/App/DependencyAnalyzerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function setUp(): void {
->willReturn('5.4.3');
$this->platformMock->expects($this->any())
->method('getIntSize')
->willReturn('4');
->willReturn(4);
$this->platformMock->expects($this->any())
->method('getDatabase')
->willReturn('mysql');
Expand Down

0 comments on commit d24ef26

Please sign in to comment.