Skip to content
Permalink
Browse files

Tests

  • Loading branch information...
T0mats0 committed Apr 4, 2018
1 parent dd96a7e commit ac6bb7fec092e63282906bc4034da44764825c52
Showing with 17 additions and 29 deletions.
  1. +17 −29 tests/TestCase/Database/QueryTest.php
@@ -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);
}
/**
@@ -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.
You can’t perform that action at this time.