diff options
author | Maurício Meneghini Fauth <mauriciofauth@gmail.com> | 2019-01-08 21:32:02 -0200 |
---|---|---|
committer | Maurício Meneghini Fauth <mauriciofauth@gmail.com> | 2019-01-16 17:21:25 -0200 |
commit | 86c5baebda24c1721fb6881df8671a3c7df60e8b (patch) | |
tree | 0a76d58ea229d1008e169b1c5b25ce90dde91808 /tests/Components | |
parent | 28427543566b6dd32fe44db704ea41368ba55c0e (diff) | |
download | sql-parser-86c5baebda24c1721fb6881df8671a3c7df60e8b.zip sql-parser-86c5baebda24c1721fb6881df8671a3c7df60e8b.tar.gz sql-parser-86c5baebda24c1721fb6881df8671a3c7df60e8b.tar.bz2 |
Apply phpmyadmin/coding-standard
Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
Diffstat (limited to 'tests/Components')
-rw-r--r-- | tests/Components/Array2dTest.php | 5 | ||||
-rw-r--r-- | tests/Components/ArrayObjTest.php | 20 | ||||
-rw-r--r-- | tests/Components/CaseExpressionTest.php | 18 | ||||
-rw-r--r-- | tests/Components/ExpressionArrayTest.php | 10 | ||||
-rw-r--r-- | tests/Components/ExpressionTest.php | 24 | ||||
-rw-r--r-- | tests/Components/FunctionCallTest.php | 4 | ||||
-rw-r--r-- | tests/Components/GroupKeywordTest.php | 4 | ||||
-rw-r--r-- | tests/Components/JoinKeywordTest.php | 2 | ||||
-rw-r--r-- | tests/Components/LimitTest.php | 8 | ||||
-rw-r--r-- | tests/Components/LockExpressionTest.php | 20 | ||||
-rw-r--r-- | tests/Components/OptionsArrayTest.php | 68 | ||||
-rw-r--r-- | tests/Components/OrderKeywordTest.php | 4 | ||||
-rw-r--r-- | tests/Components/ReferenceTest.php | 4 |
13 files changed, 108 insertions, 83 deletions
diff --git a/tests/Components/Array2dTest.php b/tests/Components/Array2dTest.php index a4dd7b5..2e2cf6b 100644 --- a/tests/Components/Array2dTest.php +++ b/tests/Components/Array2dTest.php @@ -13,7 +13,10 @@ class Array2dTest extends TestCase $parser = new Parser(); $arrays = Array2d::parse($parser, $this->getTokensList('(1, 2) +')); $this->assertEquals( - array(1, 2), + [ + 1, + 2, + ], $arrays[0]->values ); } diff --git a/tests/Components/ArrayObjTest.php b/tests/Components/ArrayObjTest.php index 4c782d2..ccef92f 100644 --- a/tests/Components/ArrayObjTest.php +++ b/tests/Components/ArrayObjTest.php @@ -10,13 +10,13 @@ class ArrayObjTest extends TestCase { public function testBuildRaw() { - $component = new ArrayObj(array('a', 'b'), array()); + $component = new ArrayObj(['a', 'b'], []); $this->assertEquals('(a, b)', ArrayObj::build($component)); } public function testBuildValues() { - $component = new ArrayObj(array(), array('a', 'b')); + $component = new ArrayObj([], ['a', 'b']); $this->assertEquals('(a, b)', ArrayObj::build($component)); } @@ -25,12 +25,12 @@ class ArrayObjTest extends TestCase $components = ArrayObj::parse( new Parser(), $this->getTokensList('(1 + 2, 3 + 4)'), - array( + [ 'type' => 'PhpMyAdmin\\SqlParser\\Components\\Expression', - 'typeOptions' => array( + 'typeOptions' => [ 'breakOnParentheses' => true, - ), - ) + ], + ] ); $this->assertEquals($components[0]->expr, '1 + 2'); $this->assertEquals($components[1]->expr, '3 + 4'); @@ -48,9 +48,9 @@ class ArrayObjTest extends TestCase public function testParseProvider() { - return array( - array('parser/parseArrayErr1'), - array('parser/parseArrayErr3'), - ); + return [ + ['parser/parseArrayErr1'], + ['parser/parseArrayErr3'], + ]; } } diff --git a/tests/Components/CaseExpressionTest.php b/tests/Components/CaseExpressionTest.php index 475486f..52078ef 100644 --- a/tests/Components/CaseExpressionTest.php +++ b/tests/Components/CaseExpressionTest.php @@ -13,7 +13,8 @@ class CaseExpressionTest extends TestCase $caseExprQuery = 'case 1 when 1 then "Some" else "Other" end'; $component = CaseExpression::parse( new Parser(), - $this->getTokensList($caseExprQuery)); + $this->getTokensList($caseExprQuery) + ); $this->assertEquals( CaseExpression::build($component), 'CASE 1 WHEN 1 THEN "Some" ELSE "Other" END' @@ -25,7 +26,8 @@ class CaseExpressionTest extends TestCase $caseExprQuery = 'case when 1=1 then "India" else "Other" end'; $component = CaseExpression::parse( new Parser(), - $this->getTokensList($caseExprQuery)); + $this->getTokensList($caseExprQuery) + ); $this->assertEquals( CaseExpression::build($component), 'CASE WHEN 1=1 THEN "India" ELSE "Other" END' @@ -38,7 +40,8 @@ class CaseExpressionTest extends TestCase . 'when 2 then "SomeOther" else "Other" end'; $component = CaseExpression::parse( new Parser(), - $this->getTokensList($caseExprQuery)); + $this->getTokensList($caseExprQuery) + ); $this->assertEquals( CaseExpression::build($component), 'CASE 1 WHEN 1 THEN "Some" WHEN 2 THEN "SomeOther" ELSE "Other" END' @@ -51,7 +54,8 @@ class CaseExpressionTest extends TestCase . 'when 2 then "SomeOther" end'; $component = CaseExpression::parse( new Parser(), - $this->getTokensList($caseExprQuery)); + $this->getTokensList($caseExprQuery) + ); $this->assertEquals( CaseExpression::build($component), 'CASE 1 WHEN 1 THEN "Some" WHEN 2 THEN "SomeOther" END' @@ -64,7 +68,8 @@ class CaseExpressionTest extends TestCase . 'when 1=2 then "SomeOther" else "Other" end'; $component = CaseExpression::parse( new Parser(), - $this->getTokensList($caseExprQuery)); + $this->getTokensList($caseExprQuery) + ); $this->assertEquals( CaseExpression::build($component), 'CASE WHEN 1=1 THEN "Some" WHEN 1=2 THEN "SomeOther" ELSE "Other" END' @@ -77,7 +82,8 @@ class CaseExpressionTest extends TestCase . 'when 1=2 then "SomeOther" end'; $component = CaseExpression::parse( new Parser(), - $this->getTokensList($caseExprQuery)); + $this->getTokensList($caseExprQuery) + ); $this->assertEquals( CaseExpression::build($component), 'CASE WHEN 1=1 THEN "Some" WHEN 1=2 THEN "SomeOther" END' diff --git a/tests/Components/ExpressionArrayTest.php b/tests/Components/ExpressionArrayTest.php index cd413ac..ede3954 100644 --- a/tests/Components/ExpressionArrayTest.php +++ b/tests/Components/ExpressionArrayTest.php @@ -13,11 +13,11 @@ class ExpressionArrayTest extends TestCase $component = ExpressionArray::parse( new Parser(), $this->getTokensList('(expr)'), - array( + [ 'breakOnParentheses' => true, - ) + ] ); - $this->assertEquals(array(), $component); + $this->assertEquals([], $component); } public function testParse2() @@ -25,9 +25,9 @@ class ExpressionArrayTest extends TestCase $component = ExpressionArray::parse( new Parser(), $this->getTokensList('(expr) +'), - array( + [ 'parenthesesDelimited' => true, - ) + ] ); $this->assertCount(1, $component); $this->assertEquals('(expr)', $component[0]->expr); diff --git a/tests/Components/ExpressionTest.php b/tests/Components/ExpressionTest.php index bb4b8fc..943aa6a 100644 --- a/tests/Components/ExpressionTest.php +++ b/tests/Components/ExpressionTest.php @@ -36,38 +36,38 @@ class ExpressionTest extends TestCase public function testParseErrProvider() { - return array( + return [ /* array( '(1))', 'Unexpected closing bracket.', ), */ - array( + [ 'tbl..col', 'Unexpected dot.', - ), - array( + ], + [ 'id AS AS id2', 'An alias was expected.', - ), - array( + ], + [ 'id`id2`\'id3\'', 'An alias was previously found.', - ), - array( + ], + [ '(id) id2 id3', 'An alias was previously found.', - ), - ); + ], + ]; } public function testBuild() { - $component = array( + $component = [ new Expression('1 + 2', 'three'), new Expression('1 + 3', 'four'), - ); + ]; $this->assertEquals( Expression::build($component), '1 + 2 AS `three`, 1 + 3 AS `four`' diff --git a/tests/Components/FunctionCallTest.php b/tests/Components/FunctionCallTest.php index b8b485a..20ac4c6 100644 --- a/tests/Components/FunctionCallTest.php +++ b/tests/Components/FunctionCallTest.php @@ -10,13 +10,13 @@ class FunctionCallTest extends TestCase { public function testBuildArray() { - $component = new FunctionCall('func', array('a', 'b')); + $component = new FunctionCall('func', ['a', 'b']); $this->assertEquals('func(a, b)', FunctionCall::build($component)); } public function testBuildArrayObj() { - $component = new FunctionCall('func', new ArrayObj(array('a', 'b'))); + $component = new FunctionCall('func', new ArrayObj(['a', 'b'])); $this->assertEquals('func(a, b)', FunctionCall::build($component)); } } diff --git a/tests/Components/GroupKeywordTest.php b/tests/Components/GroupKeywordTest.php index 8d4a407..aa88c60 100644 --- a/tests/Components/GroupKeywordTest.php +++ b/tests/Components/GroupKeywordTest.php @@ -12,11 +12,11 @@ class GroupKeywordTest extends TestCase { $this->assertEquals( GroupKeyword::build( - array( + [ new GroupKeyword(new Expression('a')), new GroupKeyword(new Expression('b')), new GroupKeyword(new Expression('c')), - ) + ] ), 'a, b, c' ); diff --git a/tests/Components/JoinKeywordTest.php b/tests/Components/JoinKeywordTest.php index 8baf93f..9e8b85f 100644 --- a/tests/Components/JoinKeywordTest.php +++ b/tests/Components/JoinKeywordTest.php @@ -23,7 +23,7 @@ class JoinKeywordTest extends TestCase $this->assertCount(1, $component); $this->assertEquals('table2', $component[0]->expr->expr); $this->assertNull($component[0]->on); - $this->assertEquals(array('id'), $component[0]->using->values); + $this->assertEquals(['id'], $component[0]->using->values); } public function testBuild() diff --git a/tests/Components/LimitTest.php b/tests/Components/LimitTest.php index e78f5ff..8d336b2 100644 --- a/tests/Components/LimitTest.php +++ b/tests/Components/LimitTest.php @@ -31,9 +31,9 @@ class LimitTest extends TestCase public function testParseProvider() { - return array( - array('parser/parseLimitErr1'), - array('parser/parseLimitErr2'), - ); + return [ + ['parser/parseLimitErr1'], + ['parser/parseLimitErr2'], + ]; } } diff --git a/tests/Components/LockExpressionTest.php b/tests/Components/LockExpressionTest.php index 56654a6..0f8e418 100644 --- a/tests/Components/LockExpressionTest.php +++ b/tests/Components/LockExpressionTest.php @@ -41,28 +41,28 @@ class LockExpressionTest extends TestCase public function testParseErrProvider() { - return array( - array( + return [ + [ 'table1 AS t1', 'Unexpected end of LOCK expression.', - ), - array( + ], + [ 'table1 AS t1 READ WRITE', 'Unexpected keyword.', - ), - array( + ], + [ 'table1 AS t1 READ 2', 'Unexpected token.', - ), - ); + ], + ]; } public function testBuild() { - $component = array( + $component = [ LockExpression::parse(new Parser(), $this->getTokensList('table1 AS t1 READ LOCAL')), LockExpression::parse(new Parser(), $this->getTokensList('table2 LOW_PRIORITY WRITE')), - ); + ]; $this->assertEquals( LockExpression::build($component), 'table1 AS `t1` READ LOCAL, table2 LOW_PRIORITY WRITE' diff --git a/tests/Components/OptionsArrayTest.php b/tests/Components/OptionsArrayTest.php index 4dda0db..c5b6eb7 100644 --- a/tests/Components/OptionsArrayTest.php +++ b/tests/Components/OptionsArrayTest.php @@ -13,23 +13,26 @@ class OptionsArrayTest extends TestCase $component = OptionsArray::parse( new Parser(), $this->getTokensList('A B = /*comment*/ (test) C'), - array( + [ 'A' => 1, - 'B' => array(2, 'var'), + 'B' => [ + 2, + 'var', + ], 'C' => 3, - ) + ] ); $this->assertEquals( - array( + [ 1 => 'A', - 2 => array( + 2 => [ 'name' => 'B', 'expr' => '(test)', 'value' => 'test', 'equals' => true, - ), + ], 3 => 'C', - ), + ], $component->options ); } @@ -39,10 +42,17 @@ class OptionsArrayTest extends TestCase $component = OptionsArray::parse( new Parser(), $this->getTokensList('SUM = (3 + 5) RESULT = 8'), - array( - 'SUM' => array(1, 'expr', array('parenthesesDelimited' => true)), - 'RESULT' => array(2, 'var'), - ) + [ + 'SUM' => [ + 1, + 'expr', + ['parenthesesDelimited' => true], + ], + 'RESULT' => [ + 2, + 'var', + ], + ] ); $this->assertEquals('(3 + 5)', (string) $component->has('SUM', true)); $this->assertEquals('8', $component->has('RESULT')); @@ -53,11 +63,14 @@ class OptionsArrayTest extends TestCase $component = OptionsArray::parse( new Parser(), $this->getTokensList('A B = /*comment*/ (test) C'), - array( + [ 'A' => 1, - 'B' => array(2, 'var'), + 'B' => [ + 2, + 'var', + ], 'C' => 3, - ) + ] ); $this->assertTrue($component->has('A')); $this->assertEquals('test', $component->has('B')); @@ -68,20 +81,23 @@ class OptionsArrayTest extends TestCase public function testRemove() { /* Assertion 1 */ - $component = new OptionsArray(array('a', 'b', 'c')); + $component = new OptionsArray(['a', 'b', 'c']); $this->assertTrue($component->remove('b')); $this->assertFalse($component->remove('d')); - $this->assertEquals($component->options, array(0 => 'a', 2 => 'c')); + $this->assertEquals($component->options, [0 => 'a', 2 => 'c']); /* Assertion 2 */ $component = OptionsArray::parse( new Parser(), $this->getTokensList('A B = /*comment*/ (test) C'), - array( + [ 'A' => 1, - 'B' => array(2, 'var'), + 'B' => [ + 2, + 'var', + ], 'C' => 3, - ) + ] ); $this->assertEquals('test', $component->has('B')); $component->remove('B'); @@ -90,23 +106,23 @@ class OptionsArrayTest extends TestCase public function testMerge() { - $component = new OptionsArray(array('a')); - $component->merge(array('b', 'c')); - $this->assertEquals($component->options, array('a', 'b', 'c')); + $component = new OptionsArray(['a']); + $component->merge(['b', 'c']); + $this->assertEquals($component->options, ['a', 'b', 'c']); } public function testBuild() { $component = new OptionsArray( - array( + [ 'ALL', 'SQL_CALC_FOUND_ROWS', - array( + [ 'name' => 'MAX_STATEMENT_TIME', 'value' => '42', 'equals' => true, - ), - ) + ], + ] ); $this->assertEquals( OptionsArray::build($component), diff --git a/tests/Components/OrderKeywordTest.php b/tests/Components/OrderKeywordTest.php index c0777ec..ffacfd4 100644 --- a/tests/Components/OrderKeywordTest.php +++ b/tests/Components/OrderKeywordTest.php @@ -12,10 +12,10 @@ class OrderKeywordTest extends TestCase { $this->assertEquals( OrderKeyword::build( - array( + [ new OrderKeyword(new Expression('a'), 'ASC'), new OrderKeyword(new Expression('b'), 'DESC'), - ) + ] ), 'a ASC, b DESC' ); diff --git a/tests/Components/ReferenceTest.php b/tests/Components/ReferenceTest.php index dc142fe..178776c 100644 --- a/tests/Components/ReferenceTest.php +++ b/tests/Components/ReferenceTest.php @@ -13,12 +13,12 @@ class ReferenceTest extends TestCase { $component = Reference::parse(new Parser(), $this->getTokensList('tbl (id)')); $this->assertEquals('tbl', $component->table->table); - $this->assertEquals(array('id'), $component->columns); + $this->assertEquals(['id'], $component->columns); } public function testBuild() { - $component = new Reference(new Expression('`tbl`'), array('id')); + $component = new Reference(new Expression('`tbl`'), ['id']); $this->assertEquals('`tbl` (`id`)', Reference::build($component)); } } |