Skip to content

Commit

Permalink
Adds a test and the corresponding bugfix.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vassyli committed Feb 3, 2021
1 parent 60a3a8b commit f7504bb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Models/Scene.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,17 @@ public function hasConnectionGroup(string $name): bool
/**
* Returns a connection group entity associated with this scene by a given name.
* @param string $name
* @return SceneConnectionGroup
* @return SceneConnectionGroup|null
*/
public function getConnectionGroup(string $name): SceneConnectionGroup
public function getConnectionGroup(string $name): ?SceneConnectionGroup
{
return $this->filterConnectionGroupCollectionByName($name)->first();
$filtered = $this->filterConnectionGroupCollectionByName($name)->first();

if (!$filtered) {
return null;
} else {
return $filtered;
}
}

/**
Expand Down
17 changes: 17 additions & 0 deletions tests/Models/SceneModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,21 @@ public function testIfConnectingASceneToAnotherAlreadyConnectedSceneThrowsAnExce
$this->expectException(ArgumentException::class);
$scene1->getConnectionGroup("lotgd/tests/village/hidden")->connect($scene2->getConnectionGroup("lotgd/tests/forest/category"));
}

/**
* @see https://github.com/lotgd/core/issues/150
*/
public function testIfGetConnectionGroupReturnsNullAndDoesNotThrowATypeError()
{
$scene1 = $this->getEntityManager()->getRepository(Scene::class)->find("30000000-0000-0000-0000-000000000001");

# Positively assert that this usually works
$connectionGroup = $scene1->getConnectionGroup("lotgd/tests/village/empty");
$this->assertNotNull($connectionGroup);
$this->assertInstanceOf(SceneConnectionGroup::class, $connectionGroup);

# Assert that connectionGroup is null if it does not exist.
$connectionGroup = $scene1->getConnectionGroup("this-does-not-exist");
$this->assertNull($connectionGroup);
}
}

0 comments on commit f7504bb

Please sign in to comment.