Fix unit tests for board archiving

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2017-05-17 19:51:06 +02:00
parent 8c04ea8dc9
commit 90eb9ce28e
6 changed files with 31 additions and 17 deletions

View File

@@ -27,9 +27,10 @@ namespace OCA\Deck\Service;
use OCA\Deck\Db\Card;
use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\StackMapper;
use OCA\Deck\ArchivedItemException;
use OCA\Deck\StatusException;
use Test\TestCase;
class CardServiceTest extends \PHPUnit_Framework_TestCase {
class CardServiceTest extends TestCase {
/** @var CardService|\PHPUnit_Framework_MockObject_MockObject */
private $cardService;
@@ -39,7 +40,8 @@ class CardServiceTest extends \PHPUnit_Framework_TestCase {
private $stackMapper;
/** @var PermissionService|\PHPUnit_Framework_MockObject_MockObject */
private $permissionService;
/** @var BoardService|\PHPUnit_Framework_MockObject_MockObject */
private $boardService;
public function setUp() {
$this->cardMapper = $this->getMockBuilder(CardMapper::class)
@@ -48,7 +50,8 @@ class CardServiceTest extends \PHPUnit_Framework_TestCase {
->disableOriginalConstructor()->getMock();
$this->permissionService = $this->getMockBuilder(PermissionService::class)
->disableOriginalConstructor()->getMock();
$this->cardService = new CardService($this->cardMapper, $this->stackMapper, $this->permissionService);
$this->boardService = $this->createMock(BoardService::class);
$this->cardService = new CardService($this->cardMapper, $this->stackMapper, $this->permissionService, $this->boardService);
}
public function testFind() {
@@ -108,7 +111,7 @@ class CardServiceTest extends \PHPUnit_Framework_TestCase {
$card->setArchived(true);
$this->cardMapper->expects($this->once())->method('find')->willReturn($card);
$this->cardMapper->expects($this->never())->method('update');
$this->setExpectedException(ArchivedItemException::class);
$this->setExpectedException(StatusException::class);
$this->cardService->update(123, 'newtitle', 234, 'text', 999, 'foo', 'admin');
}
@@ -128,7 +131,7 @@ class CardServiceTest extends \PHPUnit_Framework_TestCase {
$card->setArchived(true);
$this->cardMapper->expects($this->once())->method('find')->willReturn($card);
$this->cardMapper->expects($this->never())->method('update');
$this->setExpectedException(ArchivedItemException::class);
$this->setExpectedException(StatusException::class);
$this->cardService->rename(123, 'newtitle');
}
@@ -168,7 +171,7 @@ class CardServiceTest extends \PHPUnit_Framework_TestCase {
$card->setArchived(true);
$this->cardMapper->expects($this->once())->method('findAll')->willReturn([$card]);
$this->cardMapper->expects($this->never())->method('update')->willReturnCallback(function($c) { return $c; });
$this->setExpectedException(ArchivedItemException::class);
$this->setExpectedException(StatusException::class);
$actual = $this->cardService->reorder(123, 234, 1);
}
public function testArchive() {
@@ -204,7 +207,7 @@ class CardServiceTest extends \PHPUnit_Framework_TestCase {
$card->setArchived(true);
$this->cardMapper->expects($this->once())->method('find')->willReturn($card);
$this->cardMapper->expects($this->never())->method('assignLabel');
$this->setExpectedException(ArchivedItemException::class);
$this->setExpectedException(StatusException::class);
$this->cardService->assignLabel(123, 999);
}
@@ -221,7 +224,7 @@ class CardServiceTest extends \PHPUnit_Framework_TestCase {
$card->setArchived(true);
$this->cardMapper->expects($this->once())->method('find')->willReturn($card);
$this->cardMapper->expects($this->never())->method('removeLabel');
$this->setExpectedException(ArchivedItemException::class);
$this->setExpectedException(StatusException::class);
$this->cardService->removeLabel(123, 999);
}