/** * Render SQL for Aliased * * @param SQL\Aliased $aliased * @return string */ public static function render(SQL\Aliased $aliased) { $content = $aliased->getContent(); if ($content instanceof Query\Select) { $content = "(" . Select::render($content) . ")"; } else { $content = Compiler::name($content); } return Compiler::expression(array($content, Compiler::word('AS', Compiler::name($aliased->getAlias())))); }
/** * @covers ::__construct * @covers ::getParameters * @covers ::getAlias */ public function testConstruct() { $aliased = new SQL\Aliased('SQL', 'ALIAS'); $this->assertEquals('SQL', $aliased->getContent()); $this->assertEquals('ALIAS', $aliased->getAlias()); $this->assertNull($aliased->getParameters()); $query = $this->getMock('Harp\\Query\\Select', array('getParameters'), array(self::getDb())); $query->expects($this->once())->method('getParameters')->will($this->returnValue(array('val'))); $aliasedQuery = new SQL\Aliased($query, 'query_alias'); $this->assertSame($query, $aliasedQuery->getContent()); $this->assertEquals('query_alias', $aliasedQuery->getAlias()); $this->assertEquals(array('val'), $aliasedQuery->getParameters()); }