$record =
$result->
fetch();
$this->
assertEquals('George',
$record->
{$name_field}, 'Fetched name is correct.'
);
$this->
assertEquals(27,
$record->
{$age_field}, 'Fetched age is correct.'
);
} /**
* Tests SELECT statements with expressions.
*/
public function testSimpleSelectExpression() { $query =
$this->connection->
select('test'
);
$name_field =
$query->
addField('test', 'name'
);
$age_field =
$query->
addExpression("[age]*2", 'double_age'
);
$query->
condition('age', 27
);
$result =
$query->
execute();
// Check that the aliases are being created the way we want.
$this->
assertEquals('name',
$name_field, 'Name field alias is correct.'
);
$this->
assertEquals('double_age',
$age_field, 'Age field alias is correct.'
);
// Ensure that we got the right record.
$record =
$result->
fetch();
$this->
assertEquals('George',
$record->
{$name_field}, 'Fetched name is correct.'
);
$this->
assertEquals(27 * 2,
$record->
{$age_field}, 'Fetched age expression is correct.'
);
}