-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathInvalidTest.php
43 lines (30 loc) · 1.11 KB
/
InvalidTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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);
}
}
}