Minor fixes and changes

The tests are now using sqlite inside of the memory. This ensures a
creation of the database every time the tests are run.
Added some additional tests for probing database persistance.
Removed outdated code.
This commit is contained in:
Basilius Sauter
2016-04-20 18:11:59 +02:00
parent 7643277cf7
commit 9986420b10
5 changed files with 23 additions and 7 deletions
BIN
View File
Binary file not shown.
+1 -1
View File
@@ -1,6 +1,6 @@
<phpunit bootstrap="bootstrap/bootstrap.php">
<php>
<var name="DB_DSN" value="sqlite:dbtest.sqlite" />
<var name="DB_DSN" value="sqlite::memory:" />
<var name="DB_USER" value="root" />
<var name="DB_PASSWORD" value="" />
<var name="DB_NAME" value="daenerys" />
-1
View File
@@ -2,7 +2,6 @@
namespace LotGD\Core\Models;
use LotGD\Core\Tools\Model\Creator;
use LotGD\Core\Tools\Model\Properties;
/**
+1 -5
View File
@@ -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.');
}
+21
View File
@@ -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);
}
}