-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* detect when we've reached the end of input when lexing an unterminated string * added a mode where we throw exceptions for invalid syntax * added tests for invalid syntax, in both default and exception mode * documented `$parser->throw_on_bad_syntax` * get tests running again on php 8.1 (broken by sebastianbergmann/phpunit#4740)
- Loading branch information
Showing
4 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class InvalidTest extends TestCase{ | ||
|
||
# tests for invalid inputs | ||
|
||
function testBrokenSyntaxRegular(){ | ||
|
||
// by default, bad syntax (unterminated strings, comments, etc) will just not produce a token | ||
|
||
$obj = new iamcal\SQLParser(); | ||
|
||
$tokens = $obj->lex("CREATE TABLE `users ( id int(10) )"); | ||
$this->assertEquals(count($tokens), 1); | ||
|
||
$tokens = $obj->lex("CREATE TABLE `users` ' ( `id` int(10) )"); | ||
$this->assertEquals(count($tokens), 2); | ||
} | ||
|
||
function testBrokenSyntaxException(){ | ||
|
||
// in exception mode, it throws an exception... | ||
|
||
$obj = new iamcal\SQLParser(); | ||
$obj->throw_on_bad_syntax = true; | ||
|
||
try { | ||
$obj->lex("CREATE TABLE `users ( id int(10) )"); | ||
$this->fail("Expected Exception has not been raised"); | ||
} catch (Exception $ex) { | ||
$this->assertInstanceOf('iamcal\SQLParserSyntaxException', $ex); | ||
} | ||
|
||
try { | ||
$obj->lex("CREATE TABLE `users` ' ( `id` int(10) )"); | ||
$this->fail("Expected Exception has not been raised"); | ||
} catch (Exception $ex) { | ||
$this->assertInstanceOf('iamcal\SQLParserSyntaxException', $ex); | ||
} | ||
|
||
} | ||
} |