summaryrefslogtreecommitdiffstats
path: root/tests/Components/CreateDefinitionTest.php
diff options
context:
space:
mode:
authorDan Ungureanu <udan1107@gmail.com>2015-08-08 20:38:04 +0300
committerDan Ungureanu <udan1107@gmail.com>2015-08-08 20:38:04 +0300
commitab778e942d8f3b3950cbd1eaf7fa10ea21aeea9f (patch)
tree6601dba770d512b51f503aa05ff4d88a045de512 /tests/Components/CreateDefinitionTest.php
parent1abbd1dc1ae48330bef8ebc73bef53572f092c2b (diff)
downloadsql-parser-ab778e942d8f3b3950cbd1eaf7fa10ea21aeea9f.zip
sql-parser-ab778e942d8f3b3950cbd1eaf7fa10ea21aeea9f.tar.gz
sql-parser-ab778e942d8f3b3950cbd1eaf7fa10ea21aeea9f.tar.bz2
Refactored field to something more appropriate depending on the context in which it is used.
Diffstat (limited to 'tests/Components/CreateDefinitionTest.php')
-rw-r--r--tests/Components/CreateDefinitionTest.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/Components/CreateDefinitionTest.php b/tests/Components/CreateDefinitionTest.php
new file mode 100644
index 0000000..81c8ba8
--- /dev/null
+++ b/tests/Components/CreateDefinitionTest.php
@@ -0,0 +1,67 @@
+<?php
+
+namespace SqlParser\Tests\Components;
+
+use SqlParser\Parser;
+use SqlParser\Components\CreateDefinition;
+
+use SqlParser\Tests\TestCase;
+
+class CreateDefinitionTest extends TestCase
+{
+
+ public function testParse()
+ {
+ $component = CreateDefinition::parse(
+ new Parser(),
+ $this->getTokensList('(str TEXT, FULLTEXT INDEX indx (str))')
+ );
+ $this->assertEquals('str', $component[0]->name);
+ $this->assertEquals('FULLTEXT INDEX', $component[1]->key->type);
+ $this->assertEquals('indx', $component[1]->key->name);
+ $this->assertEquals('FULLTEXT INDEX `indx` (`str`)', $component[1]);
+ }
+
+ public function testParseErr1()
+ {
+ $parser = new Parser();
+ $component = CreateDefinition::parse(
+ $parser,
+ $this->getTokensList('(str TEXT, FULLTEXT INDEX indx (str)')
+ );
+
+ $this->assertEquals(
+ 'A closing bracket was expected.',
+ $parser->errors[0]->getMessage()
+ );
+ }
+
+ public function testParseErr2()
+ {
+ $parser = new Parser();
+ $component = CreateDefinition::parse(
+ $parser,
+ $this->getTokensList(')')
+ );
+
+ $this->assertEquals(
+ 'An opening bracket was expected.',
+ $parser->errors[0]->getMessage()
+ );
+ }
+
+ public function testBuild()
+ {
+ $parser = new Parser(
+ 'CREATE TABLE `payment` (' .
+ '-- snippet' . "\n" .
+ '`customer_id` smallint(5) unsigned NOT NULL,' .
+ 'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE' .
+ ') ENGINE=InnoDB"'
+ );
+ $this->assertEquals(
+ 'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE',
+ CreateDefinition::build($parser->statements[0]->fields[1])
+ );
+ }
+}