public function testDeleteParsing()
 {
     $di = $this->_getDI();
     $expected = array('tables' => array('robots'), 'models' => array('Robots'));
     $query = new Query('DELETE FROM Robots');
     $query->setDI($di);
     $this->assertEquals($query->parse(), $expected);
     $expected = array('tables' => array(array('robots', NULL, 'r')), 'models' => array('Robots'), 'where' => array('type' => 'binary-op', 'op' => '>', 'left' => array('type' => 'qualified', 'domain' => 'r', 'name' => 'id', 'balias' => 'id'), 'right' => array('type' => 'literal', 'value' => '100')));
     $query = new Query('DELETE FROM Robots AS r WHERE r.id > 100');
     $query->setDI($di);
     $this->assertEquals($query->parse(), $expected);
     $expected = array('tables' => array(array('robots', NULL, 'r')), 'models' => array('Robots'), 'where' => array('type' => 'binary-op', 'op' => '>', 'left' => array('type' => 'qualified', 'domain' => 'r', 'name' => 'id', 'balias' => 'id'), 'right' => array('type' => 'literal', 'value' => '100')));
     $query = new Query('DELETE FROM Robots r WHERE r.id > 100');
     $query->setDI($di);
     $this->assertEquals($query->parse(), $expected);
     $expected = array('tables' => array(array('robots', NULL, 'r')), 'models' => array('Robots'), 'where' => array('type' => 'binary-op', 'op' => '>', 'left' => array('type' => 'qualified', 'domain' => 'r', 'name' => 'id', 'balias' => 'id'), 'right' => array('type' => 'literal', 'value' => '100')));
     $query = new Query('delete from Robots as r where r.id > 100');
     $query->setDI($di);
     $this->assertEquals($query->parse(), $expected);
     $expected = array('tables' => array(array('robots', NULL, 'r')), 'models' => array('Robots'), 'limit' => array('number' => '10'));
     $query = new Query('DELETE FROM Robots r LIMIT 10');
     $query->setDI($di);
     $this->assertEquals($query->parse(), $expected);
     $expected = array('tables' => array(array('robots', NULL, 'r')), 'models' => array('Robots'), 'where' => array('type' => 'binary-op', 'op' => '>', 'left' => array('type' => 'qualified', 'domain' => 'r', 'name' => 'id', 'balias' => 'id'), 'right' => array('type' => 'literal', 'value' => '100')), 'limit' => array('number' => '10'));
     $query = new Query('DELETE FROM Robots r WHERE r.id > 100 LIMIT 10');
     $query->setDI($di);
     $this->assertEquals($query->parse(), $expected);
 }
 public function testDeleteParsing()
 {
     require 'unit-tests/config.db.php';
     if (empty($configMysql)) {
         $this->markTestSkipped('Test skipped');
         return;
     }
     $di = $this->_getDI();
     $expected = array('tables' => array('robots'), 'models' => array('Robots'));
     $query = new Query('DELETE FROM Robots');
     $query->setDI($di);
     $this->assertEquals($query->parse(), $expected);
     $expected = array('tables' => array(array('robots', NULL, 'r')), 'models' => array('Robots'), 'where' => array('type' => 'binary-op', 'op' => '>', 'left' => array('type' => 'qualified', 'domain' => 'r', 'name' => 'id', 'balias' => 'id'), 'right' => array('type' => 'literal', 'value' => '100')));
     $query = new Query('DELETE FROM Robots AS r WHERE r.id > 100');
     $query->setDI($di);
     $this->assertEquals($query->parse(), $expected);
     $expected = array('tables' => array(array('robots', NULL, 'r')), 'models' => array('Robots'), 'where' => array('type' => 'binary-op', 'op' => '>', 'left' => array('type' => 'qualified', 'domain' => 'r', 'name' => 'id', 'balias' => 'id'), 'right' => array('type' => 'literal', 'value' => '100')));
     $query = new Query('DELETE FROM Robots r WHERE r.id > 100');
     $query->setDI($di);
     $this->assertEquals($query->parse(), $expected);
     $expected = array('tables' => array(array('robots', NULL, 'r')), 'models' => array('Robots'), 'where' => array('type' => 'binary-op', 'op' => '>', 'left' => array('type' => 'qualified', 'domain' => 'r', 'name' => 'id', 'balias' => 'id'), 'right' => array('type' => 'literal', 'value' => '100')));
     $query = new Query('delete from Robots as r where r.id > 100');
     $query->setDI($di);
     $this->assertEquals($query->parse(), $expected);
     $expected = array('tables' => array(array('robots', NULL, 'r')), 'models' => array('Robots'), 'limit' => array('number' => array('type' => 'literal', 'value' => '10')));
     $query = new Query('DELETE FROM Robots r LIMIT 10');
     $query->setDI($di);
     $this->assertEquals($query->parse(), $expected);
     $expected = array('tables' => array(array('robots', NULL, 'r')), 'models' => array('Robots'), 'where' => array('type' => 'binary-op', 'op' => '>', 'left' => array('type' => 'qualified', 'domain' => 'r', 'name' => 'id', 'balias' => 'id'), 'right' => array('type' => 'literal', 'value' => '100')), 'limit' => array('number' => array('type' => 'literal', 'value' => '10')));
     $query = new Query('DELETE FROM Robots r WHERE r.id > 100 LIMIT 10');
     $query->setDI($di);
     $this->assertEquals($query->parse(), $expected);
     // Issue 1011
     $expected = array('tables' => array(array('robots', NULL, 'r')), 'models' => array('Robots'), 'where' => array('type' => 'binary-op', 'op' => '>', 'left' => array('type' => 'qualified', 'domain' => 'r', 'name' => 'id', 'balias' => 'id'), 'right' => array('type' => 'literal', 'value' => '100')), 'limit' => array('number' => array('type' => 'placeholder', 'value' => ':limit')));
     $query = new Query('DELETE FROM Robots r WHERE r.id > 100 LIMIT :limit:');
     $query->setDI($di);
     $this->assertEquals($query->parse(), $expected);
     $query = new Query('DELETE FROM Robots r WHERE r.id > 100 LIMIT :limit:');
     $query->setDI($di);
     $this->assertEquals($query->parse(), $expected);
 }
Example #3
0
 public function testDeleteParsing()
 {
     $this->specify("DELETE PHQL queries don't work as expected", function () {
         $expected = array('tables' => array('robots'), 'models' => array(Robots::class));
         $query = new Query('DELETE FROM ' . Robots::class);
         $query->setDI($this->di);
         expect($query->parse())->equals($expected);
         $expected = array('tables' => array(array('robots', null, 'r')), 'models' => array(Robots::class), 'where' => array('type' => 'binary-op', 'op' => '>', 'left' => array('type' => 'qualified', 'domain' => 'r', 'name' => 'id', 'balias' => 'id'), 'right' => array('type' => 'literal', 'value' => '100')));
         $query = new Query('DELETE FROM ' . Robots::class . ' AS r WHERE r.id > 100');
         $query->setDI($this->di);
         expect($query->parse())->equals($expected);
         $expected = array('tables' => array(array('robots', null, 'r')), 'models' => array(Robots::class), 'where' => array('type' => 'binary-op', 'op' => '>', 'left' => array('type' => 'qualified', 'domain' => 'r', 'name' => 'id', 'balias' => 'id'), 'right' => array('type' => 'literal', 'value' => '100')));
         $query = new Query('DELETE FROM ' . Robots::class . ' r WHERE r.id > 100');
         $query->setDI($this->di);
         expect($query->parse())->equals($expected);
         $expected = array('tables' => array(array('robots', null, 'r')), 'models' => array(Robots::class), 'where' => array('type' => 'binary-op', 'op' => '>', 'left' => array('type' => 'qualified', 'domain' => 'r', 'name' => 'id', 'balias' => 'id'), 'right' => array('type' => 'literal', 'value' => '100')));
         $query = new Query('DELETE FROM ' . Robots::class . ' as r WHERE r.id > 100');
         $query->setDI($this->di);
         expect($query->parse())->equals($expected);
         $expected = array('tables' => array(array('robots', null, 'r')), 'models' => array(Robots::class), 'limit' => array('number' => array('type' => 'literal', 'value' => '10')));
         $query = new Query('DELETE FROM ' . Robots::class . ' r LIMIT 10');
         $query->setDI($this->di);
         expect($query->parse())->equals($expected);
         $expected = array('tables' => array(array('robots', null, 'r')), 'models' => array(Robots::class), 'where' => array('type' => 'binary-op', 'op' => '>', 'left' => array('type' => 'qualified', 'domain' => 'r', 'name' => 'id', 'balias' => 'id'), 'right' => array('type' => 'literal', 'value' => '100')), 'limit' => array('number' => array('type' => 'literal', 'value' => '10')));
         $query = new Query('DELETE FROM ' . Robots::class . ' r WHERE r.id > 100 LIMIT 10');
         $query->setDI($this->di);
         expect($query->parse())->equals($expected);
         // Issue 1011
         $expected = array('tables' => array(array('robots', null, 'r')), 'models' => array(Robots::class), 'where' => array('type' => 'binary-op', 'op' => '>', 'left' => array('type' => 'qualified', 'domain' => 'r', 'name' => 'id', 'balias' => 'id'), 'right' => array('type' => 'literal', 'value' => '100')), 'limit' => array('number' => array('type' => 'placeholder', 'value' => ':limit')));
         $query = new Query('DELETE FROM ' . Robots::class . ' r WHERE r.id > 100 LIMIT :limit:');
         $query->setDI($this->di);
         expect($query->parse())->equals($expected);
     });
 }