From f72adb1a38762ab6719ecc0d9e1dcb10fcf99bc8 Mon Sep 17 00:00:00 2001 From: Vassyli Date: Mon, 15 Feb 2021 19:27:35 +0100 Subject: [PATCH] Adds tests for scene commands. --- .../Module/ModuleConfigResetCommand.php | 2 + src/Console/Command/Scene/SceneAddCommand.php | 19 +- .../Scene/SceneAddConnectionGroupCommand.php | 17 +- .../Command/Scene/SceneBaseCommand.php | 24 ++ .../Command/Scene/SceneConnectCommand.php | 13 +- .../Command/Scene/SceneDisconnectCommand.php | 17 +- .../Command/Scene/SceneListCommand.php | 9 +- .../Command/Scene/SceneRemoveCommand.php | 16 +- .../SceneRemoveConnectionGroupCommand.php | 17 +- .../Command/Scene/SceneShowCommand.php | 16 +- src/Models/Scene.php | 1 - .../ModuleConfigResetCommandTest.php | 13 +- .../SceneCommands/SceneAddCommandTest.php | 132 +++++++++ .../SceneAddConnectionGroupCommandTest.php | 89 ++++++ .../SceneCommands/SceneConnectCommandTest.php | 276 ++++++++++++++++++ .../SceneDisconnectCommandTest.php | 109 +++++++ .../SceneCommands/SceneListCommandTest.php | 62 ++++ .../SceneCommands/SceneRemoveCommandTest.php | 77 +++++ .../SceneRemoveConnectionGroupCommandTest.php | 139 +++++++++ .../SceneCommands/SceneShowCommandTest.php | 53 ++++ tests/datasets/scene-2.yml | 108 +++++++ 21 files changed, 1132 insertions(+), 77 deletions(-) create mode 100644 src/Console/Command/Scene/SceneBaseCommand.php create mode 100644 tests/Commands/SceneCommands/SceneAddCommandTest.php create mode 100644 tests/Commands/SceneCommands/SceneAddConnectionGroupCommandTest.php create mode 100644 tests/Commands/SceneCommands/SceneConnectCommandTest.php create mode 100644 tests/Commands/SceneCommands/SceneDisconnectCommandTest.php create mode 100644 tests/Commands/SceneCommands/SceneListCommandTest.php create mode 100644 tests/Commands/SceneCommands/SceneRemoveCommandTest.php create mode 100644 tests/Commands/SceneCommands/SceneRemoveConnectionGroupCommandTest.php create mode 100644 tests/Commands/SceneCommands/SceneShowCommandTest.php create mode 100644 tests/datasets/scene-2.yml diff --git a/src/Console/Command/Module/ModuleConfigResetCommand.php b/src/Console/Command/Module/ModuleConfigResetCommand.php index 38c587d..d652566 100644 --- a/src/Console/Command/Module/ModuleConfigResetCommand.php +++ b/src/Console/Command/Module/ModuleConfigResetCommand.php @@ -41,6 +41,8 @@ class ModuleConfigResetCommand extends ModuleBaseCommand return Command::FAILURE; } + $io->title("Module {$module->getLibrary()}"); + // Create hook $context = EventContextData::create([ "module" => $module, diff --git a/src/Console/Command/Scene/SceneAddCommand.php b/src/Console/Command/Scene/SceneAddCommand.php index 36167ae..a8ce6b0 100644 --- a/src/Console/Command/Scene/SceneAddCommand.php +++ b/src/Console/Command/Scene/SceneAddCommand.php @@ -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); diff --git a/src/Console/Command/Scene/SceneAddConnectionGroupCommand.php b/src/Console/Command/Scene/SceneAddConnectionGroupCommand.php index 0083f5a..b2d47fc 100644 --- a/src/Console/Command/Scene/SceneAddConnectionGroupCommand.php +++ b/src/Console/Command/Scene/SceneAddConnectionGroupCommand.php @@ -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."); diff --git a/src/Console/Command/Scene/SceneBaseCommand.php b/src/Console/Command/Scene/SceneBaseCommand.php new file mode 100644 index 0000000..d2bb89c --- /dev/null +++ b/src/Console/Command/Scene/SceneBaseCommand.php @@ -0,0 +1,24 @@ +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; } diff --git a/src/Console/Command/Scene/SceneDisconnectCommand.php b/src/Console/Command/Scene/SceneDisconnectCommand.php index b573d02..7d50d5a 100644 --- a/src/Console/Command/Scene/SceneDisconnectCommand.php +++ b/src/Console/Command/Scene/SceneDisconnectCommand.php @@ -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; } diff --git a/src/Console/Command/Scene/SceneListCommand.php b/src/Console/Command/Scene/SceneListCommand.php index 4bb5cb2..796c08b 100644 --- a/src/Console/Command/Scene/SceneListCommand.php +++ b/src/Console/Command/Scene/SceneListCommand.php @@ -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(), ]; } diff --git a/src/Console/Command/Scene/SceneRemoveCommand.php b/src/Console/Command/Scene/SceneRemoveCommand.php index d309aaf..339480a 100644 --- a/src/Console/Command/Scene/SceneRemoveCommand.php +++ b/src/Console/Command/Scene/SceneRemoveCommand.php @@ -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; } diff --git a/src/Console/Command/Scene/SceneRemoveConnectionGroupCommand.php b/src/Console/Command/Scene/SceneRemoveConnectionGroupCommand.php index 46c9333..88cbb43 100644 --- a/src/Console/Command/Scene/SceneRemoveConnectionGroupCommand.php +++ b/src/Console/Command/Scene/SceneRemoveConnectionGroupCommand.php @@ -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; } diff --git a/src/Console/Command/Scene/SceneShowCommand.php b/src/Console/Command/Scene/SceneShowCommand.php index 9c4b22c..d91c80e 100644 --- a/src/Console/Command/Scene/SceneShowCommand.php +++ b/src/Console/Command/Scene/SceneShowCommand.php @@ -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(); diff --git a/src/Models/Scene.php b/src/Models/Scene.php index 288b323..0b48229 100644 --- a/src/Models/Scene.php +++ b/src/Models/Scene.php @@ -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; diff --git a/tests/Commands/ModuleCommands/ModuleConfigResetCommandTest.php b/tests/Commands/ModuleCommands/ModuleConfigResetCommandTest.php index 368ef28..b2c8a58 100644 --- a/tests/Commands/ModuleCommands/ModuleConfigResetCommandTest.php +++ b/tests/Commands/ModuleCommands/ModuleConfigResetCommandTest.php @@ -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); } } diff --git a/tests/Commands/SceneCommands/SceneAddCommandTest.php b/tests/Commands/SceneCommands/SceneAddCommandTest.php new file mode 100644 index 0000000..2d5f06e --- /dev/null +++ b/tests/Commands/SceneCommands/SceneAddCommandTest.php @@ -0,0 +1,132 @@ +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()); + } +} \ No newline at end of file diff --git a/tests/Commands/SceneCommands/SceneAddConnectionGroupCommandTest.php b/tests/Commands/SceneCommands/SceneAddConnectionGroupCommandTest.php new file mode 100644 index 0000000..a394c89 --- /dev/null +++ b/tests/Commands/SceneCommands/SceneAddConnectionGroupCommandTest.php @@ -0,0 +1,89 @@ +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); + } +} \ No newline at end of file diff --git a/tests/Commands/SceneCommands/SceneConnectCommandTest.php b/tests/Commands/SceneCommands/SceneConnectCommandTest.php new file mode 100644 index 0000000..1585a4c --- /dev/null +++ b/tests/Commands/SceneCommands/SceneConnectCommandTest.php @@ -0,0 +1,276 @@ +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); + } +} \ No newline at end of file diff --git a/tests/Commands/SceneCommands/SceneDisconnectCommandTest.php b/tests/Commands/SceneCommands/SceneDisconnectCommandTest.php new file mode 100644 index 0000000..90d9ae6 --- /dev/null +++ b/tests/Commands/SceneCommands/SceneDisconnectCommandTest.php @@ -0,0 +1,109 @@ +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); + } +} \ No newline at end of file diff --git a/tests/Commands/SceneCommands/SceneListCommandTest.php b/tests/Commands/SceneCommands/SceneListCommandTest.php new file mode 100644 index 0000000..2cd8c04 --- /dev/null +++ b/tests/Commands/SceneCommands/SceneListCommandTest.php @@ -0,0 +1,62 @@ +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); + } + } + } +} \ No newline at end of file diff --git a/tests/Commands/SceneCommands/SceneRemoveCommandTest.php b/tests/Commands/SceneCommands/SceneRemoveCommandTest.php new file mode 100644 index 0000000..90dfcad --- /dev/null +++ b/tests/Commands/SceneCommands/SceneRemoveCommandTest.php @@ -0,0 +1,77 @@ +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")); + } +} \ No newline at end of file diff --git a/tests/Commands/SceneCommands/SceneRemoveConnectionGroupCommandTest.php b/tests/Commands/SceneCommands/SceneRemoveConnectionGroupCommandTest.php new file mode 100644 index 0000000..f572f93 --- /dev/null +++ b/tests/Commands/SceneCommands/SceneRemoveConnectionGroupCommandTest.php @@ -0,0 +1,139 @@ +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")); + } +} \ No newline at end of file diff --git a/tests/Commands/SceneCommands/SceneShowCommandTest.php b/tests/Commands/SceneCommands/SceneShowCommandTest.php new file mode 100644 index 0000000..0644bc9 --- /dev/null +++ b/tests/Commands/SceneCommands/SceneShowCommandTest.php @@ -0,0 +1,53 @@ +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); + } +} \ No newline at end of file diff --git a/tests/datasets/scene-2.yml b/tests/datasets/scene-2.yml new file mode 100644 index 0000000..8624d42 --- /dev/null +++ b/tests/datasets/scene-2.yml @@ -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 \ No newline at end of file