Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Ritter committed Apr 4, 2018
1 parent dd96a7e commit ac6bb7f
Showing 1 changed file with 17 additions and 29 deletions.
46 changes: 17 additions & 29 deletions tests/TestCase/Database/QueryTest.php
Expand Up @@ -4708,26 +4708,33 @@ public function testFetchColumn()
{
$this->loadFixtures('Profiles');
$query = new Query($this->connection);
$fields = [
'integer',
'integer',
'boolean'
];
$typeMap = new TypeMap($fields);
$query
->select([
'id',
'user_id',
'is_active'
])
->from('profiles')
->setSelectTypeMap($typeMap)
->where(['id' => 2])
->limit(1);
$statement = $query->execute();
$results = $statement->fetchColumn(0);
$this->assertSame('2', $results);
$this->assertSame(2, $results);

$statement = $query->execute();
$results = $statement->fetchColumn(1);
$this->assertSame('2', $results);
$this->assertSame(2, $results);

$statement = $query->execute();
$results = $statement->fetchColumn(2);
$this->assertSame('0', $results);
$this->assertSame(false, $results);
}

/**
Expand All @@ -4739,43 +4746,24 @@ public function testFetchColumnReturnsFalse()
{
$this->loadFixtures('Profiles');
$query = new Query($this->connection);
$fields = [
'integer',
'integer',
'boolean'
];
$typeMap = new TypeMap($fields);
$query
->select([
'id',
'user_id',
'is_active'
])
->from('profiles')
->setSelectTypeMap($typeMap)
->where(['id' => 2])
->limit(1);
$statement = $query->execute();
$results = $statement->fetchColumn(3);
$this->assertFalse($results);
}

/**
* 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 testFetchAllAssocColumn()
{
$this->loadFixtures('Profiles');
$query = new Query($this->connection);
$query
->select([
'id',
'user_id',
'is_active'
])
->from('profiles');
$statement = $query->execute();
$results = $statement->fetchAssoc();
$this->assertSame('1', $results['id']);
$results = $statement->fetchAssoc();
$this->assertSame('2', $results['id']);
$results = $statement->fetchColumn(0);
$this->assertSame('3', $results);
}
}

0 comments on commit ac6bb7f

Please sign in to comment.