diff options
-rw-r--r-- | src/Fragments/ParamDefFragment.php | 2 | ||||
-rw-r--r-- | src/Lexer.php | 6 | ||||
-rw-r--r-- | src/Utils/Misc.php | 3 | ||||
-rw-r--r-- | src/Utils/Routine.php | 1 | ||||
-rw-r--r-- | tests/bootstrap.php | 4 | ||||
-rw-r--r-- | tests/lexer/IsMethodsTest.php | 6 | ||||
-rw-r--r-- | tests/lexer/LexerTest.php | 104 | ||||
-rw-r--r-- | tests/lexer/TokenTest.php | 6 | ||||
-rw-r--r-- | tests/lexer/TokensList.php | 4 | ||||
-rw-r--r-- | tests/parser/ArrayFragmentTest.php | 24 | ||||
-rw-r--r-- | tests/parser/CallStatementTest.php | 18 | ||||
-rw-r--r-- | tests/parser/CreateStatementTest.php | 36 | ||||
-rw-r--r-- | tests/parser/DeleteStatementTest.php | 18 | ||||
-rw-r--r-- | tests/parser/InsertStatementTest.php | 18 | ||||
-rw-r--r-- | tests/parser/ParserTest.php | 4 | ||||
-rw-r--r-- | tests/parser/RenameStatementTest.php | 18 | ||||
-rw-r--r-- | tests/parser/ReplaceStatementTest.php | 18 | ||||
-rw-r--r-- | tests/parser/SelectStatementTest.php | 26 | ||||
-rw-r--r-- | tests/parser/UpdateStatementTest.php | 18 | ||||
-rw-r--r-- | tests/utils/MiscTest.php | 5 | ||||
-rw-r--r-- | tests/utils/RoutineTest.php | 8 |
21 files changed, 203 insertions, 144 deletions
diff --git a/src/Fragments/ParamDefFragment.php b/src/Fragments/ParamDefFragment.php index 05bad6e..b7d414d 100644 --- a/src/Fragments/ParamDefFragment.php +++ b/src/Fragments/ParamDefFragment.php @@ -91,7 +91,7 @@ class ParamDefFragment extends Fragment if (($token->value === 'IN') || ($token->value === 'OUT') || ($token->value === 'INOUT')) { $expr->inOut = $token->value; ++$list->idx; - } else if ($token->value === ')') { + } elseif ($token->value === ')') { ++$list->idx; break; } else { diff --git a/src/Lexer.php b/src/Lexer.php index 238d63b..2b980ab 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -135,7 +135,7 @@ class Lexer // Another example is `parseComment`. $tokens = new TokensList(); - $lastToken = NULL; + $lastToken = null; for ($this->last = 0, $lastIdx = 0; $this->last < $this->len; $lastIdx = ++$this->last) { /** @var Token The new token. */ @@ -153,8 +153,8 @@ class Lexer if ($this->delimiter !== $this->str[$this->last]) { $this->error('Unexpected character.', $this->str[$this->last], $this->last); } - } else if (($token->type === Token::TYPE_SYMBOL) && ($token->flags & Token::FLAG_SYMBOL_VARIABLE) && - ($lastToken !== NULL)) { + } elseif (($token->type === Token::TYPE_SYMBOL) && ($token->flags & Token::FLAG_SYMBOL_VARIABLE) && + ($lastToken !== null)) { // Handles ```... FROM 'user'@'%' ...```. if ((($lastToken->type === Token::TYPE_SYMBOL) && ($lastToken->flags & Token::FLAG_SYMBOL_BACKTICK)) || ($lastToken->type === Token::TYPE_STRING)) { diff --git a/src/Utils/Misc.php b/src/Utils/Misc.php index aca16fe..dc8b438 100644 --- a/src/Utils/Misc.php +++ b/src/Utils/Misc.php @@ -68,7 +68,7 @@ class Misc } foreach ($tree->expr as $expr) { - if ((empty($expr->column)) || (empty($expr->alias)) ){ + if ((empty($expr->column)) || (empty($expr->alias))) { continue; } @@ -87,5 +87,4 @@ class Misc return $retval; } - } diff --git a/src/Utils/Routine.php b/src/Utils/Routine.php index 1b694e2..0f42c51 100644 --- a/src/Utils/Routine.php +++ b/src/Utils/Routine.php @@ -42,5 +42,4 @@ class Routine return $retval; } - } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index e7aa672..549cc96 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,5 +1,7 @@ <?php +namespace SqlParser\Tests; + require('vendor/autoload.php'); use SqlParser\Lexer; @@ -18,7 +20,7 @@ use SqlParser\Token; * which holds the Parser instance, without errors and the `errors` key which * holds the array that was previously extracted. */ -abstract class TestCase extends PHPUnit_Framework_TestCase +abstract class TestCase extends \PHPUnit_Framework_TestCase { /** diff --git a/tests/lexer/IsMethodsTest.php b/tests/lexer/IsMethodsTest.php index 6121a4d..d1d9546 100644 --- a/tests/lexer/IsMethodsTest.php +++ b/tests/lexer/IsMethodsTest.php @@ -1,9 +1,13 @@ <?php +namespace SqlParser\Tests\Lexer; + use SqlParser\Context; use SqlParser\Token; -class IsMethodsTest extends PHPUnit_Framework_TestCase +use SqlParser\Tests\TestCase; + +class IsMethodsTest extends TestCase { public function testIsKeyword() diff --git a/tests/lexer/LexerTest.php b/tests/lexer/LexerTest.php index c8f941d..9620ee7 100644 --- a/tests/lexer/LexerTest.php +++ b/tests/lexer/LexerTest.php @@ -1,8 +1,12 @@ <?php +namespace SqlParser\Tests\Lexer; + use SqlParser\Exceptions\LexerException; use SqlParser\Lexer; +use SqlParser\Tests\TestCase; + class LexerTest extends TestCase { @@ -32,78 +36,32 @@ class LexerTest extends TestCase $lexer->error('strict error', 'foo', 1, 4); } - public function testLex() - { - $this->runLexerTest('lex'); - } - - public function testLexKeyword() - { - $this->runLexerTest('lexKeyword'); - } - - public function testLexOperator() - { - $this->runLexerTest('lexOperator'); - } - - public function testLexWhitespace() - { - $this->runLexerTest('lexWhitespace'); - } - - public function testLexComment() - { - $this->runLexerTest('lexComment'); - } - - public function testLexBool() - { - $this->runLexerTest('lexBool'); - } - - public function testLexNumber() - { - $this->runLexerTest('lexNumber'); - } - - public function testLexString() - { - $this->runLexerTest('lexString'); - } - - public function testLexStringErr1() - { - $this->runLexerTest('lexStringErr1'); - } - - public function testLexSymbol() - { - $this->runLexerTest('lexSymbol'); - } - - public function testLexSymbolUser() - { - $this->runLexerTest('lexSymbolUser'); - } - - public function testLexSymbolErr1() - { - $this->runLexerTest('lexSymbolErr1'); - } - - public function testLexSymbolErr2() - { - $this->runLexerTest('lexSymbolErr2'); - } - - public function testLexSymbolErr3() - { - $this->runLexerTest('lexSymbolErr3'); - } - - public function testLexDelimiter() - { - $this->runLexerTest('lexDelimiter'); + /** + * @dataProvider testLexProvider + */ + public function testLex($test) + { + $this->runLexerTest($test); + } + + public function testLexProvider() + { + return array( + array('lex'), + array('lexKeyword'), + array('lexOperator'), + array('lexWhitespace'), + array('lexComment'), + array('lexBool'), + array('lexNumber'), + array('lexString'), + array('lexStringErr1'), + array('lexSymbol'), + array('lexSymbolUser'), + array('lexSymbolErr1'), + array('lexSymbolErr2'), + array('lexSymbolErr3'), + array('lexDelimiter'), + ); } } diff --git a/tests/lexer/TokenTest.php b/tests/lexer/TokenTest.php index 02e9ff1..640d4ed 100644 --- a/tests/lexer/TokenTest.php +++ b/tests/lexer/TokenTest.php @@ -1,8 +1,12 @@ <?php +namespace SqlParser\Tests\Lexer; + use SqlParser\Token; -class TokenTest extends PHPUnit_Framework_TestCase +use SqlParser\Tests\TestCase; + +class TokenTest extends TestCase { public function testExtractKeyword() diff --git a/tests/lexer/TokensList.php b/tests/lexer/TokensList.php index 0415a8e..8887241 100644 --- a/tests/lexer/TokensList.php +++ b/tests/lexer/TokensList.php @@ -1,8 +1,12 @@ <?php +namespace SqlParser\Tests\Lexer; + use SqlParser\Token; use SqlParser\TokensList; +use SqlParser\Tests\TestCase; + class TokensListCase extends TestCase { diff --git a/tests/parser/ArrayFragmentTest.php b/tests/parser/ArrayFragmentTest.php index ad40385..a31bf2a 100644 --- a/tests/parser/ArrayFragmentTest.php +++ b/tests/parser/ArrayFragmentTest.php @@ -1,20 +1,26 @@ <?php +namespace SqlParser\Tests\Parser; + +use SqlParser\Tests\TestCase; + class ArrayFragmentTest extends TestCase { - public function testArrayErr1() - { - $this->runParserTest('parseArrayErr1'); - } - - public function testArrayErr2() + /** + * @dataProvider testArrayProvider + */ + public function testArray($test) { - $this->runParserTest('parseArrayErr2'); + $this->runParserTest($test); } - public function testArrayErr3() + public function testArrayProvider() { - $this->runParserTest('parseArrayErr3'); + return array( + array('parseArrayErr1'), + array('parseArrayErr2'), + array('parseArrayErr3'), + ); } } diff --git a/tests/parser/CallStatementTest.php b/tests/parser/CallStatementTest.php index c558ce1..f017b14 100644 --- a/tests/parser/CallStatementTest.php +++ b/tests/parser/CallStatementTest.php @@ -1,15 +1,25 @@ <?php +namespace SqlParser\Tests\Parser; + +use SqlParser\Tests\TestCase; + class CallStatementTest extends TestCase { - public function testCall() + /** + * @dataProvider testCallProvider + */ + public function testCall($test) { - $this->runParserTest('parseCall'); + $this->runParserTest($test); } - public function testCall2() + public function testCallProvider() { - $this->runParserTest('parseCall2'); + return array( + array('parseCall'), + array('parseCall2'), + ); } } diff --git a/tests/parser/CreateStatementTest.php b/tests/parser/CreateStatementTest.php index b23e4ab..edd71fe 100644 --- a/tests/parser/CreateStatementTest.php +++ b/tests/parser/CreateStatementTest.php @@ -1,30 +1,28 @@ <?php -class CreateStatementTest extends TestCase -{ +namespace SqlParser\Tests\Parser; - public function testCreateTable() - { - $this->runParserTest('parseCreateTable'); - } +use SqlParser\Tests\TestCase; - public function testCreateProcedure() - { - $this->runParserTest('parseCreateProcedure'); - } - - public function testCreateProcedure2() - { - $this->runParserTest('parseCreateProcedure2'); - } +class CreateStatementTest extends TestCase +{ - public function testCreateFunction() + /** + * @dataProvider testCreateProvider + */ + public function testCreate($test) { - $this->runParserTest('parseCreateFunction'); + $this->runParserTest($test); } - public function testCreateFunctionErr1() + public function testCreateProvider() { - $this->runParserTest('parseCreateFunctionErr1'); + return array( + array('parseCreateTable'), + array('parseCreateProcedure'), + array('parseCreateProcedure2'), + array('parseCreateFunction'), + array('parseCreateFunctionErr1'), + ); } } diff --git a/tests/parser/DeleteStatementTest.php b/tests/parser/DeleteStatementTest.php index dab28c7..d6180e7 100644 --- a/tests/parser/DeleteStatementTest.php +++ b/tests/parser/DeleteStatementTest.php @@ -1,10 +1,24 @@ <?php +namespace SqlParser\Tests\Parser; + +use SqlParser\Tests\TestCase; + class DeleteStatementTest extends TestCase { - public function testDelete() + /** + * @dataProvider testDeleteProvider + */ + public function testDelete($test) + { + $this->runParserTest($test); + } + + public function testDeleteProvider() { - $this->runParserTest('parseDelete'); + return array( + array('parseDelete'), + ); } } diff --git a/tests/parser/InsertStatementTest.php b/tests/parser/InsertStatementTest.php index bce6065..d63054c 100644 --- a/tests/parser/InsertStatementTest.php +++ b/tests/parser/InsertStatementTest.php @@ -1,10 +1,24 @@ <?php +namespace SqlParser\Tests\Parser; + +use SqlParser\Tests\TestCase; + class InsertStatementTest extends TestCase { - public function testInsert() + /** + * @dataProvider testInsertProvider + */ + public function testInsert($test) + { + $this->runParserTest($test); + } + + public function testInsertProvider() { - $this->runParserTest('parseInsert'); + return array( + array('parseInsert'), + ); } } diff --git a/tests/parser/ParserTest.php b/tests/parser/ParserTest.php index 8a77086..dc3475b 100644 --- a/tests/parser/ParserTest.php +++ b/tests/parser/ParserTest.php @@ -1,11 +1,15 @@ <?php +namespace SqlParser\Tests\Parser; + use SqlParser\Exceptions\ParserException; use SqlParser\Lexer; use SqlParser\Parser; use SqlParser\Token; use SqlParser\TokensList; +use SqlParser\Tests\TestCase; + class ParserTest extends TestCase { diff --git a/tests/parser/RenameStatementTest.php b/tests/parser/RenameStatementTest.php index 2ae608d..62ed19d 100644 --- a/tests/parser/RenameStatementTest.php +++ b/tests/parser/RenameStatementTest.php @@ -1,15 +1,25 @@ <?php +namespace SqlParser\Tests\Parser; + +use SqlParser\Tests\TestCase; + class RenameStatementTest extends TestCase { - public function testRename() + /** + * @dataProvider testRenameProvider + */ + public function testRename($test) { - $this->runParserTest('parseRename'); + $this->runParserTest($test); } - public function testRename2() + public function testRenameProvider() { - $this->runParserTest('parseRename2'); + return array( + array('parseRename'), + array('parseRename2'), + ); } } diff --git a/tests/parser/ReplaceStatementTest.php b/tests/parser/ReplaceStatementTest.php index 4366a15..8044a8f 100644 --- a/tests/parser/ReplaceStatementTest.php +++ b/tests/parser/ReplaceStatementTest.php @@ -1,15 +1,25 @@ <?php +namespace SqlParser\Tests\Parser; + +use SqlParser\Tests\TestCase; + class ReplaceStatementTest extends TestCase { - public function testReplace() + /** + * @dataProvider testReplaceProvider + */ + public function testReplace($test) { - $this->runParserTest('parseReplace'); + $this->runParserTest($test); } - public function testReplace2() + public function testReplaceProvider() { - $this->runParserTest('parseReplace2'); + return array( + array('parseReplace'), + array('parseReplace2'), + ); } } diff --git a/tests/parser/SelectStatementTest.php b/tests/parser/SelectStatementTest.php index 21df10f..943ceb7 100644 --- a/tests/parser/SelectStatementTest.php +++ b/tests/parser/SelectStatementTest.php @@ -1,27 +1,33 @@ <?php +namespace SqlParser\Tests\Parser; + +use SqlParser\Tests\TestCase; + class SelectStatementTest extends TestCase { - public function testSelect() + public function testSelectOptions() { $parser = $this->runParserTest('parseSelect'); $stmt = $parser->statements[0]; $this->assertEquals(10, $stmt->options->has('MAX_STATEMENT_TIME')); } - public function testSelect2() - { - $this->runParserTest('parseSelect2'); - } - - public function testSelectErr1() + /** + * @dataProvider testSelectProvider + */ + public function testSelect($test) { - $this->runParserTest('parseSelectErr1'); + $this->runParserTest($test); } - public function testSelectNested() + public function testSelectProvider() { - $this->runParserTest('parseSelectNested'); + return array( + array('parseSelect2'), + array('parseSelectErr1'), + array('parseSelectNested'), + ); } } diff --git a/tests/parser/UpdateStatementTest.php b/tests/parser/UpdateStatementTest.php index 882d9ac..0bb4df0 100644 --- a/tests/parser/UpdateStatementTest.php +++ b/tests/parser/UpdateStatementTest.php @@ -1,15 +1,25 @@ <?php +namespace SqlParser\Tests\Parser; + +use SqlParser\Tests\TestCase; + class UpdateStatementTest extends TestCase { - public function testUpdate() + /** + * @dataProvider testUpdateProvider + */ + public function testUpdate($test) { - $this->runParserTest('parseUpdate'); + $this->runParserTest($test); } - public function testUpdate2() + public function testUpdateProvider() { - $this->runParserTest('parseUpdate2'); + return array( + array('parseUpdate'), + array('parseUpdate2'), + ); } } diff --git a/tests/utils/MiscTest.php b/tests/utils/MiscTest.php index a1f5194..0b04d37 100644 --- a/tests/utils/MiscTest.php +++ b/tests/utils/MiscTest.php @@ -1,8 +1,12 @@ <?php +namespace SqlParser\Tests\Utils; + use SqlParser\Parser; use SqlParser\Utils\Misc; +use SqlParser\Tests\TestCase; + class MiscTest extends TestCase { @@ -82,5 +86,4 @@ class MiscTest extends TestCase ), ); } - } diff --git a/tests/utils/RoutineTest.php b/tests/utils/RoutineTest.php index 1f95c33..950f1cc 100644 --- a/tests/utils/RoutineTest.php +++ b/tests/utils/RoutineTest.php @@ -1,8 +1,12 @@ <?php +namespace SqlParser\Tests\Utils; + use SqlParser\Parser; use SqlParser\Utils\Routine; +use SqlParser\Tests\TestCase; + class RoutineTest extends TestCase { @@ -72,7 +76,8 @@ class RoutineTest extends TestCase ) ), array( - 'CREATE PROCEDURE `foo`(IN `baz\\` INT(001) zerofill, out bazz varchar(15) charset utf8) BEGIN SELECT NULL; END', + 'CREATE PROCEDURE `foo`(IN `baz\\` INT(001) zerofill, out bazz varchar(15) charset utf8) '. + 'BEGIN SELECT NULL; END', array( 'num' => 2, 'dir' => array( @@ -99,5 +104,4 @@ class RoutineTest extends TestCase ), ); } - } |