Remove extra whitespace in CharacterModelTest
This commit is contained in:
@@ -15,7 +15,7 @@ class CharacterModelTest extends CoreModelTestCase
|
||||
{
|
||||
/** @var string default data set */
|
||||
protected $dataset = "character";
|
||||
|
||||
|
||||
/**
|
||||
* Tests for soft deletion
|
||||
*/
|
||||
@@ -23,27 +23,27 @@ class CharacterModelTest extends CoreModelTestCase
|
||||
{
|
||||
$chars = $this->getEntityManager()->getRepository(Character::class)->find(3);
|
||||
$this->assertSame(null, $chars);
|
||||
|
||||
|
||||
$allChars = $this->getEntityManager()->getRepository(Character::class)->findAll();
|
||||
$this->assertSame(2, count($allChars));
|
||||
|
||||
|
||||
$char = $this->getEntityManager()->getRepository(Character::class)->find(1);
|
||||
$char->delete($this->getEntityManager());
|
||||
$this->getEntityManager()->flush();
|
||||
$this->getEntityManager()->clear();
|
||||
|
||||
|
||||
|
||||
|
||||
$allChars = $this->getEntityManager()
|
||||
->getRepository(Character::class)
|
||||
->findAll();
|
||||
$this->assertSame(1, count($allChars));
|
||||
|
||||
|
||||
$allChars = $this->getEntityManager()
|
||||
->getRepository(Character::class)
|
||||
->findAll(CharacterRepository::INCLUDE_SOFTDELETED);
|
||||
$this->assertSame(3, count($allChars));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns data to create valid characters
|
||||
* @return array $futureId => $characterData
|
||||
@@ -61,7 +61,7 @@ class CharacterModelTest extends CoreModelTestCase
|
||||
]],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns data to create invalid characters
|
||||
* @return array A list of faulty characters
|
||||
@@ -79,7 +79,7 @@ class CharacterModelTest extends CoreModelTestCase
|
||||
]],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests character creation
|
||||
* @param array $characterData
|
||||
@@ -88,17 +88,17 @@ class CharacterModelTest extends CoreModelTestCase
|
||||
public function testCreation(array $characterData)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
|
||||
$characterEntity = Character::create($characterData);
|
||||
$characterEntity->save($em);
|
||||
|
||||
|
||||
$em->flush();
|
||||
|
||||
|
||||
$this->assertInternalType("int", $characterEntity->getId());
|
||||
|
||||
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests character creation with faulty data
|
||||
* @param type $characterData
|
||||
@@ -109,7 +109,7 @@ class CharacterModelTest extends CoreModelTestCase
|
||||
{
|
||||
Character::create($characterData);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests if invalid array key given during Character::create throws an exception
|
||||
* @expectedException \LotGD\Core\Exceptions\UnexpectedArrayKeyException
|
||||
@@ -122,71 +122,71 @@ class CharacterModelTest extends CoreModelTestCase
|
||||
"unknownAttribute" => "helloWorld",
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests if Deletor does it's work
|
||||
*/
|
||||
public function testDeletion()
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
|
||||
// Count rows before
|
||||
$rowsBefore = count($em->getRepository(Character::class)->findAll());
|
||||
|
||||
|
||||
// Delete one row
|
||||
$character = $em->getRepository(Character::class)->find(1);
|
||||
$character->delete($em);
|
||||
|
||||
|
||||
$em->clear();
|
||||
|
||||
|
||||
$rowsAfter = count($em->getRepository(Character::class)->findAll());
|
||||
|
||||
|
||||
$this->assertEquals($rowsBefore - 1, $rowsAfter);
|
||||
|
||||
|
||||
// test flushing
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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"));
|
||||
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user