Fix test mocking

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2020-12-30 12:54:19 +01:00
parent 7291c46d0d
commit 74814ad614
14 changed files with 32 additions and 55 deletions

View File

@@ -42,7 +42,7 @@ use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
/** @internal Just for testing the service registration */
class MyAttachmentService {
class MyAttachmentService implements IAttachmentService {
public function extendData(Attachment $attachment) {
}
public function display(Attachment $attachment) {
@@ -84,6 +84,10 @@ class AttachmentServiceTest extends TestCase {
private $l10n;
/** @var ChangeHelper */
private $changeHelper;
/**
* @var IAttachmentService|MockObject
*/
private $filesAppServiceImpl;
/**
* @throws \OCP\AppFramework\QueryException
@@ -92,6 +96,8 @@ class AttachmentServiceTest extends TestCase {
parent::setUp();
$this->attachmentServiceImpl = $this->createMock(IAttachmentService::class);
$this->filesAppServiceImpl = $this->createMock(IAttachmentService::class);
$this->appContainer = $this->createMock(IAppContainer::class);
$this->attachmentMapper = $this->createMock(AttachmentMapper::class);
@@ -105,6 +111,8 @@ class AttachmentServiceTest extends TestCase {
$this->cacheFactory->expects($this->any())->method('createDistributed')->willReturn($this->cache);
$this->appContainer->expects($this->at(0))->method('query')->with(FileService::class)->willReturn($this->attachmentServiceImpl);
$this->appContainer->expects($this->at(1))->method('query')->with(FilesAppService::class)->willReturn($this->filesAppServiceImpl);
$this->application->expects($this->any())
->method('getContainer')
->willReturn($this->appContainer);
@@ -119,8 +127,12 @@ class AttachmentServiceTest extends TestCase {
$application = $this->createMock(Application::class);
$appContainer = $this->createMock(IAppContainer::class);
$fileServiceMock = $this->createMock(FileService::class);
$appContainer->expects($this->at(1))->method('query')->with(MyAttachmentService::class)->willReturn(new MyAttachmentService());
$fileAppServiceMock = $this->createMock(FilesAppService::class);
$appContainer->expects($this->at(0))->method('query')->with(FileService::class)->willReturn($fileServiceMock);
$appContainer->expects($this->at(1))->method('query')->with(FilesAppService::class)->willReturn($fileAppServiceMock);
$appContainer->expects($this->at(2))->method('query')->with(MyAttachmentService::class)->willReturn(new MyAttachmentService());
$application->expects($this->any())
->method('getContainer')
->willReturn($appContainer);
@@ -135,8 +147,10 @@ class AttachmentServiceTest extends TestCase {
$application = $this->createMock(Application::class);
$appContainer = $this->createMock(IAppContainer::class);
$fileServiceMock = $this->createMock(FileService::class);
$fileAppServiceMock = $this->createMock(FilesAppService::class);
$appContainer->expects($this->at(0))->method('query')->with(FileService::class)->willReturn($fileServiceMock);
$appContainer->expects($this->at(1))->method('query')->with(MyAttachmentService::class)->willReturn(new MyAttachmentService());
$appContainer->expects($this->at(1))->method('query')->with(FilesAppService::class)->willReturn($fileAppServiceMock);
$appContainer->expects($this->at(2))->method('query')->with(MyAttachmentService::class)->willReturn(new MyAttachmentService());
$application->expects($this->any())
->method('getContainer')
->willReturn($appContainer);

View File

@@ -123,20 +123,9 @@ class BoardServiceTest extends TestCase {
$b3 = new Board();
$b3->setId(3);
$this->boardMapper->expects($this->once())
->method('findAllByUser')
->method('findAllForUser')
->with('admin')
->willReturn([$b1, $b2]);
$this->stackMapper->expects($this->any())
->method('findAll')
->willReturn([]);
$this->boardMapper->expects($this->once())
->method('findAllByGroups')
->with('admin', ['a', 'b', 'c'])
->willReturn([$b2, $b3]);
$this->boardMapper->expects($this->once())
->method('findAllByCircles')
->with('admin')
->willReturn([]);
->willReturn([$b1, $b2, $b3]);
$user = $this->createMock(IUser::class);
$this->groupManager->method('getUserGroupIds')
->willReturn(['a', 'b', 'c']);

View File

@@ -26,6 +26,7 @@ namespace OCA\Deck\Controller;
use OCA\Deck\Service\ConfigService;
use OCA\Deck\Service\PermissionService;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IInitialStateService;
use OCP\IL10N;
use OCP\IRequest;
@@ -37,6 +38,7 @@ class PageControllerTest extends \Test\TestCase {
private $permissionService;
private $initialState;
private $configService;
private $eventDispatcher;
public function setUp(): void {
$this->l10n = $this->createMock(IL10N::class);
@@ -44,9 +46,10 @@ class PageControllerTest extends \Test\TestCase {
$this->permissionService = $this->createMock(PermissionService::class);
$this->configService = $this->createMock(ConfigService::class);
$this->initialState = $this->createMock(IInitialStateService::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->controller = new PageController(
'deck', $this->request, $this->permissionService, $this->initialState, $this->configService
'deck', $this->request, $this->permissionService, $this->initialState, $this->configService, $this->eventDispatcher
);
}