Adds tests for scene commands.

This commit is contained in:
Vassyli
2021-02-15 19:27:35 +01:00
committed by Basilius Sauter
parent 0292a66252
commit f72adb1a38
21 changed files with 1132 additions and 77 deletions
@@ -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);
}
}
+108
View File
@@ -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