Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move test seutp in TestCommand class
Ioannis committed Jun 6, 2024
1 parent 462f158 commit 37fd07c
Showing 2 changed files with 30 additions and 12 deletions.
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;
}
}

0 comments on commit 37fd07c

Please sign in to comment.