Exemplo n.º 1
0
 /**
  * @param array $columns
  * @param string $sql
  * @param string $expectedResult
  * @dataProvider renderDataProvider
  */
 public function testRender($columns, $sql, $expectedResult)
 {
     $mapValues = [['column', null, '`column`'], [['table', 'column'], null, '`table`.`column`'], [['table', 'column'], 'alias', '`table`.`column` AS `alias`']];
     $this->quoteMock->expects($this->any())->method('quoteColumnAs')->willReturnMap($mapValues);
     $this->selectMock->expects($this->exactly(2))->method('getPart')->with(Select::COLUMNS)->willReturn($columns);
     $this->assertEquals($expectedResult, $this->model->render($this->selectMock, $sql));
 }
Exemplo n.º 2
0
 public function testRender()
 {
     $sql = 'SELECT';
     $expectedResult = $sql . ' ' . Select::SQL_GROUP_BY . ' group1' . ",\n\t" . 'group2';
     $mapValues = [[Select::FROM, true], [Select::GROUP, ['group1', 'group2']]];
     $this->selectMock->expects($this->exactly(3))->method('getPart')->willReturnMap($mapValues);
     $this->quoteMock->expects($this->exactly(2))->method('quoteIdentifier')->willReturnArgument(0);
     $this->assertEquals($expectedResult, $this->model->render($this->selectMock, $sql));
 }
Exemplo n.º 3
0
 /**
  * @param array $from
  * @param string $sql
  * @param string $expectedResult
  * @dataProvider renderDataProvider
  */
 public function testRender($from, $sql, $expectedResult)
 {
     $this->quoteMock->expects($this->any())->method('quoteIdentifier')->willReturnArgument(0);
     $this->quoteMock->expects($this->any())->method('quoteTableAs')->willReturnCallback(function ($tableName, $correlationName) {
         return $tableName . ' AS ' . $correlationName;
     });
     $this->selectMock->expects($this->once())->method('getPart')->with(Select::FROM)->willReturn($from);
     $this->assertEquals($expectedResult, $this->model->render($this->selectMock, $sql));
 }
Exemplo n.º 4
0
 /**
  * Render GROUP BY section
  *
  * @param Select $select
  * @param string $sql
  * @return string
  */
 public function render(Select $select, $sql = '')
 {
     if ($select->getPart(Select::FROM) && $select->getPart(Select::GROUP)) {
         $group = [];
         foreach ($select->getPart(Select::GROUP) as $term) {
             $group[] = $this->quote->quoteIdentifier($term);
         }
         $sql .= ' ' . Select::SQL_GROUP_BY . ' ' . implode(",\n\t", $group);
     }
     return $sql;
 }
Exemplo n.º 5
0
 /**
  * Render ORDER BY section
  *
  * @param Select $select
  * @param string $sql
  * @return string
  */
 public function render(Select $select, $sql = '')
 {
     if ($select->getPart(Select::ORDER)) {
         $order = [];
         foreach ($select->getPart(Select::ORDER) as $term) {
             if (is_array($term)) {
                 if (is_numeric($term[0]) && strval(intval($term[0])) == $term[0]) {
                     $order[] = (int) trim($term[0]) . ' ' . $term[1];
                 } else {
                     $order[] = $this->quote->quoteIdentifier($term[0]) . ' ' . $term[1];
                 }
             } elseif (is_numeric($term) && strval(intval($term)) == $term) {
                 $order[] = (int) trim($term);
             } else {
                 $order[] = $this->quote->quoteIdentifier($term);
             }
         }
         $sql .= ' ' . Select::SQL_ORDER_BY . ' ' . implode(', ', $order) . PHP_EOL;
     }
     return $sql;
 }
Exemplo n.º 6
0
 /**
  * Render COLUMNS section
  *
  * @param Select $select
  * @param string $sql
  * @return null|string
  * @throws \Zend_Db_Select_Exception
  */
 public function render(Select $select, $sql = '')
 {
     if (!count($select->getPart(Select::COLUMNS))) {
         return null;
     }
     $columns = [];
     foreach ($select->getPart(Select::COLUMNS) as $columnEntry) {
         list($correlationName, $column, $alias) = $columnEntry;
         if ($column instanceof \Zend_Db_Expr) {
             $columns[] = $this->quote->quoteColumnAs($column, $alias);
         } else {
             if ($column == Select::SQL_WILDCARD) {
                 $column = new \Zend_Db_Expr(Select::SQL_WILDCARD);
                 $alias = null;
             }
             if (empty($correlationName)) {
                 $columns[] = $this->quote->quoteColumnAs($column, $alias);
             } else {
                 $columns[] = $this->quote->quoteColumnAs([$correlationName, $column], $alias);
             }
         }
     }
     return $sql . ' ' . implode(', ', $columns);
 }
Exemplo n.º 7
0
 /**
  * Return a quoted table name
  *
  * @param string   $tableName        The table name
  * @param string   $correlationName  The correlation name OPTIONAL
  * @return string
  */
 protected function getQuotedTable($tableName, $correlationName = null)
 {
     return $this->quote->quoteTableAs($tableName, $correlationName);
 }
Exemplo n.º 8
0
 /**
  * @param string|array $identifier
  * @param string $expectedResult
  * @dataProvider getStringArrayToQuoteWithAliasDataProvider
  */
 public function testQuoteTableAs($identifier, $alias, $expectedResult)
 {
     $this->assertEquals($expectedResult, $this->model->quoteTableAs($identifier, $alias));
 }