Added strict_types=1 and added test

This commit is contained in:
Basilius Sauter
2016-04-15 18:56:08 +02:00
parent 5a405fc2db
commit 7afa27246b
4 changed files with 58 additions and 16 deletions
+6 -1
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace LotGD\Core\Models;
@@ -64,12 +65,16 @@ class Character {
$this->displayName = $this->name;
}
public function getDisplayName(): string {
return $this->displayName;
}
/**
* Sets the maximum health of a character to a given value. It also sets the
* health if none has been set yet.
* @param int $maxhealth
*/
protected function setMaxhealth(int $maxhealth) {
public function setMaxhealth(int $maxhealth) {
$this->maxhealth = $maxhealth;
$this->health = $this->health??$this->maxhealth;
}
+1
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace LotGD\Core\Tools\Model;
+7 -8
View File
@@ -1,19 +1,14 @@
<?php
declare(strict_types=1);
namespace LotGD\Core\Tests;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\ORM\{
EntityManager,
Mapping\AnsiQuoteStrategy,
Tools\Setup,
Tools\SchemaTool
};
use Doctrine\ORM\Mapping\{
AnsiQuoteStrategy,
ClassMetadata,
Driver\DriverChain,
Driver\AnnotationDriver
};
/**
* Description of ModelTestCase
@@ -40,7 +35,11 @@ abstract class ModelTestCase extends \PHPUnit_Framework_TestCase {
$schemaTool->createSchema($metaData);
}
protected function getEntityManager() {
/**
* Returns the entity manager to run tests.
* @return \LotGD\Core\Tests\EntityManager
*/
protected function getEntityManager(): EntityManager {
return $this->_em;
}
}
+44 -7
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace LotGD\Core\Tests\Models;
@@ -15,15 +16,51 @@ use Doctrine\ORM\Mapping as ORM;
class CharacterModelTest extends ModelTestCase {
/** @var array */
protected $entities = [Character::class];
/**
* Tests character creation
*/
public function testCreation() {
$characters = [
1 => [
"name" => "Testcharacter",
"maxhealth" => 250
],
2 => [
"name" => "Spamegg",
"maxhealth" => 42
],
];
foreach($characters as $characterId => $characterData) {
$characterEntity = Character::create($characterData);
$characterEntity->save($this->getEntityManager());
public function testCreationQuery() {
$character = Character::create([
"name" => "Testcharacter",
"maxhealth" => 250,
]);
$this->assertEquals($characterEntity->getId(), $characterId);
}
$character->save($this->getEntityManager());
$entities = $this->getEntityManager()->getRepository(Character::class)
->findAll();
$this->assertEquals(count($entities), count($characters));
}
/**
* @expectedException TypeError
*/
public function testCreationTypes() {
$faultyCharacters = [
1 => [
"name" => 16,
"maxhealth" => 16,
],
2 => [
"name" => "Faulter",
"maxhealth" => 17.8,
]
];
$this->assertEquals($character->getId(), 1);
foreach($faultyCharacters as $faultyCharacterData) {
$char = Character::create($faultyCharacterData);
}
}
}