Model changes
Adds basic Scene model Extends Character model with reusable properties (Using the two traits Properties and PropertyManager).
This commit is contained in:
@@ -6,8 +6,6 @@ namespace LotGD\Core\Tests\Models;
|
||||
use LotGD\Core\Models\Character;
|
||||
use LotGD\Core\Tests\ModelTestCase;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Description of CharacterModelTest
|
||||
*
|
||||
@@ -21,7 +19,8 @@ class CharacterModelTest extends ModelTestCase {
|
||||
* Returns data to create valid characters
|
||||
* @return array $futureId => $characterData
|
||||
*/
|
||||
public function validCharacters() {
|
||||
public function validCharacters(): array
|
||||
{
|
||||
return [
|
||||
[[
|
||||
"name" => "Testcharacter",
|
||||
@@ -38,7 +37,8 @@ class CharacterModelTest extends ModelTestCase {
|
||||
* Returns data to create invalid characters
|
||||
* @return array A list of faulty characters
|
||||
*/
|
||||
public function invalidCharacters() {
|
||||
public function invalidCharacters(): array
|
||||
{
|
||||
return [
|
||||
[[
|
||||
"name" => 16,
|
||||
@@ -56,7 +56,8 @@ class CharacterModelTest extends ModelTestCase {
|
||||
* @param array $characterData
|
||||
* @dataProvider validCharacters
|
||||
*/
|
||||
public function testCreation(array $characterData) {
|
||||
public function testCreation(array $characterData)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$characterEntity = Character::create($characterData);
|
||||
@@ -71,7 +72,8 @@ class CharacterModelTest extends ModelTestCase {
|
||||
* @dataProvider invalidCharacters
|
||||
* @expectedException TypeError
|
||||
*/
|
||||
public function testFaultyCreation(array $characterData) {
|
||||
public function testFaultyCreation(array $characterData)
|
||||
{
|
||||
Character::create($characterData);
|
||||
}
|
||||
|
||||
@@ -79,7 +81,8 @@ class CharacterModelTest extends ModelTestCase {
|
||||
* Tests if invalid array key given during Character::create throws an exception
|
||||
* @expectedException \LotGD\Core\Exceptions\UnexpectedArrayKeyException
|
||||
*/
|
||||
public function testUnknownArrayKey() {
|
||||
public function testUnknownArrayKey()
|
||||
{
|
||||
Character::create([
|
||||
"name" => "Walter",
|
||||
"maxHealth" => 15,
|
||||
@@ -90,7 +93,8 @@ class CharacterModelTest extends ModelTestCase {
|
||||
/**
|
||||
* Tests if Deletor does it's work
|
||||
*/
|
||||
public function testDeletion() {
|
||||
public function testDeletion()
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
// Count rows before
|
||||
@@ -104,4 +108,30 @@ class CharacterModelTest extends ModelTestCase {
|
||||
|
||||
$this->assertEquals($rowsBefore - 1, $rowsAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests character properties
|
||||
*/
|
||||
public function testProperties()
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
// test default values
|
||||
$firstCharacter = $em->getRepository(Character::class)->find(1);
|
||||
$this->assertSame(5, $firstCharacter->getProperty("dragonkills", 5));
|
||||
$this->assertNotSame(5, $firstCharacter->getProperty("dragonkills", "5"));
|
||||
$this->assertSame("hanniball", $firstCharacter->getProperty("petname", "hanniball"));
|
||||
|
||||
// test setting variables, then getting
|
||||
$firstCharacter->setProperty("dragonkills", 5);
|
||||
$this->assertSame(5, $firstCharacter->getProperty("dragonkills"));
|
||||
$this->assertNotSame("5", $firstCharacter->getProperty("dragonkills"));
|
||||
|
||||
$firstCharacter->setProperty("dragonkills", "20");
|
||||
$this->assertNotSame(20, $firstCharacter->getProperty("dragonkills"));
|
||||
$this->assertSame("20", $firstCharacter->getProperty("dragonkills"));
|
||||
|
||||
// test precreated property
|
||||
$this->assertSame("hallo", $firstCharacter->getProperty("test"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Tests\Models;
|
||||
|
||||
use LotGD\Core\Models\Scene;
|
||||
use LotGD\Core\Tests\ModelTestCase;
|
||||
|
||||
/**
|
||||
* Description of CharacterModelTest
|
||||
*/
|
||||
class SceneModelTest extends ModelTestCase
|
||||
{
|
||||
/** @var string default data set */
|
||||
protected $dataset = "scene";
|
||||
|
||||
/**
|
||||
* Test getter methods
|
||||
*/
|
||||
public function testGetters()
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$scene = $em->getRepository(Scene::class)->find(2);
|
||||
|
||||
$this->assertEquals("The Forest", $scene->getTitle());
|
||||
$this->assertEquals("This is a very dangerous and dark forest", $scene->getDescription());
|
||||
$this->assertInstanceOf(Scene::class, $scene->getParent());
|
||||
$this->assertEquals(true, $scene->hasParent());
|
||||
$this->assertEquals(false, $scene->hasChildren());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if parent<=>child relationship is working.
|
||||
*/
|
||||
public function testChildParentRelationships()
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$parentScene = $em->getRepository(Scene::class)->find(1);
|
||||
$childScene = $em->getRepository(Scene::class)->find(2);
|
||||
|
||||
$this->assertEquals($parentScene, $childScene->getParent());
|
||||
$this->assertContains($childScene, $parentScene->getChildren());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the scene can be removed.
|
||||
*/
|
||||
public function testMoveScene()
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$parentScene1 = $em->getRepository(Scene::class)->find(1);
|
||||
$parentScene2 = $em->getRepository(Scene::class)->find(4);
|
||||
|
||||
$orphanScene = $em->getRepository(scene::class)->find(5);
|
||||
$this->assertEquals(false, $orphanScene->hasParent());
|
||||
$this->assertEquals(false, $orphanScene->hasChildren());
|
||||
|
||||
// Assign orphanScene to parentScene1 and check relationships
|
||||
$orphanScene->setParent($parentScene1);
|
||||
|
||||
$this->assertEquals(true, $orphanScene->hasParent());
|
||||
$this->assertCount(3, $parentScene1->getChildren());
|
||||
$this->assertEquals($parentScene1, $orphanScene->getParent());
|
||||
$this->assertContains($orphanScene, $parentScene1->getChildren());
|
||||
|
||||
// Move the scene now to parentScene2 and check relationships
|
||||
$orphanScene->setParent($parentScene2);
|
||||
|
||||
$this->assertCount(2, $parentScene1->getChildren());
|
||||
$this->assertCount(1, $parentScene2->getChildren());
|
||||
$this->assertEquals($parentScene2, $orphanScene->getParent());
|
||||
$this->assertContains($orphanScene, $parentScene2->getChildren());
|
||||
|
||||
// Make an orphan out of it again
|
||||
$orphanScene->setParent(null);
|
||||
|
||||
$this->assertCount(2, $parentScene1->getChildren());
|
||||
$this->assertCount(0, $parentScene2->getChildren());
|
||||
$this->assertEquals(false, $orphanScene->hasParent());
|
||||
$this->assertNotContains($orphanScene, $parentScene1->getChildren());
|
||||
$this->assertNotContains($orphanScene, $parentScene2->getChildren());
|
||||
}
|
||||
}
|
||||
@@ -10,4 +10,9 @@ characters:
|
||||
name: "Testcharacter 2"
|
||||
displayName: "Testcharacter 2"
|
||||
health: 90
|
||||
maxhealth: 90
|
||||
maxhealth: 90
|
||||
character_properties:
|
||||
-
|
||||
owner_id: 1
|
||||
propertyName: "test"
|
||||
propertyValue: 's:5:"hallo";'
|
||||
@@ -1,13 +1,26 @@
|
||||
characters:
|
||||
scenes:
|
||||
-
|
||||
id: 1
|
||||
name: "Testcharacter 1"
|
||||
displayName: "Testcharacter 1"
|
||||
health: 0
|
||||
maxhealth: 100
|
||||
title: "The Village"
|
||||
description: "This is the village."
|
||||
parent:
|
||||
-
|
||||
id: 2
|
||||
name: "Testcharacter 2"
|
||||
displayName: "Testcharacter 2"
|
||||
health: 90
|
||||
maxhealth: 90
|
||||
title: "The Forest"
|
||||
description: "This is a very dangerous and dark forest"
|
||||
parent: 1
|
||||
-
|
||||
id: 3
|
||||
title: "The Weaponry"
|
||||
description: "This is the place where you can buy awesome weapons"
|
||||
parent: 1
|
||||
-
|
||||
id: 4
|
||||
title: "Another Village"
|
||||
description: "This is another village"
|
||||
parent:
|
||||
-
|
||||
id: 5
|
||||
title: "Orphan"
|
||||
description: "This is an orphan scene"
|
||||
parent:
|
||||
Reference in New Issue
Block a user