Default valute to board property fix command flow and refactor
Fixes on getBoard tests Refactor Reduce psalm info Refactor to implement pattern Change order of methods to put all abstract first and all public first Signed-off-by: Vitor Mattos <vitor@php.rio>
This commit is contained in:
committed by
Julius Härtl
parent
6714c89220
commit
19c609540b
@@ -22,38 +22,46 @@
|
||||
*/
|
||||
namespace OCA\Deck\Service;
|
||||
|
||||
use OC\Comments\Comment;
|
||||
use OCA\Deck\Db\Acl;
|
||||
use OCA\Deck\Db\AclMapper;
|
||||
use OCA\Deck\Db\Assignment;
|
||||
use OCA\Deck\Db\AssignmentMapper;
|
||||
use OCA\Deck\Db\Board;
|
||||
use OCA\Deck\Db\BoardMapper;
|
||||
use OCA\Deck\Db\Card;
|
||||
use OCA\Deck\Db\CardMapper;
|
||||
use OCA\Deck\Db\Label;
|
||||
use OCA\Deck\Db\LabelMapper;
|
||||
use OCA\Deck\Db\Stack;
|
||||
use OCA\Deck\Db\StackMapper;
|
||||
use OCP\Comments\ICommentsManager;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class BoardImportServiceTest extends \Test\TestCase {
|
||||
/** @var IDBConnection */
|
||||
/** @var IDBConnection|MockObject */
|
||||
protected $dbConn;
|
||||
/** @var IUserManager */
|
||||
/** @var IUserManager|MockObject */
|
||||
private $userManager;
|
||||
/** @var BoardMapper */
|
||||
/** @var BoardMapper|MockObject */
|
||||
private $boardMapper;
|
||||
/** @var AclMapper */
|
||||
/** @var AclMapper|MockObject */
|
||||
private $aclMapper;
|
||||
/** @var LabelMapper */
|
||||
/** @var LabelMapper|MockObject */
|
||||
private $labelMapper;
|
||||
/** @var StackMapper */
|
||||
/** @var StackMapper|MockObject */
|
||||
private $stackMapper;
|
||||
/** @var CardMapper */
|
||||
/** @var CardMapper|MockObject */
|
||||
private $cardMapper;
|
||||
/** @var AssignmentMapper */
|
||||
/** @var AssignmentMapper|MockObject */
|
||||
private $assignmentMapper;
|
||||
/** @var ICommentsManager */
|
||||
/** @var ICommentsManager|MockObject */
|
||||
private $commentsManager;
|
||||
/** @var BoardImportService */
|
||||
/** @var BoardImportTrelloService|MockObject */
|
||||
private $importTrelloService;
|
||||
/** @var BoardImportService|MockObject */
|
||||
private $boardImportService;
|
||||
public function setUp(): void {
|
||||
$this->dbConn = $this->createMock(IDBConnection::class);
|
||||
@@ -85,40 +93,83 @@ class BoardImportServiceTest extends \Test\TestCase {
|
||||
$configInstance = json_decode(file_get_contents(__DIR__ . '/../../data/config-trello.json'));
|
||||
$this->boardImportService->setConfigInstance($configInstance);
|
||||
|
||||
$this->importTrelloService = $this->createMock(BoardImportTrelloService::class);
|
||||
$this->boardImportService->setImportSystem($this->importTrelloService);
|
||||
|
||||
$owner = $this->createMock(IUser::class);
|
||||
$owner
|
||||
->method('getUID')
|
||||
->willReturn('admin');
|
||||
|
||||
$johndoe = $this->createMock(IUser::class);
|
||||
$johndoe
|
||||
->method('getUID')
|
||||
->willReturn('johndoe');
|
||||
$this->userManager
|
||||
->method('get')
|
||||
->willReturn($owner);
|
||||
->withConsecutive(
|
||||
['admin'],
|
||||
['johndoe']
|
||||
)
|
||||
->willReturnonConsecutiveCalls(
|
||||
$owner,
|
||||
$johndoe
|
||||
);
|
||||
}
|
||||
|
||||
public function testImportSuccess() {
|
||||
$importService = $this->createMock(ABoardImportService::class);
|
||||
$board = new Board();
|
||||
$importService
|
||||
->method('getBoard')
|
||||
->willReturn($board);
|
||||
$this->boardImportService->setSystem('trello');
|
||||
$this->boardImportService->setImportSystem($importService);
|
||||
$this->boardMapper
|
||||
->expects($this->once())
|
||||
->method('insert');
|
||||
|
||||
$this->importTrelloService
|
||||
->method('getAclList')
|
||||
->willReturn([new Acl()]);
|
||||
$this->aclMapper
|
||||
->expects($this->once())
|
||||
->method('insert');
|
||||
|
||||
$this->importTrelloService
|
||||
->method('getLabels')
|
||||
->willReturn([new Label()]);
|
||||
$this->labelMapper
|
||||
->expects($this->once())
|
||||
->method('insert');
|
||||
|
||||
$this->importTrelloService
|
||||
->method('getStacks')
|
||||
->willReturn([new Stack()]);
|
||||
$this->stackMapper
|
||||
->expects($this->once())
|
||||
->method('insert');
|
||||
|
||||
$this->importTrelloService
|
||||
->method('getCards')
|
||||
->willReturn([new Card()]);
|
||||
$this->cardMapper
|
||||
->expects($this->any())
|
||||
->method('insert');
|
||||
|
||||
$this->importTrelloService
|
||||
->method('getComments')
|
||||
->willReturn([
|
||||
'fakecardid' => [new Comment()]
|
||||
]);
|
||||
$this->commentsManager
|
||||
->expects($this->once())
|
||||
->method('save');
|
||||
|
||||
$this->importTrelloService
|
||||
->method('getCardAssignments')
|
||||
->willReturn([
|
||||
'fakecardid' => [new Assignment()]
|
||||
]);
|
||||
$this->assignmentMapper
|
||||
->expects($this->once())
|
||||
->method('insert');
|
||||
|
||||
$actual = $this->boardImportService->import();
|
||||
$this->assertNull($actual);
|
||||
}
|
||||
|
||||
public function testImportBoard() {
|
||||
$this->boardImportService->validateOwner();
|
||||
$actual = $this->boardImportService->importBoard();
|
||||
$this->assertNull($actual);
|
||||
$board = $this->boardImportService->getBoard();
|
||||
$this->assertEquals('Test Board Name', $board->getTitle());
|
||||
$this->assertEquals('admin', $board->getOwner());
|
||||
$this->assertEquals('0800fd', $board->getColor());
|
||||
}
|
||||
|
||||
public function testImportAcl() {
|
||||
$this->markTestIncomplete();
|
||||
$actual = $this->boardImportService->importAcl();
|
||||
$this->assertNull($actual);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user