diff --git a/src/Assert.php b/src/Assert.php index a056a544..b74d03b8 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -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(); diff --git a/src/Models/AbstractCrudModel.php b/src/Models/AbstractCrudModel.php index e91a2bdc..9a176e27 100644 --- a/src/Models/AbstractCrudModel.php +++ b/src/Models/AbstractCrudModel.php @@ -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(); } }