Skip to content
Permalink
Browse files

Removed fetchObject() and fetchAllObjects(). Left fetchColumn(), fetc…

…hAssoc().
  • Loading branch information...
T0mats0 committed Apr 2, 2018
1 parent f524dcb commit 77a6dc11f43a20a3dfa9d74d1ddb672af62d4f38
@@ -114,14 +114,6 @@ public function fetchAssoc()
return $this->fetch(static::FETCH_TYPE_ASSOC);
}
/**
* {@inheritdoc}
*/
public function fetchObject()
{
return $this->fetch(static::FETCH_TYPE_OBJ);
}
/**
* {@inheritDoc}
*
@@ -47,12 +47,6 @@ class StatementDecorator implements StatementInterface, Countable, IteratorAggre
* @var string
*/
const FETCH_TYPE_ASSOC = 'assoc';
/**
* Used to designate that objects of \stdClass be returned in a result when calling fetch methods
*
* @var string
*/
const FETCH_TYPE_OBJ = 'obj';
/**
* Statement instance implementation, such as PDOStatement
@@ -215,16 +209,6 @@ public function fetch($type = self::FETCH_TYPE_NUM)
return $this->_statement->fetch($type);
}
/**
* Returns the next row as a stdClass object
*
* @return array|false Result array containing columns and values in an anonymous object or false if no results
*/
public function fetchObject()
{
return $this->fetch(static::FETCH_TYPE_OBJ);
}
/**
* @return array|false Result array containing columns and values an an associative array or false if no results
*/
@@ -268,16 +252,6 @@ public function fetchAll($type = self::FETCH_TYPE_NUM)
return $this->_statement->fetchAll($type);
}
/**
* Returns an array of \stdClass objects or false
*
* @return \stdClass[]|false
*/
public function fetchAllObjects()
{
return $this->fetchAll(static::FETCH_TYPE_OBJ);
}
/**
* Returns the number of rows affected by this SQL statement.
*
@@ -4530,34 +4530,6 @@ public function testDeleteModifiers()
);
}
/**
* Tests that fetch returns an anonymous object when the string 'obj'
* is passed as an argument
*
* @return void
*/
public function testSelectWithObjFetchType()
{
$this->loadFixtures('Comments');
$query = new Query($this->connection);
$result = $query
->select(['id'])
->from('comments')
->where(['id' => '1'])
->execute();
$obj = (object)['id' => 1];
$this->assertEquals($obj, $result->fetch('obj'));
$query = new Query($this->connection);
$result = $query
->select(['id'])
->from('comments')
->where(['id' => '1'])
->execute();
$rows = $result->fetchAll('obj');
$this->assertEquals($obj, $rows[0]);
}
/**
* Test getValueBinder()
*
@@ -4701,6 +4673,7 @@ public function assertQuotedQuery($pattern, $query, $optional = false)
/**
* Test that calling fetchAssoc return an associated array.
* @return void
* @throws \Exception
*/
public function testFetchAssoc()
{
@@ -4720,34 +4693,8 @@ public function testFetchAssoc()
}
/**
* Test that calling fetchObject returns a \stdClass object
* @return void
*/
public function testFetchObject()
{
$this->loadFixtures('Profiles');
$query = new Query($this->connection);
$results = $query
->select([
'id',
'user_id',
'is_active'
])
->from('profiles')
->limit(1)
->execute()
->fetchObject();
$this->assertInstanceOf(\stdClass::class, $results);
$this->assertObjectHasAttribute('id', $results);
$this->assertObjectHasAttribute('user_id', $results);
$this->assertObjectHasAttribute('is_active', $results);
$this->assertEquals($results->id, '1');
$this->assertEquals($results->user_id, '1');
$this->assertEquals($results->is_active, '0');
}
/**
* Test that calling fetchColumn returns the correct column value.
* Test that fetchColumn() will return the correct value at $position.
* @throws \Exception
* @return void
*/
public function testFetchColumn()
@@ -4772,8 +4719,9 @@ public function testFetchColumn()
* Test that calling fetchAssoc, fetchColum and fetchObject in sequence
* alters the fetched data to the correct types and values.
* @return void
* @throws \Exception
*/
public function testFetchAllAssocColumnAndObj()
public function testFetchAllAssocColumn()
{
$this->loadFixtures('Profiles');
$query = new Query($this->connection);
@@ -4791,28 +4739,6 @@ public function testFetchAllAssocColumnAndObj()
$this->assertEquals('2', $results['id']);
$results = $statement->fetchColumn(0);
$this->assertEquals('3', $results[0]);
$results = $statement->fetchObject();
$this->assertEquals('4', $results->id);
}
/**
* Test that an array of objects is returned
* @return void
*/
public function testFetchAllObjects()
{
$this->loadFixtures('Profiles');
$query = new Query($this->connection);
$query
->select([
'id',
'user_id',
'is_active'
])
->from('profiles');
$statement = $query->execute();
$results = $statement->fetchAllObjects();
$this->assertInstanceOf(\stdClass::class, $results[0]);
$this->assertEquals('2', $results[1]->id);
}
}

0 comments on commit 77a6dc1

Please sign in to comment.
You can’t perform that action at this time.