Exemplo n.º 1
0
 public function testException3()
 {
     try {
         $e = new Expression('hello, [world]');
         $e->render();
     } catch (\atk4\dsql\Exception $e) {
         $this->assertEquals('Expression could not render tag', $e->getMessage());
         $this->assertEquals('world', $e->getParams()['tag']);
     }
 }
Exemplo n.º 2
0
 /**
  * @covers ::field
  * @covers ::_render_field
  * @covers ::table
  * @covers ::_render_table
  * @covers ::render
  */
 public function testUnionQuery()
 {
     // 1st query
     $q1 = $this->q()->table('sales')->field('date')->field('amount', 'debit')->field($this->q()->expr('0'), 'credit');
     $this->assertEquals('select `date`,`amount` `debit`,0 `credit` from `sales`', $q1->render());
     // 2nd query
     $q2 = $this->q()->table('purchases')->field('date')->field($this->q()->expr('0'), 'debit')->field('amount', 'credit');
     $this->assertEquals('select `date`,0 `debit`,`amount` `credit` from `purchases`', $q2->render());
     // $q1 union $q2
     $u = new Expression('[] union []', [$q1, $q2]);
     $this->assertEquals('(select `date`,`amount` `debit`,0 `credit` from `sales`) union (select `date`,0 `debit`,`amount` `credit` from `purchases`)', $u->render());
     // SELECT date,debit,credit FROM ($q1 union $q2)
     $q = $this->q()->field('date,debit,credit')->table($u, 'derrivedTable');
     /*
      * @see https://github.com/atk4/dsql/issues/33
      * @see https://github.com/atk4/dsql/issues/34
      */
     /*
     $this->assertEquals(
         'select `date`,`debit`,`credit` from ((select `date`,`amount` `debit`,0 `credit` from `sales`) union (select `date`,0 `debit`,`amount` `credit` from `purchases`)) `derrivedTable`',
         $q->render()
     );
     */
 }
Exemplo n.º 3
0
 /**
  * Fully covers _param method.
  *
  * @covers ::_param
  */
 public function testParam()
 {
     $e = new Expression('hello, [who]', ['who' => 'world']);
     $this->assertEquals('hello, :a', $e->render());
     $this->assertEquals([':a' => 'world'], $e->params);
     // @todo Imants: allowing to pass value as array looks wrong.
     //      See test case in testParam() method.
     //      Maybe we should add implode(' ', array_map(...)) here ?
     $e = new Expression('hello, [who]', ['who' => ['cruel', 'world']]);
     $this->assertEquals('hello, (:a,:b)', $e->render());
     $this->assertEquals([':a' => 'cruel', ':b' => 'world'], $e->params);
 }