public function all() { $model = ReflectionUtils::createNewInstance(static::$forModel); $query = Query::getInstance()->select()->from($model->table())->order(Order::desc("id")); $resultSet = $this->getDatabase()->query($query)->listResult(); return new ResultSet($resultSet); }
public function testShouldProduceSelectStatementWithLimit() { $table = "test"; $sql = Query::getInstance()->select()->from($table)->limit(Limit::limit(1, 100))->build(); $expectedSql = "SELECT * FROM {$table} LIMIT 1 OFFSET 100"; $this->assertThat($sql, $this->equalTo($expectedSql)); }
public function testShouldFetchAllPersistedObjects() { self::$phactory->getConnection()->exec("DELETE FROM tests"); $users = array(); for ($i = 1; $i <= 10; $i++) { $users[] = self::$phactory->create('test'); } $query = Query::getInstance(); $query->select(Projections::count("id"))->from("tests"); $database = new Database(self::$phactory->getConnection()); $result = $database->query($query)->uniqueResult(); $this->assertThat(array_pop($result), $this->equalTo(10)); }