Made database retrieval conscious about data types

This commit is contained in:
Marcin Kurczewski 2014-05-05 17:44:09 +02:00
parent a74b133cfc
commit 76d544572c
2 changed files with 27 additions and 2 deletions

View file

@ -48,11 +48,29 @@ class Assert
}
public function areEqual($expected, $actual)
{
if ($expected !== $actual)
$this->fail('Assertion failed. Expected: "' . $this->dumpVar($expected) . '", got: "' . $this->dumpVar($actual) . '"');
}
public function areEquivalent($expected, $actual)
{
if ($expected != $actual)
$this->fail('Assertion failed. Expected: "' . $this->dumpVar($expected) . '", got: "' . $this->dumpVar($actual) . '"');
}
public function areNotEqual($expected, $actual)
{
if ($expected === $actual)
$this->fail('Assertion failed. Specified objects are equal');
}
public function areNotEquivalent($expected, $actual)
{
if ($expected == $actual)
$this->fail('Assertion failed. Specified objects are equivalent');
}
public function dumpVar($var)
{
ob_start();

View file

@ -59,7 +59,7 @@ abstract class AbstractCrudModel implements IModel
$stmt = new Sql\SelectStatement();
$stmt->setColumn(new Sql\AliasFunctor(new Sql\CountFunctor('1'), 'count'));
$stmt->setTable(static::getTableName());
return Database::fetchOne($stmt)['count'];
return (int) Database::fetchOne($stmt)['count'];
}
@ -75,6 +75,13 @@ abstract class AbstractCrudModel implements IModel
public static function convertRow($row)
{
$entity = static::spawn();
//todo: force this to be implemented by children
//instead of providing clumsy generic solution
if (isset($row['id']))
$row['id'] = (int) $row['id'];
foreach ($row as $key => $val)
{
if (isset(self::$keyCache[$key]))
@ -132,7 +139,7 @@ abstract class AbstractCrudModel implements IModel
$stmt->setColumn($key, new Sql\Binding($val));
}
Database::exec($stmt);
$entity->id = Database::lastInsertId();
$entity->id = (int) Database::lastInsertId();
}
}