diff --git a/dbtest.sqlite b/dbtest.sqlite deleted file mode 100644 index 965a8a7..0000000 Binary files a/dbtest.sqlite and /dev/null differ diff --git a/phpunit.xml b/phpunit.xml index 4ec1b21..ddcbd55 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,6 +1,6 @@ - + diff --git a/src/Models/CharacterProperty.php b/src/Models/CharacterProperty.php index 4ae6151..bc05122 100644 --- a/src/Models/CharacterProperty.php +++ b/src/Models/CharacterProperty.php @@ -2,7 +2,6 @@ namespace LotGD\Core\Models; -use LotGD\Core\Tools\Model\Creator; use LotGD\Core\Tools\Model\Properties; /** diff --git a/src/Tools/Model/Properties.php b/src/Tools/Model/Properties.php index 56e0d95..f873a38 100644 --- a/src/Tools/Model/Properties.php +++ b/src/Tools/Model/Properties.php @@ -3,10 +3,6 @@ declare(strict_types=1); namespace LotGD\Core\Tools\Model; -const PROPERTY_STRING = 0; -const PROPERTY_INT = 1; -const PROPERTY_FLOAT = 2; - /** * Provides method and doctrine annotation for a property submodel */ @@ -33,7 +29,7 @@ trait Properties */ public function setName(string $name) { - if($name === "") { + if ($name === "") { throw new ArgumentEmptyException('The argument $name must not be empty.'); } diff --git a/tests/Models/CharacterModelTest.php b/tests/Models/CharacterModelTest.php index 9a56153..4370b77 100644 --- a/tests/Models/CharacterModelTest.php +++ b/tests/Models/CharacterModelTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace LotGD\Core\Tests\Models; use LotGD\Core\Models\Character; +use LotGD\Core\Models\CharacterProperty; use LotGD\Core\Tests\ModelTestCase; /** @@ -107,6 +108,9 @@ class CharacterModelTest extends ModelTestCase { $rowsAfter = count($em->getRepository(Character::class)->findAll()); $this->assertEquals($rowsBefore - 1, $rowsAfter); + + // test flushing + $em->flush(); } /** @@ -131,7 +135,24 @@ class CharacterModelTest extends ModelTestCase { $this->assertNotSame(20, $firstCharacter->getProperty("dragonkills")); $this->assertSame("20", $firstCharacter->getProperty("dragonkills")); + // save some other variables + $firstCharacter->setProperty("testvar1", 5); + $firstCharacter->setProperty("testvar2", [5 => 18]); + $firstCharacter->setProperty("testvar3 9 8", "spam and eggs"); + $firstCharacter->setProperty("testvar4", true); + // test precreated property $this->assertSame("hallo", $firstCharacter->getProperty("test")); + + // test flushing + $em->flush(); + + // revisit database and retrieve properties, check if the correct number is saved + $total = intval($em->createQueryBuilder() + ->from(CharacterProperty::class, "u") + ->select("COUNT(u.propertyName)") + ->getQuery()->getSingleScalarResult()); + + $this->assertSame(6, $total); } }