Skip to content

CFM-28_Setup_Command_test_setup #203

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Move test seutp in TestCommand class
Ioannis committed Jun 6, 2024
commit 37fd07cc1cfa11ae4aa3d63f0f8fe12a3633cce8
14 changes: 3 additions & 11 deletions app/src/Command/SetupCommand.php
@@ -79,17 +79,9 @@ public function execute(Arguments $args, ConsoleIo $io)
$force = $args->getOption('force');

// Check if the COmanage CO already exists, and if so abort.

$coTable = $this->getTableLocator()->get('Cos');
$query = $coTable->find();
$comanageCO = $coTable->findCOmanageCO($query)->first();

if(!is_null($comanageCO)) {
$io->out(__d('command', 'se.already'));

if(!$force) {
exit;
}
if($this->executeCommand(TestCommand::class, ['-t', 'setup']) === static::CODE_ERROR
&& !$force) {
$this->abort(static::CODE_ERROR);
}

// Collect the admin info before we try to do anything.
28 changes: 27 additions & 1 deletion app/src/Command/TestCommand.php
@@ -53,7 +53,7 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar
$parser->addOption('test', [
'help' => __d('command', 'opt.test.test'),
'short' => 't',
'choices' => ['database', 'mail']
'choices' => ['database', 'mail', 'setup']
])->addOption('datasource', [
'help' => __d('command', 'opt.test.database.source'),
'default' => 'default'
@@ -88,6 +88,9 @@ public function execute(Arguments $args, ConsoleIo $io)
case 'mail':
$this->testMail((int)$args->getOption('recipient'));
break;
case 'setup':
$this->testSetup();
break;
default:
$io->out("Command $test unknown");
break;
@@ -139,4 +142,27 @@ protected function testMail(int $recipient): int {

return static::CODE_SUCCESS;
}

/**
* Test COmanage setup
*
* @since COmanage Registry v5.0.0
* @return int Return Code (CODE_SUCCESS or CODE_ERROR)
*/

protected function testSetup(): int {

// Check if the COmanage CO already exists, and if so abort.

$coTable = $this->getTableLocator()->get('Cos');
$query = $coTable->find();
$comanageCO = $coTable->findCOmanageCO($query)->first();

if($comanageCO !== null) {
$this->io->out(__d('command', 'se.already'));
$this->abort(static::CODE_ERROR);
}

return static::CODE_SUCCESS;
}
}