Example #1
0
 public function testSelectRawExpressions()
 {
     $this->loadFixtures('Stats');
     $stat = new Stat();
     // In place of expr()
     $query = $stat->select();
     $query->fields(['name AS role', Query::raw('`name` AS `class`')]);
     $this->assertEquals(new EntityCollection([new Entity(['role' => 'Warrior', 'class' => 'Warrior']), new Entity(['role' => 'Ranger', 'class' => 'Ranger']), new Entity(['role' => 'Mage', 'class' => 'Mage'])]), $query->all());
     // In place of func()
     $query = $stat->select();
     $query->fields([Query::raw('SUBSTR(`name`, 1, 3) as `shortName`')]);
     $this->assertEquals(new EntityCollection([new Entity(['shortName' => 'War']), new Entity(['shortName' => 'Ran']), new Entity(['shortName' => 'Mag'])]), $query->all());
 }
Example #2
0
 public function testFormatSelectFieldsRawExprs()
 {
     $this->assertRegExp('/(`|\\")?name(`|\\")? AS (`|\\")?alias(`|\\")?/', $this->object->formatSelectFields([Query::raw('`name` AS `alias`')])[0]);
     $this->assertRegExp('/(`|\\")?name(`|\\")? AS (`|\\")?alias(`|\\")?/', $this->object->formatSelectFields([Query::raw('`name` AS `alias`')], 'foo')[0]);
 }