Adds tests for scene commands.
This commit is contained in:
@@ -41,6 +41,8 @@ class ModuleConfigResetCommand extends ModuleBaseCommand
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$io->title("Module {$module->getLibrary()}");
|
||||
|
||||
// Create hook
|
||||
$context = EventContextData::create([
|
||||
"module" => $module,
|
||||
|
||||
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Console\Command\Scene;
|
||||
|
||||
use Exception;
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use LotGD\Core\Models\SceneTemplate;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
@@ -18,15 +17,15 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
/**
|
||||
* Resets the viewpoint of a given character.
|
||||
*/
|
||||
class SceneAddCommand extends BaseCommand
|
||||
class SceneAddCommand extends SceneBaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('scene:add')
|
||||
->setDescription('Add a scene.')
|
||||
$this->setName($this->namespaced("add"))
|
||||
->setDescription("Add a scene.")
|
||||
->setDefinition(
|
||||
new InputDefinition([
|
||||
new InputArgument(
|
||||
@@ -57,7 +56,7 @@ class SceneAddCommand extends BaseCommand
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$em = $this->game->getEntityManager();
|
||||
$logger = $this->game->getLogger();
|
||||
$logger = $this->getCliLogger();
|
||||
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
@@ -76,11 +75,11 @@ class SceneAddCommand extends BaseCommand
|
||||
$template = $templateClass;
|
||||
}
|
||||
|
||||
$scene = Scene::create([
|
||||
"title" => $title,
|
||||
"description" => $description,
|
||||
"template" => $template,
|
||||
]);
|
||||
$scene = new Scene(
|
||||
title: $title,
|
||||
description: $description,
|
||||
template: $template
|
||||
);
|
||||
|
||||
try {
|
||||
$em->persist($scene);
|
||||
|
||||
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Console\Command\Scene;
|
||||
|
||||
use Exception;
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use LotGD\Core\Exceptions\ArgumentException;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use LotGD\Core\Models\SceneConnectionGroup;
|
||||
@@ -18,18 +17,18 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
/**
|
||||
* Resets the viewpoint of a given character.
|
||||
*/
|
||||
class SceneAddConnectionGroupCommand extends BaseCommand
|
||||
class SceneAddConnectionGroupCommand extends SceneBaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('scene:addConnectionGroup')
|
||||
->setDescription('Add a connection group to an existing scene.')
|
||||
$this->setName($this->namespaced('addConnectionGroup'))
|
||||
->setDescription("Add a connection group to an existing scene.")
|
||||
->setDefinition(
|
||||
new InputDefinition([
|
||||
new InputArgument("id", InputArgument::REQUIRED, "ID of the scene"),
|
||||
$this->getSceneIdArgumentDefinition(),
|
||||
new InputArgument("groupName", InputArgument::REQUIRED, "Internal id of the group."),
|
||||
new InputArgument("groupTitle", InputArgument::REQUIRED, "Title of the group (what the character can see"),
|
||||
]),
|
||||
@@ -43,7 +42,7 @@ class SceneAddConnectionGroupCommand extends BaseCommand
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$em = $this->game->getEntityManager();
|
||||
$logger = $this->game->getLogger();
|
||||
$logger = $this->getCliLogger();
|
||||
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
@@ -56,7 +55,7 @@ class SceneAddConnectionGroupCommand extends BaseCommand
|
||||
$scene = $em->getRepository(Scene::class)->find($sceneId);
|
||||
|
||||
if (!$scene) {
|
||||
$io->error("The requested scene with the ID {$sceneId} was not found");
|
||||
$io->error("The requested scene with the ID {$sceneId} was not found.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
@@ -70,10 +69,12 @@ class SceneAddConnectionGroupCommand extends BaseCommand
|
||||
// Commit changes
|
||||
$em->flush();
|
||||
} catch(ArgumentException $e) {
|
||||
// Catches the error if a group already exists.
|
||||
$io->error($e->getMessage());
|
||||
return Command::FAILURE;
|
||||
} catch (Exception $e) {
|
||||
$io->error("An unknown error occured: {$e->getMessage()}");
|
||||
$io->error("An unknown error occurred: {$e->getMessage()}");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$io->success("{$connectionGroup} successfully added.");
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command\Scene;
|
||||
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class SceneBaseCommand extends BaseCommand
|
||||
{
|
||||
protected ?string $namespace = "character";
|
||||
|
||||
/**
|
||||
* @return InputArgument
|
||||
*/
|
||||
protected function getSceneIdArgumentDefinition(): InputArgument
|
||||
{
|
||||
return new InputArgument(
|
||||
name: "id",
|
||||
mode: InputArgument::REQUIRED,
|
||||
description: "Scene ID",
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Console\Command\Scene;
|
||||
|
||||
use Exception;
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use LotGD\Core\Exceptions\ArgumentException;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use LotGD\Core\Models\SceneConnectable;
|
||||
@@ -19,15 +18,15 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
/**
|
||||
* Resets the viewpoint of a given character.
|
||||
*/
|
||||
class SceneConnectCommand extends BaseCommand
|
||||
class SceneConnectCommand extends SceneBaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('scene:connect')
|
||||
->setDescription('Connects two scenes.')
|
||||
$this->setName($this->namespaced("connect"))
|
||||
->setDescription("Connects two scenes.")
|
||||
->setDefinition(
|
||||
new InputDefinition([
|
||||
new InputArgument(
|
||||
@@ -72,7 +71,7 @@ class SceneConnectCommand extends BaseCommand
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$em = $this->game->getEntityManager();
|
||||
$logger = $this->game->getLogger();
|
||||
$logger = $this->getCliLogger();
|
||||
$sceneRepository = $em->getRepository(Scene::class);
|
||||
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
@@ -141,10 +140,10 @@ class SceneConnectCommand extends BaseCommand
|
||||
// Commit changes
|
||||
$em->flush();
|
||||
} catch (ArgumentException $e) {
|
||||
$io->error("Scenes were not connected. Reason: {$e}.");
|
||||
$io->error("Scenes were not connected. Reason: {$e->getMessage()}.");
|
||||
return Command::FAILURE;
|
||||
} catch (Exception $e) {
|
||||
$io->error("An unknown error occured: {$e->getMessage()}");
|
||||
$io->error("An unknown error occurred: {$e}");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Console\Command\Scene;
|
||||
|
||||
use Exception;
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
@@ -16,26 +15,26 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
/**
|
||||
* Resets the viewpoint of a given character.
|
||||
*/
|
||||
class SceneDisconnectCommand extends BaseCommand
|
||||
class SceneDisconnectCommand extends SceneBaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('scene:disconnect')
|
||||
->setDescription('Disconnects two scenes.')
|
||||
$this->setName($this->namespaced("disconnect"))
|
||||
->setDescription("Disconnects two scenes.")
|
||||
->setDefinition(
|
||||
new InputDefinition([
|
||||
new InputArgument(
|
||||
"scene1",
|
||||
mode: InputArgument::REQUIRED,
|
||||
description: "Outgoing scene ID",
|
||||
description: "One scene ID",
|
||||
),
|
||||
new InputArgument(
|
||||
"scene2",
|
||||
mode: InputArgument::REQUIRED,
|
||||
description: "Incoming scene ID",
|
||||
description: "The other scene ID",
|
||||
),
|
||||
])
|
||||
)
|
||||
@@ -48,7 +47,7 @@ class SceneDisconnectCommand extends BaseCommand
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$em = $this->game->getEntityManager();
|
||||
$logger = $this->game->getLogger();
|
||||
$logger = $this->getCliLogger();
|
||||
$sceneRepository = $em->getRepository(Scene::class);
|
||||
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
@@ -71,7 +70,7 @@ class SceneDisconnectCommand extends BaseCommand
|
||||
$connection = $scene1->getConnectionTo($scene2);
|
||||
|
||||
if (!$connection) {
|
||||
$io->error("The to given scenes do not share a connection.");
|
||||
$io->error("The given scenes do not share a connection.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
@@ -80,7 +79,7 @@ class SceneDisconnectCommand extends BaseCommand
|
||||
$em->remove($connection);
|
||||
$em->flush();
|
||||
} catch (Exception $e) {
|
||||
$io->error("An unknown error occured: {$e->getMessage()}");
|
||||
$io->error("An unknown error occurred: {$e->getMessage()}");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,15 +10,15 @@ use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class SceneListCommand extends BaseCommand
|
||||
class SceneListCommand extends SceneBaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('scene:list')
|
||||
->setDescription('Lists all scenes')
|
||||
$this->setName($this->namespaced("list"))
|
||||
->setDescription("Lists all scenes")
|
||||
;
|
||||
}
|
||||
|
||||
@@ -33,12 +33,13 @@ class SceneListCommand extends BaseCommand
|
||||
/** @var Scene[] $scenes */
|
||||
$scenes = $em->getRepository(Scene::class)->findAll();
|
||||
|
||||
$table = [["id", "title", "connections"], []];
|
||||
$table = [["id", "title", "connections", "template"], []];
|
||||
foreach ($scenes as $scene) {
|
||||
$table[1][] = [
|
||||
$scene->getId(),
|
||||
$scene->getTitle(),
|
||||
count($scene->getConnectedScenes()),
|
||||
$scene->getTemplate()?->getClass(),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command\Scene;
|
||||
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
@@ -15,22 +13,18 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
/**
|
||||
* Resets the viewpoint of a given character.
|
||||
*/
|
||||
class SceneRemoveCommand extends BaseCommand
|
||||
class SceneRemoveCommand extends SceneBaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('scene:remove')
|
||||
->setDescription('Removes a scene.')
|
||||
$this->setName($this->namespaced("remove"))
|
||||
->setDescription("Removes a scene.")
|
||||
->setDefinition(
|
||||
new InputDefinition([
|
||||
new InputArgument(
|
||||
"id",
|
||||
mode: InputArgument::REQUIRED,
|
||||
description: "Scene ID",
|
||||
),
|
||||
$this->getSceneIdArgumentDefinition(),
|
||||
])
|
||||
)
|
||||
;
|
||||
@@ -57,7 +51,7 @@ class SceneRemoveCommand extends BaseCommand
|
||||
}
|
||||
|
||||
if (!$scene->isRemovable()) {
|
||||
$io->error("The scene with the ID {$sceneId} was marked as not removable. Please remove the responsible");
|
||||
$io->error("The scene with the ID {$sceneId} was marked as not removable. Please remove the responsible module instead.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command\Scene;
|
||||
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use LotGD\Core\Models\SceneConnection;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
@@ -16,18 +15,18 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
/**
|
||||
* Resets the viewpoint of a given character.
|
||||
*/
|
||||
class SceneRemoveConnectionGroupCommand extends BaseCommand
|
||||
class SceneRemoveConnectionGroupCommand extends SceneBaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('scene:removeConnectionGroup')
|
||||
->setDescription('Removes a connection group from an existing scene.')
|
||||
$this->setName($this->namespaced("removeConnectionGroup"))
|
||||
->setDescription("Removes a connection group from an existing scene.")
|
||||
->setDefinition(
|
||||
new InputDefinition([
|
||||
new InputArgument("id", InputArgument::REQUIRED, "ID of the scene"),
|
||||
$this->getSceneIdArgumentDefinition(),
|
||||
new InputArgument("groupName", InputArgument::REQUIRED, "Internal id of the group."),
|
||||
]),
|
||||
)
|
||||
@@ -40,7 +39,7 @@ class SceneRemoveConnectionGroupCommand extends BaseCommand
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$em = $this->game->getEntityManager();
|
||||
$logger = $this->game->getLogger();
|
||||
$logger = $this->getCliLogger();
|
||||
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
@@ -52,12 +51,12 @@ class SceneRemoveConnectionGroupCommand extends BaseCommand
|
||||
$scene = $em->getRepository(Scene::class)->find($sceneId);
|
||||
|
||||
if (!$scene) {
|
||||
$io->error("The requested scene with the ID {$sceneId} was not found");
|
||||
$io->error("The scene with the ID {$sceneId} was not found.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if (!$scene->hasConnectionGroup($groupName)) {
|
||||
$io->error("The scene {$sceneId} oes not have a connection group with the name {$groupName}");
|
||||
$io->error("The scene {$sceneId} does not have a connection group with the name {$groupName}");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
@@ -84,7 +83,7 @@ class SceneRemoveConnectionGroupCommand extends BaseCommand
|
||||
try {
|
||||
$em->flush();
|
||||
} catch (\Exception $e) {
|
||||
$io->error("An unknown error occured: {$e->getMessage()}");
|
||||
$io->error("An unknown error occurred: {$e->getMessage()}");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command\Scene;
|
||||
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use LotGD\Core\Models\SceneConnectable;
|
||||
use LotGD\Core\Models\SceneConnection;
|
||||
use LotGD\Core\Models\SceneConnectionGroup;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
@@ -18,18 +16,18 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
/**
|
||||
* Resets the viewpoint of a given character.
|
||||
*/
|
||||
class SceneShowCommand extends BaseCommand
|
||||
class SceneShowCommand extends SceneBaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('scene:show')
|
||||
->setDescription('Show details about a specific scene.')
|
||||
$this->setName($this->namespaced("show"))
|
||||
->setDescription("Show details about a specific scene.")
|
||||
->setDefinition(
|
||||
new InputDefinition([
|
||||
new InputArgument("id", InputArgument::REQUIRED, "ID of the scene"),
|
||||
$this->getSceneIdArgumentDefinition(),
|
||||
])
|
||||
)
|
||||
;
|
||||
@@ -81,7 +79,7 @@ class SceneShowCommand extends BaseCommand
|
||||
# Get formatting for outgoing scene connection group name
|
||||
$outgoingSceneConnectionGroup = $connection->getOutgoingConnectionGroupName();
|
||||
if ($outgoingSceneConnectionGroup) {
|
||||
$outgoingSceneConnectionGroup = "(on $outgoingSceneConnectionGroup)";
|
||||
$outgoingSceneConnectionGroup = " (on $outgoingSceneConnectionGroup)";
|
||||
} else {
|
||||
$outgoingSceneConnectionGroup = "";
|
||||
}
|
||||
@@ -100,9 +98,9 @@ class SceneShowCommand extends BaseCommand
|
||||
|
||||
# Check if the connection is bidirectional (only out (this)->in)
|
||||
if ($connection->isDirectionality(SceneConnectable::Bidirectional)) {
|
||||
$list[] = "this$outgoingSceneConnectionGroup <=> {$other->getTitle()}$incomingSceneConnectionGroup (id={$other->getId()})";
|
||||
$list[] = "this$outgoingSceneConnectionGroup <=> {$other->getTitle()}$incomingSceneConnectionGroup(id={$other->getId()})";
|
||||
} else {
|
||||
$list[] = "this$outgoingSceneConnectionGroup => {$other->getTitle()}$incomingSceneConnectionGroup (id={$other->getId()})";
|
||||
$list[] = "this$outgoingSceneConnectionGroup => {$other->getTitle()}$incomingSceneConnectionGroup(id={$other->getId()})";
|
||||
}
|
||||
} else {
|
||||
$other = $connection->getOutgoingScene();
|
||||
|
||||
@@ -17,7 +17,6 @@ use LotGD\Core\Exceptions\ArgumentException;
|
||||
use LotGD\Core\Exceptions\AttributeMissingException;
|
||||
use LotGD\Core\Exceptions\UnexpectedArrayKeyException;
|
||||
use LotGD\Core\Exceptions\WrongTypeException;
|
||||
use LotGD\Core\Tools\Model\Creator;
|
||||
use LotGD\Core\Tools\Model\Deletor;
|
||||
use LotGD\Core\Tools\Model\PropertyManager;
|
||||
use LotGD\Core\Tools\Model\Saveable;
|
||||
|
||||
@@ -3,15 +3,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Tests\Commands\CharacterCommands;
|
||||
|
||||
use LotGD\Core\Console\Command\Module\ModuleConfigListCommand;
|
||||
use LotGD\Core\Console\Command\Module\ModuleConfigSetCommand;
|
||||
use LotGD\Core\Console\Command\Module\ModuleListCommand;
|
||||
use LotGD\Core\EventHandler;
|
||||
use LotGD\Core\Console\Command\Module\ModuleConfigResetCommand;
|
||||
use LotGD\Core\EventManager;
|
||||
use LotGD\Core\Events\EventContext;
|
||||
use LotGD\Core\Events\EventContextData;
|
||||
use LotGD\Core\Game;
|
||||
use LotGD\Core\Models\Module;
|
||||
use LotGD\Core\Tests\CoreModelTestCase;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
@@ -24,7 +19,7 @@ class ModuleConfigResetCommandTest extends CoreModelTestCase
|
||||
|
||||
protected function getCommand(): CommandTester
|
||||
{
|
||||
return new CommandTester(new ModuleConfigSetCommand($this->g));
|
||||
return new CommandTester(new ModuleConfigResetCommand($this->g));
|
||||
}
|
||||
|
||||
public function testIfCommandEmitsEvent()
|
||||
@@ -73,14 +68,14 @@ class ModuleConfigResetCommandTest extends CoreModelTestCase
|
||||
$command->execute([
|
||||
"moduleName" => $module,
|
||||
"setting" => $setting,
|
||||
"value" => $value,
|
||||
]);
|
||||
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::FAILURE, $command->getStatusCode());
|
||||
$this->assertStringContainsString("Module {$module}", $output);
|
||||
$this->assertStringContainsString("Module lotgd/tests", $output);
|
||||
$this->assertStringContainsString("[ERROR]", $output);
|
||||
$this->assertStringNotContainsString("[OK]", $output);
|
||||
$this->assertStringContainsString("Setting does not exist.", $output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Tests\Commands\SceneCommands;
|
||||
|
||||
use LotGD\Core\Console\Command\Scene\SceneAddCommand;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use LotGD\Core\Tests\CoreModelTestCase;
|
||||
use LotGD\Core\Tests\SceneTemplates\NewSceneSceneTemplate;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
class SceneAddCommandTest extends CoreModelTestCase
|
||||
{
|
||||
/** @var string default data set */
|
||||
protected $dataset = "scene-2";
|
||||
|
||||
protected function getCommand(): CommandTester
|
||||
{
|
||||
return new CommandTester(new SceneAddCommand($this->g));
|
||||
}
|
||||
|
||||
public function testIfCommandFailsIfNoNameWasGiven()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$command->execute([]);
|
||||
}
|
||||
|
||||
public function testIfSceneGetsCreatedWithOnlyName()
|
||||
{
|
||||
$repository = $this->g->getEntityManager()->getRepository(Scene::class);
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"title" => "A scene.",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::SUCCESS, $command->getStatusCode());
|
||||
$this->assertStringContainsString("[OK]", $output);
|
||||
$this->assertStringContainsString("was successfully created.", $output);
|
||||
|
||||
// Check the database, too.
|
||||
$this->g->getEntityManager()->clear();
|
||||
/** @var Scene $scene */
|
||||
$scene = $repository->findOneBy(["title" => "A scene."]);
|
||||
$this->assertNotNull($scene);
|
||||
$this->assertSame("A scene.", $scene->getTitle());
|
||||
$this->assertSame("", $scene->getDescription());
|
||||
$this->assertNull($scene->getTemplate());
|
||||
}
|
||||
|
||||
public function testIfSceneGetsCreatedWithDescription()
|
||||
{
|
||||
$repository = $this->g->getEntityManager()->getRepository(Scene::class);
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"title" => "Another scene.",
|
||||
"description" => "The scenery is nice."
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::SUCCESS, $command->getStatusCode());
|
||||
$this->assertStringContainsString("[OK]", $output);
|
||||
$this->assertStringContainsString("was successfully created.", $output);
|
||||
|
||||
// Check the database, too.
|
||||
$this->g->getEntityManager()->clear();
|
||||
/** @var Scene $scene */
|
||||
$scene = $repository->findOneBy(["title" => "Another scene."]);
|
||||
$this->assertNotNull($scene);
|
||||
$this->assertSame("Another scene.", $scene->getTitle());
|
||||
$this->assertSame("The scenery is nice.", $scene->getDescription());
|
||||
$this->assertNull($scene->getTemplate());
|
||||
}
|
||||
|
||||
public function testIfSceneGetsCreatedWithValidSceneTemplate()
|
||||
{
|
||||
$repository = $this->g->getEntityManager()->getRepository(Scene::class);
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"title" => "A templated scene.",
|
||||
"description" => "The scenery is nice.",
|
||||
"--template" => "LotGD\\Core\\Tests\\SceneTemplates\\NewSceneSceneTemplate"
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::SUCCESS, $command->getStatusCode());
|
||||
$this->assertStringContainsString("[OK]", $output);
|
||||
$this->assertStringContainsString("was successfully created.", $output);
|
||||
$this->assertStringNotContainsString("[WARNING]", $output);
|
||||
$this->assertStringNotContainsString("has not been found. Set to NULL instead.", $output);
|
||||
|
||||
// Check the database, too.
|
||||
$this->g->getEntityManager()->clear();
|
||||
/** @var Scene $scene */
|
||||
$scene = $repository->findOneBy(["title" => "A templated scene."]);
|
||||
$this->assertNotNull($scene);
|
||||
$this->assertSame("A templated scene.", $scene->getTitle());
|
||||
$this->assertSame("The scenery is nice.", $scene->getDescription());
|
||||
$this->assertSame(NewSceneSceneTemplate::class, $scene->getTemplate()?->getClass());
|
||||
}
|
||||
|
||||
public function testIfSceneGetsCreatedWithInvalidSceneTemplateButThrowsWarning()
|
||||
{
|
||||
$repository = $this->g->getEntityManager()->getRepository(Scene::class);
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"title" => "A wrongly templated scene.",
|
||||
"description" => "The scenery is nice.",
|
||||
"--template" => "LotGD\\Core\\Tests\\SceneTemplates\\Darn"
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::SUCCESS, $command->getStatusCode());
|
||||
$this->assertStringContainsString("[OK]", $output);
|
||||
$this->assertStringContainsString("was successfully created.", $output);
|
||||
$this->assertStringContainsString("[WARNING]", $output);
|
||||
$this->assertStringContainsString("has not been found. Set to NULL instead.", $output);
|
||||
|
||||
// Check the database, too.
|
||||
$this->g->getEntityManager()->clear();
|
||||
/** @var Scene $scene */
|
||||
$scene = $repository->findOneBy(["title" => "A wrongly templated scene."]);
|
||||
$this->assertNotNull($scene);
|
||||
$this->assertSame("A wrongly templated scene.", $scene->getTitle());
|
||||
$this->assertSame("The scenery is nice.", $scene->getDescription());
|
||||
$this->assertNull($scene->getTemplate());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Tests\Commands\SceneCommands;
|
||||
|
||||
use LotGD\Core\Console\Command\Scene\SceneAddConnectionGroupCommand;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use LotGD\Core\Tests\CoreModelTestCase;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
class SceneAddConnectionGroupCommandTest extends CoreModelTestCase
|
||||
{
|
||||
/** @var string default data set */
|
||||
protected $dataset = "scene-2";
|
||||
|
||||
protected function getCommand(): CommandTester
|
||||
{
|
||||
return new CommandTester(new SceneAddConnectionGroupCommand($this->g));
|
||||
}
|
||||
|
||||
public function testIfCommandFailsIfNoNameWasGiven()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$command->execute([]);
|
||||
}
|
||||
|
||||
public function testIfCommandFailsIfSceneWasNotFound()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"id" => "30000000-0000-0000-0000-000000000000",
|
||||
"groupName" => "a/group/name",
|
||||
"groupTitle" => "The Abyss",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::FAILURE, $command->getStatusCode());
|
||||
$this->assertStringContainsString("[ERROR]", $output);
|
||||
$this->assertStringNotContainsString("[OK]", $output);
|
||||
$this->assertStringContainsString("The requested scene with the ID 30000000-0000-0000-0000-000000000000 was not found.", $output);
|
||||
}
|
||||
|
||||
public function testIfCommandGetsSuccessfullyAddedToScene()
|
||||
{
|
||||
$repository = $this->g->getEntityManager()->getRepository(Scene::class);
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"id" => "30000000-0000-0000-0000-000000000001",
|
||||
"groupName" => "a/group/name",
|
||||
"groupTitle" => "The Abyss",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::SUCCESS, $command->getStatusCode());
|
||||
$this->assertStringContainsString("[OK]", $output);
|
||||
$this->assertStringNotContainsString("[ERROR]", $output);
|
||||
$this->assertStringContainsString("successfully added.", $output);
|
||||
|
||||
// Check the database, too.
|
||||
$this->g->getEntityManager()->clear();
|
||||
/** @var Scene $scene */
|
||||
$scene = $repository->find("30000000-0000-0000-0000-000000000001");
|
||||
$this->assertNotNull($scene);
|
||||
$this->assertTrue($scene->hasConnectionGroup("a/group/name"));
|
||||
$this->assertNotNull($scene->getConnectionGroup("a/group/name"));
|
||||
$this->assertSame("The Abyss", $scene->getConnectionGroup("a/group/name")?->getTitle());
|
||||
}
|
||||
|
||||
public function testIfCommandFailsIfGroupNameIsAlreadyInUse()
|
||||
{
|
||||
$repository = $this->g->getEntityManager()->getRepository(Scene::class);
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"id" => "30000000-0000-0000-0000-000000000001",
|
||||
"groupName" => "lotgd/tests/village/outside",
|
||||
"groupTitle" => "The Abyss",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::FAILURE, $command->getStatusCode());
|
||||
$this->assertStringNotContainsString("[OK]", $output);
|
||||
$this->assertStringContainsString("[ERROR]", $output);
|
||||
$this->assertStringContainsString("Cannot add a second group with the same name to this scene.", $output);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,276 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Tests\Commands\SceneCommands;
|
||||
|
||||
use LotGD\Core\Console\Command\Scene\SceneConnectCommand;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use LotGD\Core\Models\SceneConnection;
|
||||
use LotGD\Core\Tests\CoreModelTestCase;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
class SceneConnectCommandTest extends CoreModelTestCase
|
||||
{
|
||||
/** @var string default data set */
|
||||
protected $dataset = "scene-2";
|
||||
|
||||
protected function getCommand(): CommandTester
|
||||
{
|
||||
return new CommandTester(new SceneConnectCommand($this->g));
|
||||
}
|
||||
|
||||
public function testIfCommandFailsIfNoOutgoingOrIncomingSceneWasGiven()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$command->execute([]);
|
||||
}
|
||||
|
||||
public function testIfCommandFailsIfNoIncomingSceneWasGiven()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$command->execute([
|
||||
"outgoing" => "30000000-0000-0000-0000-000000000005",
|
||||
]);
|
||||
}
|
||||
|
||||
public function testIfCommandFailsIfNoOutgoingWasGiven()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$command->execute([
|
||||
"incoming" => "30000000-0000-0000-0000-000000000004",
|
||||
]);
|
||||
}
|
||||
|
||||
public function testIfCommandFailsIfOutgoingSceneDoesNotExist()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"outgoing" => "30000000-0000-0000-0000-000000000000",
|
||||
"incoming" => "30000000-0000-0000-0000-000000000004",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::FAILURE, $command->getStatusCode());
|
||||
$this->assertStringNotContainsString("[OK]", $output);
|
||||
$this->assertStringContainsString("[ERROR]", $output);
|
||||
}
|
||||
|
||||
public function testIfCommandFailsIfIncomingSceneDoesNotExist()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"outgoing" => "30000000-0000-0000-0000-000000000005",
|
||||
"incoming" => "30000000-0000-0000-0000-000000000000",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::FAILURE, $command->getStatusCode());
|
||||
$this->assertStringNotContainsString("[OK]", $output);
|
||||
$this->assertStringContainsString("[ERROR]", $output);
|
||||
}
|
||||
|
||||
public function testIfScenesGetConnected()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"outgoing" => "30000000-0000-0000-0000-000000000005",
|
||||
"incoming" => "30000000-0000-0000-0000-000000000004",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::SUCCESS, $command->getStatusCode());
|
||||
$this->assertStringContainsString("[OK]", $output);
|
||||
$this->assertStringNotContainsString("[ERROR]", $output);
|
||||
$this->assertStringContainsString("The two scenes were successfully connected.", $output);
|
||||
|
||||
$this->getEntityManager()->clear();
|
||||
$sceneRepository = $this->getEntityManager()->getRepository(Scene::class);
|
||||
|
||||
/** @var Scene $outgoing */
|
||||
$outgoing = $sceneRepository->find("30000000-0000-0000-0000-000000000005");
|
||||
/** @var Scene $outgoing */
|
||||
$incoming = $sceneRepository->find("30000000-0000-0000-0000-000000000004");
|
||||
|
||||
$this->assertTrue($outgoing->isConnectedTo($incoming));
|
||||
}
|
||||
|
||||
public function testIfCommandFailsIfScenesAreAlreadyConnected()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"outgoing" => "30000000-0000-0000-0000-000000000001",
|
||||
"incoming" => "30000000-0000-0000-0000-000000000002",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::FAILURE, $command->getStatusCode());
|
||||
$this->assertStringNotContainsString("[OK]", $output);
|
||||
$this->assertStringContainsString("[ERROR]", $output);
|
||||
$this->assertStringContainsString("Scenes were not connected. Reason: The given scene (ID 30000000-0000-0000-0000-000000000002) is already", $output);
|
||||
$this->assertStringContainsString("connected to this (ID 30000000-0000-0000-0000-000000000001) one..", $output);
|
||||
}
|
||||
|
||||
public function testIfScenesGetConnectedOnOutgoingConnectionGroup()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"outgoing" => "30000000-0000-0000-0000-000000000001",
|
||||
"incoming" => "30000000-0000-0000-0000-000000000005",
|
||||
"--outgoingGroupName" => "lotgd/tests/village/outside",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::SUCCESS, $command->getStatusCode());
|
||||
$this->assertStringContainsString("[OK]", $output);
|
||||
$this->assertStringNotContainsString("[ERROR]", $output);
|
||||
$this->assertStringContainsString("The two scenes were successfully connected.", $output);
|
||||
|
||||
$this->getEntityManager()->clear();
|
||||
$sceneRepository = $this->getEntityManager()->getRepository(Scene::class);
|
||||
|
||||
/** @var Scene $outgoing */
|
||||
$outgoing = $sceneRepository->find("30000000-0000-0000-0000-000000000001");
|
||||
/** @var Scene $outgoing */
|
||||
$incoming = $sceneRepository->find("30000000-0000-0000-0000-000000000005");
|
||||
|
||||
$this->assertTrue($outgoing->isConnectedTo($incoming));
|
||||
|
||||
$thatOne = null;
|
||||
/** @var SceneConnection $connection */
|
||||
foreach ($outgoing->getConnections() as $connection) {
|
||||
if (
|
||||
$connection->getOutgoingConnectionGroupName() === "lotgd/tests/village/outside"
|
||||
and $connection->getIncomingScene() === $incoming
|
||||
) {
|
||||
$thatOne = true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertTrue($thatOne);
|
||||
}
|
||||
|
||||
public function testIfScenesGetConnectedOnIncomingConnectionGroup()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"outgoing" => "30000000-0000-0000-0000-000000000005",
|
||||
"incoming" => "30000000-0000-0000-0000-000000000002",
|
||||
"--incomingGroupName" => "lotgd/tests/forest/category",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::SUCCESS, $command->getStatusCode());
|
||||
$this->assertStringContainsString("[OK]", $output);
|
||||
$this->assertStringNotContainsString("[ERROR]", $output);
|
||||
$this->assertStringContainsString("The two scenes were successfully connected.", $output);
|
||||
|
||||
$this->getEntityManager()->clear();
|
||||
$sceneRepository = $this->getEntityManager()->getRepository(Scene::class);
|
||||
|
||||
/** @var Scene $outgoing */
|
||||
$outgoing = $sceneRepository->find("30000000-0000-0000-0000-000000000005");
|
||||
/** @var Scene $outgoing */
|
||||
$incoming = $sceneRepository->find("30000000-0000-0000-0000-000000000002");
|
||||
|
||||
$this->assertTrue($outgoing->isConnectedTo($incoming));
|
||||
|
||||
$thatOne = null;
|
||||
/** @var SceneConnection $connection */
|
||||
foreach ($outgoing->getConnections() as $connection) {
|
||||
if (
|
||||
$connection->getIncomingConnectionGroupName() === "lotgd/tests/forest/category"
|
||||
and $connection->getIncomingScene() === $incoming
|
||||
) {
|
||||
$thatOne = true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertTrue($thatOne);
|
||||
}
|
||||
|
||||
public function testIfScenesGetConnectedOnBothConnectionGroup()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"outgoing" => "30000000-0000-0000-0000-000000000002",
|
||||
"incoming" => "30000000-0000-0000-0000-000000000003",
|
||||
"--outgoingGroupName" => "lotgd/tests/forest/category",
|
||||
"--incomingGroupName" => "lotgd/tests/weaponry/category",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::SUCCESS, $command->getStatusCode());
|
||||
$this->assertStringContainsString("[OK]", $output);
|
||||
$this->assertStringNotContainsString("[ERROR]", $output);
|
||||
$this->assertStringContainsString("The two scenes were successfully connected.", $output);
|
||||
|
||||
$this->getEntityManager()->clear();
|
||||
$sceneRepository = $this->getEntityManager()->getRepository(Scene::class);
|
||||
|
||||
/** @var Scene $outgoing */
|
||||
$outgoing = $sceneRepository->find("30000000-0000-0000-0000-000000000002");
|
||||
/** @var Scene $outgoing */
|
||||
$incoming = $sceneRepository->find("30000000-0000-0000-0000-000000000003");
|
||||
|
||||
$this->assertTrue($outgoing->isConnectedTo($incoming));
|
||||
|
||||
$thatOne = null;
|
||||
/** @var SceneConnection $connection */
|
||||
foreach ($outgoing->getConnections() as $connection) {
|
||||
if (
|
||||
$connection->getOutgoingConnectionGroupName() === "lotgd/tests/forest/category"
|
||||
and $connection->getIncomingConnectionGroupName() === "lotgd/tests/weaponry/category"
|
||||
and $connection->getIncomingScene() === $incoming
|
||||
) {
|
||||
$thatOne = true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertTrue($thatOne);
|
||||
}
|
||||
|
||||
public function testIfUnidirectionalSceneConnectionWorks()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"outgoing" => "30000000-0000-0000-0000-000000000004",
|
||||
"incoming" => "30000000-0000-0000-0000-000000000002",
|
||||
"--directionality" => "1",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::SUCCESS, $command->getStatusCode());
|
||||
$this->assertStringContainsString("[OK]", $output);
|
||||
$this->assertStringNotContainsString("[ERROR]", $output);
|
||||
$this->assertStringContainsString("The two scenes were successfully connected.", $output);
|
||||
|
||||
$this->getEntityManager()->clear();
|
||||
$sceneRepository = $this->getEntityManager()->getRepository(Scene::class);
|
||||
|
||||
/** @var Scene $outgoing */
|
||||
$outgoing = $sceneRepository->find("30000000-0000-0000-0000-000000000004");
|
||||
/** @var Scene $outgoing */
|
||||
$incoming = $sceneRepository->find("30000000-0000-0000-0000-000000000002");
|
||||
|
||||
$thatOne = null;
|
||||
/** @var SceneConnection $connection */
|
||||
foreach ($outgoing->getConnections() as $connection) {
|
||||
if (
|
||||
$connection->getIncomingScene() === $incoming
|
||||
and $connection->isDirectionality(1)
|
||||
) {
|
||||
$thatOne = true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertTrue($thatOne);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Tests\Commands\SceneCommands;
|
||||
|
||||
use LotGD\Core\Console\Command\Scene\SceneDisconnectCommand;
|
||||
use LotGD\Core\Tests\CoreModelTestCase;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
class SceneDisconnectCommandTest extends CoreModelTestCase
|
||||
{
|
||||
/** @var string default data set */
|
||||
protected $dataset = "scene-2";
|
||||
|
||||
protected function getCommand(): CommandTester
|
||||
{
|
||||
return new CommandTester(new SceneDisconnectCommand($this->g));
|
||||
}
|
||||
|
||||
public function testIfCommandFailsIfNoSceneWasGiven()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$command->execute([]);
|
||||
}
|
||||
|
||||
public function testIfCommandFailsIfScene1WasNotGiven()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$command->execute([
|
||||
"scene2" => "A"
|
||||
]);
|
||||
}
|
||||
|
||||
public function testIfCommandFailsIfScene2WasNotGiven()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$command->execute([
|
||||
"scene1" => "A"
|
||||
]);
|
||||
}
|
||||
|
||||
public function testIfCommandFailsIfScene1WasNotFound()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"scene1" => "30000000-0000-0000-0000-000000000000",
|
||||
"scene2" => "30000000-0000-0000-0000-000000000005",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::FAILURE, $command->getStatusCode());
|
||||
$this->assertStringContainsString("[ERROR]", $output);
|
||||
$this->assertStringContainsString("Scene with id 30000000-0000-0000-0000-000000000000 was not found.", $output);
|
||||
$this->assertStringNotContainsString("[OK]", $output);
|
||||
}
|
||||
|
||||
public function testIfCommandFailsIfScene2WasNotFound()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"scene1" => "30000000-0000-0000-0000-000000000005",
|
||||
"scene2" => "30000000-0000-0000-0000-000000000000",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::FAILURE, $command->getStatusCode());
|
||||
$this->assertStringContainsString("[ERROR]", $output);
|
||||
$this->assertStringContainsString("Scene with id 30000000-0000-0000-0000-000000000000 was not found.", $output);
|
||||
$this->assertStringNotContainsString("[OK]", $output);
|
||||
}
|
||||
|
||||
public function testIfCommandFailsWhenBothScenesDontShareAConnection()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"scene1" => "30000000-0000-0000-0000-000000000005",
|
||||
"scene2" => "30000000-0000-0000-0000-000000000001",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::FAILURE, $command->getStatusCode());
|
||||
$this->assertStringContainsString("[ERROR]", $output);
|
||||
$this->assertStringContainsString("The given scenes do not share a connection.", $output);
|
||||
$this->assertStringNotContainsString("[OK]", $output);
|
||||
}
|
||||
|
||||
public function testIfCommandSucceedsWhenBothScenesShareAConnection()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"scene1" => "30000000-0000-0000-0000-000000000001",
|
||||
"scene2" => "30000000-0000-0000-0000-000000000002",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::SUCCESS, $command->getStatusCode());
|
||||
$this->assertStringContainsString("[OK]", $output);
|
||||
$this->assertStringContainsString("The connections between the two given scenes was removed.", $output);
|
||||
$this->assertStringNotContainsString("[ERROR]", $output);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Tests\Commands\SceneCommands;
|
||||
|
||||
use LotGD\Core\Console\Command\Scene\SceneListCommand;
|
||||
use LotGD\Core\Tests\CoreModelTestCase;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
class SceneListCommandTest extends CoreModelTestCase
|
||||
{
|
||||
/** @var string default data set */
|
||||
protected $dataset = "scene-2";
|
||||
|
||||
protected function getCommand(): CommandTester
|
||||
{
|
||||
return new CommandTester(new SceneListCommand($this->g));
|
||||
}
|
||||
|
||||
public function testIfCommandSucceedsWithoutAArguments()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
$command->execute([]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::SUCCESS, $command->getStatusCode());
|
||||
|
||||
$dataset = $this->getDataSet();
|
||||
$databaseScenes = $dataset["scenes"];
|
||||
$databaseSceneConnections = $dataset["scene_connections"];
|
||||
$connections = [];
|
||||
foreach ($databaseSceneConnections as $connection) {
|
||||
if (!isset($connections[$connection["outgoingScene"]])) {
|
||||
$connections[$connection["outgoingScene"]] = 0;
|
||||
}
|
||||
|
||||
$connections[$connection["outgoingScene"]] += 1;
|
||||
|
||||
|
||||
if (!isset($connections[$connection["incomingScene"]])) {
|
||||
$connections[$connection["incomingScene"]] = 0;
|
||||
}
|
||||
|
||||
$connections[$connection["incomingScene"]] += 1;
|
||||
}
|
||||
|
||||
foreach ($databaseScenes as $scene) {
|
||||
// Assert details on the list
|
||||
$this->assertStringContainsString($scene["id"], $output);
|
||||
$this->assertStringContainsString($scene["title"], $output);
|
||||
if ($scene["template"]) {
|
||||
$this->assertStringContainsString($scene["template"], $output);
|
||||
}
|
||||
if (isset($connections[$scene["id"]])) {
|
||||
$this->assertStringContainsString((string)$connections[$scene["id"]], $output);
|
||||
} else {
|
||||
$this->assertStringContainsString("0", $output);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Tests\Commands\SceneCommands;
|
||||
|
||||
use LotGD\Core\Console\Command\Scene\SceneRemoveCommand;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use LotGD\Core\Tests\CoreModelTestCase;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
class SceneRemoveCommandTest extends CoreModelTestCase
|
||||
{
|
||||
/** @var string default data set */
|
||||
protected $dataset = "scene-2";
|
||||
|
||||
protected function getCommand(): CommandTester
|
||||
{
|
||||
return new CommandTester(new SceneRemoveCommand($this->g));
|
||||
}
|
||||
|
||||
public function testIfCommandFailsIfNoSceneIdWasGiven()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$command->execute([]);
|
||||
}
|
||||
|
||||
public function testIfCommandFailsIfSceneIdDoesNotExist()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"id" => "30000000-0000-0000-0000-000000000000",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::FAILURE, $command->getStatusCode());
|
||||
$this->assertStringContainsString("[ERROR]", $output);
|
||||
$this->assertStringContainsString("The scene with the ID 30000000-0000-0000-0000-000000000000 was not found.", $output);
|
||||
$this->assertStringNotContainsString("[OK]", $output);
|
||||
}
|
||||
|
||||
public function testIfCommandFailsIfSceneWasMarkedAsNotRemoveable()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"id" => "30000000-0000-0000-0000-000000000005",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::FAILURE, $command->getStatusCode());
|
||||
$this->assertStringContainsString("[ERROR]", $output);
|
||||
$this->assertStringContainsString("The scene with the ID 30000000-0000-0000-0000-000000000005 was marked as not ", $output);
|
||||
$this->assertStringNotContainsString("[OK]", $output);
|
||||
}
|
||||
|
||||
public function testIfCommandSucceeds()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"id" => "30000000-0000-0000-0000-000000000001",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::SUCCESS, $command->getStatusCode());
|
||||
$this->assertStringContainsString("[OK]", $output);
|
||||
$this->assertStringContainsString("was successfully removed.", $output);
|
||||
$this->assertStringNotContainsString("[ERROR]", $output);
|
||||
|
||||
// Assert database result
|
||||
$this->getEntityManager()->clear();
|
||||
|
||||
$this->assertNull($this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000001"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Tests\Commands\SceneCommands;
|
||||
|
||||
use LotGD\Core\Console\Command\Scene\SceneRemoveConnectionGroupCommand;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use LotGD\Core\Tests\CoreModelTestCase;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
class SceneRemoveConnectionGroupCommandTest extends CoreModelTestCase
|
||||
{
|
||||
/** @var string default data set */
|
||||
protected $dataset = "scene-2";
|
||||
|
||||
protected function getCommand(): CommandTester
|
||||
{
|
||||
return new CommandTester(new SceneRemoveConnectionGroupCommand($this->g));
|
||||
}
|
||||
|
||||
public function testIfCommandFailsIfNoSceneIdWasGiven()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$command->execute([]);
|
||||
}
|
||||
|
||||
public function testIfCommandFailsIfSceneIdDoesNotExist()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"id" => "30000000-0000-0000-0000-000000000000",
|
||||
"groupName" => "nobody/nothing",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::FAILURE, $command->getStatusCode());
|
||||
$this->assertStringContainsString("[ERROR]", $output);
|
||||
$this->assertStringContainsString("The scene with the ID 30000000-0000-0000-0000-000000000000 was not found.", $output);
|
||||
$this->assertStringNotContainsString("[OK]", $output);
|
||||
}
|
||||
|
||||
public function testIfCommandFailsWhenSceneDoesNotHaveGivenConnectionGroup()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"id" => "30000000-0000-0000-0000-000000000001",
|
||||
"groupName" => "nobody/nothing",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::FAILURE, $command->getStatusCode());
|
||||
$this->assertStringContainsString("[ERROR]", $output);
|
||||
$this->assertStringContainsString("The scene 30000000-0000-0000-0000-000000000001 does not have a connection group with the name", $output);
|
||||
$this->assertStringNotContainsString("[OK]", $output);
|
||||
}
|
||||
|
||||
public function testIfCommandSuccessfullyRemovesGroup()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"id" => "30000000-0000-0000-0000-000000000001",
|
||||
"groupName" => "lotgd/tests/village/outside",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::SUCCESS, $command->getStatusCode());
|
||||
$this->assertStringContainsString("[OK]", $output);
|
||||
$this->assertStringNotContainsString("[ERROR]", $output);
|
||||
$this->assertStringNotContainsString("//", $output);
|
||||
$this->assertStringContainsString(" was successfully removed", $output);
|
||||
|
||||
// Assert on database level (make sure command calls flush)
|
||||
$this->getEntityManager()->clear();
|
||||
/** @var Scene $scene */
|
||||
$scene = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000001");
|
||||
$this->assertNotNull($scene);
|
||||
$this->assertFalse($scene->hasConnectionGroup("lotgd/tests/village/outside"));
|
||||
}
|
||||
|
||||
public function testIfCommandSuccessfullyRemovesGroupAndMovesConnectionDirectlyToTheOutgoingScene()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"id" => "30000000-0000-0000-0000-000000000001",
|
||||
"groupName" => "lotgd/tests/village/market",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::SUCCESS, $command->getStatusCode());
|
||||
$this->assertStringContainsString("[OK]", $output);
|
||||
$this->assertStringNotContainsString("[ERROR]", $output);
|
||||
$this->assertStringContainsString("//", $output);
|
||||
$this->assertStringContainsString("Updated connection to", $output);
|
||||
$this->assertStringContainsString(" was successfully removed", $output);
|
||||
|
||||
// Assert on database level (make sure command calls flush)
|
||||
$this->getEntityManager()->clear();
|
||||
/** @var Scene $scene */
|
||||
$scene = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000001");
|
||||
$otherScene = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000003");
|
||||
$this->assertNotNull($scene);
|
||||
$connection = $scene->getConnectionTo($otherScene);
|
||||
$this->assertNotNull($connection);
|
||||
$this->assertNull($connection->getOutgoingConnectionGroupName());
|
||||
$this->assertFalse($scene->hasConnectionGroup("lotgd/tests/village/market"));
|
||||
}
|
||||
|
||||
public function testIfCommandSuccessfullyRemovesGroupAndMovesConnectionDirectlyToTheIncomingScene()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"id" => "30000000-0000-0000-0000-000000000003",
|
||||
"groupName" => "lotgd/tests/weaponry/category",
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::SUCCESS, $command->getStatusCode());
|
||||
$this->assertStringContainsString("[OK]", $output);
|
||||
$this->assertStringNotContainsString("[ERROR]", $output);
|
||||
$this->assertStringContainsString("//", $output);
|
||||
$this->assertStringContainsString("Updated connection to", $output);
|
||||
$this->assertStringContainsString(" was successfully removed", $output);
|
||||
|
||||
// Assert on database level (make sure command calls flush)
|
||||
$this->getEntityManager()->clear();
|
||||
/** @var Scene $scene */
|
||||
$scene = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000001");
|
||||
$otherScene = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000003");
|
||||
$this->assertNotNull($scene);
|
||||
$connection = $scene->getConnectionTo($otherScene);
|
||||
$this->assertNotNull($connection);
|
||||
$this->assertNull($connection->getIncomingConnectionGroupName());
|
||||
$this->assertFalse($scene->hasConnectionGroup("lotgd/tests/weaponry/category"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Tests\Commands\SceneCommands;
|
||||
|
||||
use LotGD\Core\Console\Command\Scene\SceneShowCommand;
|
||||
use LotGD\Core\Tests\CoreModelTestCase;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
class SceneShowCommandTest extends CoreModelTestCase
|
||||
{
|
||||
/** @var string default data set */
|
||||
protected $dataset = "scene-2";
|
||||
|
||||
protected function getCommand(): CommandTester
|
||||
{
|
||||
return new CommandTester(new SceneShowCommand($this->g));
|
||||
}
|
||||
|
||||
public function testIfCommandFailsIfNoSceneIdWasGiven()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$command->execute([]);
|
||||
}
|
||||
|
||||
public function testIfCommandSucceedsIfIdWasFound()
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
$command->execute([
|
||||
"id" => "30000000-0000-0000-0000-000000000006"
|
||||
]);
|
||||
$output = $command->getDisplay();
|
||||
|
||||
$this->assertSame(Command::SUCCESS, $command->getStatusCode());
|
||||
|
||||
$this->assertStringContainsString("Connection Test Scene", $output);
|
||||
$this->assertStringContainsString("30000000-0000-0000-0000-000000000006", $output);
|
||||
$this->assertStringContainsString("LotGD\\Core\\Tests\\SceneTemplates\\Village", $output);
|
||||
$this->assertStringContainsString("This is a connection test scene", $output);
|
||||
|
||||
$this->assertStringContainsString("Group One (id=lotgd/tests/testscene/one)", $output);
|
||||
$this->assertStringContainsString("Group Two (id=lotgd/tests/testscene/two)", $output);
|
||||
$this->assertStringContainsString("Group Three (id=lotgd/tests/testscene/three)", $output);
|
||||
|
||||
$this->assertStringContainsString("this <=> The Village (id=30000000-0000-0000-0000-000000000001)", $output);
|
||||
$this->assertStringContainsString("this (on lotgd/tests/testscene/three) => The Weaponry (id=30000000-0000-0000-0000-000000000003)", $output);
|
||||
$this->assertStringContainsString("this (on lotgd/tests/testscene/three) <= The Forest (id=30000000-0000-0000-0000-000000000002)", $output);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
scenes:
|
||||
-
|
||||
id: "30000000-0000-0000-0000-000000000001"
|
||||
title: "The Village"
|
||||
description: "This is the village."
|
||||
template: "LotGD\\Core\\Tests\\SceneTemplates\\Village"
|
||||
removeable: true
|
||||
-
|
||||
id: "30000000-0000-0000-0000-000000000002"
|
||||
title: "The Forest"
|
||||
description: "This is a very dangerous and dark forest"
|
||||
template: "LotGD\\Core\\Tests\\SceneTemplates\\Forest"
|
||||
removeable: true
|
||||
-
|
||||
id: "30000000-0000-0000-0000-000000000003"
|
||||
title: "The Weaponry"
|
||||
description: "This is the place where you can buy awesome weapons"
|
||||
template: null
|
||||
removeable: true
|
||||
-
|
||||
id: "30000000-0000-0000-0000-000000000004"
|
||||
title: "Another Village"
|
||||
description: "This is another village"
|
||||
template: "LotGD\\Core\\Tests\\SceneTemplates\\Village"
|
||||
removeable: true
|
||||
-
|
||||
id: "30000000-0000-0000-0000-000000000005"
|
||||
title: "Orphan"
|
||||
description: "This is an orphan scene"
|
||||
template: null
|
||||
removeable: false
|
||||
-
|
||||
id: "30000000-0000-0000-0000-000000000006"
|
||||
title: "Connection Test Scene"
|
||||
description: "This is a connection test scene"
|
||||
template: "LotGD\\Core\\Tests\\SceneTemplates\\Village"
|
||||
removeable: true
|
||||
scene_connection_groups:
|
||||
-
|
||||
scene: "30000000-0000-0000-0000-000000000001"
|
||||
name: "lotgd/tests/village/outside"
|
||||
title: "Outside"
|
||||
-
|
||||
scene: "30000000-0000-0000-0000-000000000001"
|
||||
name: "lotgd/tests/village/market"
|
||||
title: "Market"
|
||||
-
|
||||
scene: "30000000-0000-0000-0000-000000000001"
|
||||
name: "lotgd/tests/village/empty"
|
||||
title: "Empty"
|
||||
-
|
||||
scene: "30000000-0000-0000-0000-000000000002"
|
||||
name: "lotgd/tests/forest/category"
|
||||
title: "Empty"
|
||||
-
|
||||
scene: "30000000-0000-0000-0000-000000000003"
|
||||
name: "lotgd/tests/weaponry/category"
|
||||
title: "Empty"
|
||||
-
|
||||
scene: "30000000-0000-0000-0000-000000000006"
|
||||
name: "lotgd/tests/testscene/one"
|
||||
title: "Group One"
|
||||
-
|
||||
scene: "30000000-0000-0000-0000-000000000006"
|
||||
name: "lotgd/tests/testscene/two"
|
||||
title: "Group Two"
|
||||
-
|
||||
scene: "30000000-0000-0000-0000-000000000006"
|
||||
name: "lotgd/tests/testscene/three"
|
||||
title: "Group Three"
|
||||
scene_connections:
|
||||
-
|
||||
outgoingScene: "30000000-0000-0000-0000-000000000001"
|
||||
incomingScene: "30000000-0000-0000-0000-000000000002"
|
||||
-
|
||||
outgoingScene: "30000000-0000-0000-0000-000000000001"
|
||||
outgoingConnectionGroupName: "lotgd/tests/village/market"
|
||||
incomingScene: "30000000-0000-0000-0000-000000000003"
|
||||
incomingConnectionGroupName: "lotgd/tests/weaponry/category"
|
||||
-
|
||||
outgoingScene: "30000000-0000-0000-0000-000000000001"
|
||||
incomingScene: "30000000-0000-0000-0000-000000000004"
|
||||
-
|
||||
outgoingScene: "30000000-0000-0000-0000-000000000006"
|
||||
incomingScene: "30000000-0000-0000-0000-000000000001"
|
||||
-
|
||||
outgoingScene: "30000000-0000-0000-0000-000000000002"
|
||||
incomingScene: "30000000-0000-0000-0000-000000000006"
|
||||
incomingConnectionGroupName: "lotgd/tests/testscene/three"
|
||||
directionality: 1
|
||||
-
|
||||
outgoingScene: "30000000-0000-0000-0000-000000000006"
|
||||
outgoingConnectionGroupName: "lotgd/tests/testscene/three"
|
||||
incomingScene: "30000000-0000-0000-0000-000000000003"
|
||||
directionality: 1
|
||||
scene_templates:
|
||||
-
|
||||
class: "LotGD\\Core\\Tests\\SceneTemplates\\Village"
|
||||
module: "lotgd/core"
|
||||
userAssignable: true
|
||||
-
|
||||
class: "LotGD\\Core\\Tests\\SceneTemplates\\Forest"
|
||||
module: "lotgd/core"
|
||||
userAssignable: true
|
||||
-
|
||||
class: "LotGD\\Core\\Tests\\SceneTemplates\\NewSceneSceneTemplate"
|
||||
module: "lotgd/core"
|
||||
userAssignable: true
|
||||
Reference in New Issue
Block a user