Skip to content

Commit

Permalink
Removed fetchObject() and fetchAllObjects(). Left fetchColumn(), fetc…
Browse files Browse the repository at this point in the history
…hAssoc().
  • Loading branch information
Eugene Ritter committed Apr 2, 2018
1 parent f524dcb commit 77a6dc1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 114 deletions.
8 changes: 0 additions & 8 deletions src/Database/Statement/BufferedStatement.php
Expand Up @@ -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}
*
Expand Down
26 changes: 0 additions & 26 deletions src/Database/Statement/StatementDecorator.php
Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.
*
Expand Down
86 changes: 6 additions & 80 deletions tests/TestCase/Database/QueryTest.php
Expand Up @@ -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()
*
Expand Down Expand Up @@ -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()
{
Expand All @@ -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()
Expand All @@ -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);
Expand All @@ -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.