diff options
Diffstat (limited to 'tests/Components')
-rw-r--r-- | tests/Components/Array2dTest.php | 4 | ||||
-rw-r--r-- | tests/Components/ExpressionTest.php | 2 | ||||
-rw-r--r-- | tests/Components/FieldDefinitionTest.php | 34 | ||||
-rw-r--r-- | tests/Components/KeyTest.php | 21 |
4 files changed, 55 insertions, 6 deletions
diff --git a/tests/Components/Array2dTest.php b/tests/Components/Array2dTest.php index 5ec9d7e..0ceb345 100644 --- a/tests/Components/Array2dTest.php +++ b/tests/Components/Array2dTest.php @@ -46,7 +46,7 @@ class Array2dTest extends TestCase $parser = new Parser(); Array2d::parse($parser, $this->getTokensList('(1, 2),')); $this->assertEquals( - "Expected open bracket followed by a set of values.", + "An opening bracket followed by a set of values was expected.", $parser->errors[0]->getMessage() ); } @@ -56,7 +56,7 @@ class Array2dTest extends TestCase $parser = new Parser(); Array2d::parse($parser, $this->getTokensList('(1, 2),(3)')); $this->assertEquals( - "Expected 2 values, found 1.", + "2 values were expected, but found 1.", $parser->errors[0]->getMessage() ); } diff --git a/tests/Components/ExpressionTest.php b/tests/Components/ExpressionTest.php index c5e10a4..f1c491c 100644 --- a/tests/Components/ExpressionTest.php +++ b/tests/Components/ExpressionTest.php @@ -26,7 +26,7 @@ class ExpressionTest extends TestCase $parser = new Parser(); Expression::parse($parser, $this->getTokensList('(1))')); $errors = $this->getErrorsAsArray($parser); - $this->assertEquals($errors[0][0], 'Unexpected bracket.'); + $this->assertEquals($errors[0][0], 'Unexpected closing bracket.'); } public function testParseErr2() diff --git a/tests/Components/FieldDefinitionTest.php b/tests/Components/FieldDefinitionTest.php index 967d37c..3ecc363 100644 --- a/tests/Components/FieldDefinitionTest.php +++ b/tests/Components/FieldDefinitionTest.php @@ -14,7 +14,7 @@ class FieldDefinitionTest extends TestCase { $component = FieldDefinition::parse( new Parser(), - $this->getTokensList('(str TEXT, FULLTEXT INDEX indx (str)') + $this->getTokensList('(str TEXT, FULLTEXT INDEX indx (str))') ); $this->assertEquals('str', $component[0]->name); $this->assertEquals('FULLTEXT INDEX', $component[1]->key->type); @@ -22,14 +22,42 @@ class FieldDefinitionTest extends TestCase $this->assertEquals('FULLTEXT INDEX `indx` (`str`)', $component[1]); } + public function testParseErr1() + { + $parser = new Parser(); + $component = FieldDefinition::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 = FieldDefinition::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")' + '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', diff --git a/tests/Components/KeyTest.php b/tests/Components/KeyTest.php new file mode 100644 index 0000000..e8a462e --- /dev/null +++ b/tests/Components/KeyTest.php @@ -0,0 +1,21 @@ +<?php + +namespace SqlParser\Tests\Components; + +use SqlParser\Parser; +use SqlParser\Components\Key; + +use SqlParser\Tests\TestCase; + +class KeyTest extends TestCase +{ + + public function testParse() + { + $component = Key::parse( + new Parser(), + $this->getTokensList('') + ); + $this->assertEquals(null, $component->name); + } +} |