|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * issue242.php |
| 4 | + * |
| 5 | + * Test case for PHPSQLCreator. |
| 6 | + */ |
| 7 | +namespace PHPSQLParser\Test\Creator; |
| 8 | + |
| 9 | +use PHPSQLParser\PHPSQLParser; |
| 10 | +use PHPSQLParser\PHPSQLCreator; |
| 11 | + |
| 12 | +class Issue242Test extends \PHPUnit_Framework_TestCase { |
| 13 | + |
| 14 | + public function testOnDuplicateKey() { |
| 15 | + $sql = "INSERT INTO `wp_options` (`option_name`, `option_value`, `autoload`) VALUES ('some_key', 'some_value', 'yes') ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)"; |
| 16 | + |
| 17 | + $parser = new PHPSQLParser(); |
| 18 | + $parser->parse($sql); |
| 19 | + |
| 20 | + $creator = new PHPSQLCreator(); |
| 21 | + $created = $creator->create($parser->parsed); |
| 22 | + $this->assertEquals($sql, $created); |
| 23 | + } |
| 24 | + |
| 25 | + public function testOnDuplicateKeyAbsValues() { |
| 26 | + $sql = "INSERT INTO wp_dh_wfConfig (name, val, autoload) values ('totalAlertsSent', '16', 'yes') ON DUPLICATE KEY UPDATE val = '16', autoload = 'yes';"; |
| 27 | + |
| 28 | + $parser = new PHPSQLParser(); |
| 29 | + $parser->parse($sql); |
| 30 | + |
| 31 | + $creator = new PHPSQLCreator(); |
| 32 | + $created = $creator->create($parser->parsed); |
| 33 | + $this->assertEquals($sql, $created); |
| 34 | + } |
| 35 | + |
| 36 | + public function testNormalInsert() { |
| 37 | + $sql = "INSERT INTO `wp_options` (`option_name`, `option_value`, `autoload`) VALUES ('some_key', 'some_value', 'yes')"; |
| 38 | + |
| 39 | + $parser = new PHPSQLParser(); |
| 40 | + $parser->parse($sql); |
| 41 | + |
| 42 | + $creator = new PHPSQLCreator(); |
| 43 | + $created = $creator->create($parser->parsed); |
| 44 | + $this->assertEquals($sql, $created); |
| 45 | + } |
| 46 | + |
| 47 | + public function testNormalInsertMultipleValues() { |
| 48 | + $sql = "INSERT INTO `wp_options` (`option_name`, `option_value`, `autoload`) VALUES ('some_key', 'some_value', 'yes'), ('some_key', 'some_value', 'yes')"; |
| 49 | + |
| 50 | + $parser = new PHPSQLParser(); |
| 51 | + $parser->parse($sql); |
| 52 | + |
| 53 | + $creator = new PHPSQLCreator(); |
| 54 | + $created = $creator->create($parser->parsed); |
| 55 | + $this->assertEquals($sql, $created); |
| 56 | + } |
| 57 | +} |
0 commit comments