Import participants
Big refactor to create route Import participants Signed-off-by: Vitor Mattos <vitor@php.rio>
This commit is contained in:
committed by
Julius Härtl
parent
fd92fc3c4d
commit
c5d10dafb8
@@ -24,6 +24,9 @@
|
||||
namespace OCA\Deck\Command;
|
||||
|
||||
use OCA\Deck\Command\ImportHelper\TrelloHelper;
|
||||
use OCA\Deck\Service\AImportService;
|
||||
use OCA\Deck\Service\BoardImportService;
|
||||
use OCA\Deck\Service\BoardService;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
@@ -32,14 +35,21 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
class BoardImportTest extends \Test\TestCase {
|
||||
/** @var TrelloHelper */
|
||||
private $trelloHelper;
|
||||
/** @var BoardImportService */
|
||||
private $boardImportService;
|
||||
/** @var BoardImport */
|
||||
private $boardImport;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->trelloHelper = $this->createMock(TrelloHelper::class);
|
||||
$this->boardImportService = $this->createMock(BoardImportService::class);
|
||||
$this->boardImportService
|
||||
->method('getAllowedImportSystems')
|
||||
->willReturn(['trello']);
|
||||
$this->boardImport = new BoardImport(
|
||||
$this->trelloHelper
|
||||
$this->trelloHelper,
|
||||
$this->boardImportService
|
||||
);
|
||||
$questionHelper = new QuestionHelper();
|
||||
$this->boardImport->setHelperSet(
|
||||
@@ -60,8 +70,8 @@ class BoardImportTest extends \Test\TestCase {
|
||||
)
|
||||
->will($this->returnValueMap([
|
||||
['system', 'trello'],
|
||||
['config', __DIR__ . '/fixtures/config-trello.json'],
|
||||
['data', __DIR__ . '/fixtures/data-trello.json']
|
||||
['config', __DIR__ . '/../../data/config-trello.json'],
|
||||
['data', __DIR__ . '/../../data/data-trello.json']
|
||||
]));
|
||||
$output = $this->createMock(OutputInterface::class);
|
||||
|
||||
@@ -69,6 +79,13 @@ class BoardImportTest extends \Test\TestCase {
|
||||
->expects($this->once())
|
||||
->method('writeLn')
|
||||
->with('Done!');
|
||||
$this->boardImportService
|
||||
->method('getSystem')
|
||||
->willReturn('trello');
|
||||
$importService = $this->createMock(AImportService::class);
|
||||
$this->boardImportService
|
||||
->method('getImportService')
|
||||
->willReturn($importService);
|
||||
|
||||
$this->invokePrivate($this->boardImport, 'interact', [$input, $output]);
|
||||
$actual = $this->invokePrivate($this->boardImport, 'execute', [$input, $output]);
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
namespace OCA\Deck\Command;
|
||||
|
||||
use OCA\Deck\Command\ImportHelper\TrelloHelper;
|
||||
use OCA\Deck\Service\AImportService;
|
||||
use OCA\Deck\Service\BoardImportService;
|
||||
use OCA\Deck\Service\TrelloImportService;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
@@ -33,6 +35,8 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
class TrelloHelperTest extends \Test\TestCase {
|
||||
/** @var TrelloImportService */
|
||||
private $trelloImportService;
|
||||
/** @var BoardImportService */
|
||||
private $boardImportService;
|
||||
/** @var TrelloHelper */
|
||||
private $trelloHelper;
|
||||
public function setUp(): void {
|
||||
@@ -42,7 +46,14 @@ class TrelloHelperTest extends \Test\TestCase {
|
||||
$this->trelloImportService
|
||||
);
|
||||
$questionHelper = new QuestionHelper();
|
||||
$command = new BoardImport($this->trelloHelper);
|
||||
$this->boardImportService = $this->createMock(BoardImportService::class);
|
||||
$this->boardImportService
|
||||
->method('getAllowedImportSystems')
|
||||
->willReturn(['trello']);
|
||||
$command = new BoardImport(
|
||||
$this->trelloHelper,
|
||||
$this->boardImportService
|
||||
);
|
||||
$command->setHelperSet(
|
||||
new HelperSet([
|
||||
$questionHelper
|
||||
@@ -61,10 +72,18 @@ class TrelloHelperTest extends \Test\TestCase {
|
||||
)
|
||||
->will($this->returnValueMap([
|
||||
['system', 'trello'],
|
||||
['config', __DIR__ . '/../fixtures/config-trello.json']
|
||||
['config', __DIR__ . '/../../../data/config-trello.json']
|
||||
]));
|
||||
$output = $this->createMock(OutputInterface::class);
|
||||
|
||||
$this->boardImportService
|
||||
->method('getSystem')
|
||||
->willReturn('trello');
|
||||
$importService = $this->createMock(AImportService::class);
|
||||
$this->boardImportService
|
||||
->method('getImportService')
|
||||
->willReturn($importService);
|
||||
|
||||
$this->invokePrivate($this->trelloHelper->getCommand(), 'validateSystem', [$input, $output]);
|
||||
$this->invokePrivate($this->trelloHelper->getCommand(), 'validateConfig', [$input, $output]);
|
||||
$actual = $this->trelloHelper->import($input, $output);
|
||||
|
||||
46
tests/unit/Service/BoardImportServiceTest.php
Normal file
46
tests/unit/Service/BoardImportServiceTest.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 Vitor Mattos <vitor@php.rio>
|
||||
*
|
||||
* @author Vitor Mattos <vitor@php.rio>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
namespace OCA\Deck\Service;
|
||||
|
||||
class BoardImportServiceTest extends \Test\TestCase {
|
||||
/** @var TrelloImportService */
|
||||
private $trelloImportService;
|
||||
/** @var BoardImportService */
|
||||
private $boardImportService;
|
||||
public function setUp(): void {
|
||||
$this->trelloImportService = $this->createMock(TrelloImportService::class);
|
||||
$this->boardImportService = new BoardImportService(
|
||||
$this->trelloImportService
|
||||
);
|
||||
}
|
||||
|
||||
public function testImportSuccess() {
|
||||
$config = json_decode(file_get_contents(__DIR__ . '/../../data/config-trello.json'));
|
||||
$data = json_decode(file_get_contents(__DIR__ . '/../../data/data-trello.json'));
|
||||
$actual = $this->boardImportService->import(
|
||||
'trello',
|
||||
$config,
|
||||
$data
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,8 @@ class BoardServiceTest extends TestCase {
|
||||
private $changeHelper;
|
||||
/** @var IEventDispatcher */
|
||||
private $eventDispatcher;
|
||||
/** @var TrelloImportService */
|
||||
private $trelloImportService;
|
||||
private $userId = 'admin';
|
||||
|
||||
public function setUp(): void {
|
||||
@@ -91,6 +93,7 @@ class BoardServiceTest extends TestCase {
|
||||
$this->activityManager = $this->createMock(ActivityManager::class);
|
||||
$this->changeHelper = $this->createMock(ChangeHelper::class);
|
||||
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
||||
$this->trelloImportService = $this->createMock(TrelloImportService::class);
|
||||
|
||||
$this->service = new BoardService(
|
||||
$this->boardMapper,
|
||||
@@ -107,6 +110,7 @@ class BoardServiceTest extends TestCase {
|
||||
$this->activityManager,
|
||||
$this->eventDispatcher,
|
||||
$this->changeHelper,
|
||||
$this->trelloImportService,
|
||||
$this->userId
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user