Phalcon\Test\Unit\Mvc\Model\QueryTest::testInsertParsing PHP Method

testInsertParsing() public method

public testInsertParsing ( )
    public function testInsertParsing()
    {
        $this->specify("INSERT PHQL queries don't work as expected", function () {
            $expected = array('model' => Robots::class, 'table' => 'robots', 'values' => array(array('type' => 322, 'value' => array('type' => 'literal', 'value' => 'NULL')), array('type' => 260, 'value' => array('type' => 'literal', 'value' => 'some robot')), array('type' => 258, 'value' => array('type' => 'literal', 'value' => '1945'))));
            $query = new Query('INSERT INTO ' . Robots::class . ' VALUES (NULL, \'some robot\', 1945)');
            $query->setDI($this->di);
            expect($query->parse())->equals($expected);
            $expected = array('model' => strtolower(Robots::class), 'table' => 'robots', 'values' => array(array('type' => 322, 'value' => array('type' => 'literal', 'value' => 'NULL')), array('type' => 260, 'value' => array('type' => 'literal', 'value' => 'some robot')), array('type' => 258, 'value' => array('type' => 'literal', 'value' => '1945'))));
            $query = new Query('insert into ' . strtolower(Robots::class) . ' values (null, \'some robot\', 1945)');
            $query->setDI($this->di);
            expect($query->parse())->equals($expected);
            $expected = array('model' => SomeProducts::class, 'table' => 'le_products', 'values' => array(array('type' => 260, 'value' => array('type' => 'literal', 'value' => 'Some name')), array('type' => 259, 'value' => array('type' => 'literal', 'value' => '100.15')), array('type' => 350, 'value' => array('type' => 'functionCall', 'name' => 'current_date')), array('type' => 350, 'value' => array('type' => 'functionCall', 'name' => 'now'))));
            $query = new Query('INSERT INTO ' . SomeProducts::class . ' VALUES ("Some name", 100.15, current_date(), now())');
            $query->setDI($this->di);
            expect($query->parse())->equals($expected);
            $expected = array('model' => Robots::class, 'table' => 'robots', 'values' => array(array('type' => 356, 'value' => array('type' => 'parentheses', 'left' => array('type' => 'binary-op', 'op' => '*', 'left' => array('type' => 'binary-op', 'op' => '+', 'left' => array('type' => 'literal', 'value' => '1'), 'right' => array('type' => 'literal', 'value' => '1000')), 'right' => array('type' => 'placeholder', 'value' => ':le_id')))), array('type' => 350, 'value' => array('type' => 'functionCall', 'name' => 'CONCAT', 'arguments' => array(array('type' => 'literal', 'value' => '\'some\''), array('type' => 'literal', 'value' => '\'robot\'')))), array('type' => 258, 'value' => array('type' => 'literal', 'value' => '2011'))));
            $query = new Query('INSERT INTO ' . Robots::class . ' VALUES ((1+1000*:le_id:), CONCAT(\'some\', \'robot\'), 2011)');
            $query->setDI($this->di);
            expect($query->parse())->equals($expected);
            $expected = array('model' => Robots::class, 'table' => 'robots', 'fields' => array('name', 'type', 'year'), 'values' => array(array('type' => 260, 'value' => array('type' => 'literal', 'value' => 'a name')), array('type' => 260, 'value' => array('type' => 'literal', 'value' => 'virtual')), array('type' => 273, 'value' => array('type' => 'placeholder', 'value' => ':0'))));
            $query = new Query('INSERT INTO ' . Robots::class . ' (name, type, year) VALUES (\'a name\', \'virtual\', ?0)');
            $query->setDI($this->di);
            expect($query->parse())->equals($expected);
            $expected = array('model' => Robotters::class, 'table' => 'robots', 'values' => array(array('type' => 322, 'value' => array('type' => 'literal', 'value' => 'NULL')), array('type' => 260, 'value' => array('type' => 'literal', 'value' => 'some robot')), array('type' => 258, 'value' => array('type' => 'literal', 'value' => '1945'))));
            $query = new Query('INSERT INTO ' . Robotters::class . ' VALUES (NULL, \'some robot\', 1945)');
            $query->setDI($this->di);
            expect($query->parse())->equals($expected);
            $expected = array('model' => strtolower(Robotters::class), 'table' => 'robots', 'values' => array(array('type' => 322, 'value' => array('type' => 'literal', 'value' => 'NULL')), array('type' => 260, 'value' => array('type' => 'literal', 'value' => 'some robot')), array('type' => 258, 'value' => array('type' => 'literal', 'value' => '1945'))));
            $query = new Query('insert into ' . strtolower(Robotters::class) . ' values (null, \'some robot\', 1945)');
            $query->setDI($this->di);
            expect($query->parse())->equals($expected);
            $expected = array('model' => Robotters::class, 'table' => 'robots', 'values' => array(array('type' => 356, 'value' => array('type' => 'parentheses', 'left' => array('type' => 'binary-op', 'op' => '*', 'left' => array('type' => 'binary-op', 'op' => '+', 'left' => array('type' => 'literal', 'value' => '1'), 'right' => array('type' => 'literal', 'value' => '1000')), 'right' => array('type' => 'placeholder', 'value' => ':le_id')))), array('type' => 350, 'value' => array('type' => 'functionCall', 'name' => 'CONCAT', 'arguments' => array(array('type' => 'literal', 'value' => '\'some\''), array('type' => 'literal', 'value' => '\'robot\'')))), array('type' => 258, 'value' => array('type' => 'literal', 'value' => '2011'))));
            $query = new Query('INSERT INTO ' . Robotters::class . ' VALUES ((1+1000*:le_id:), CONCAT(\'some\', \'robot\'), 2011)');
            $query->setDI($this->di);
            expect($query->parse())->equals($expected);
            $expected = array('model' => Robotters::class, 'table' => 'robots', 'fields' => array('theName', 'theType', 'theYear'), 'values' => array(array('type' => 260, 'value' => array('type' => 'literal', 'value' => 'a name')), array('type' => 260, 'value' => array('type' => 'literal', 'value' => 'virtual')), array('type' => 273, 'value' => array('type' => 'placeholder', 'value' => ':0'))));
            $query = new Query('INSERT INTO ' . Robotters::class . ' (theName, theType, theYear) VALUES (\'a name\', \'virtual\', ?0)');
            $query->setDI($this->di);
            expect($query->parse())->equals($expected);
        });
    }