diff options
Diffstat (limited to 'tests/Components')
21 files changed, 135 insertions, 109 deletions
diff --git a/tests/Components/Array2dTest.php b/tests/Components/Array2dTest.php index 83e6215..1c57a43 100644 --- a/tests/Components/Array2dTest.php +++ b/tests/Components/Array2dTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -13,10 +14,10 @@ class Array2dTest extends TestCase $parser = new Parser(); $arrays = Array2d::parse($parser, $this->getTokensList('(1, 2) +')); $this->assertEquals( - array( + [ 1, 2, - ), + ], $arrays[0]->values ); } diff --git a/tests/Components/ArrayObjTest.php b/tests/Components/ArrayObjTest.php index 3664e1c..f683d72 100644 --- a/tests/Components/ArrayObjTest.php +++ b/tests/Components/ArrayObjTest.php @@ -1,8 +1,10 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; use PhpMyAdmin\SqlParser\Components\ArrayObj; +use PhpMyAdmin\SqlParser\Components\Expression; use PhpMyAdmin\SqlParser\Parser; use PhpMyAdmin\SqlParser\Tests\TestCase; @@ -10,13 +12,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,21 +27,23 @@ class ArrayObjTest extends TestCase $components = ArrayObj::parse( new Parser(), $this->getTokensList('(1 + 2, 3 + 4)'), - array( - 'type' => 'PhpMyAdmin\\SqlParser\\Components\\Expression', - 'typeOptions' => array( + [ + 'type' => Expression::class, + 'typeOptions' => [ 'breakOnParentheses' => true, - ) - ) + ], + ] ); + $this->assertInstanceOf(Expression::class, $components[0]); + $this->assertInstanceOf(Expression::class, $components[1]); $this->assertEquals($components[0]->expr, '1 + 2'); $this->assertEquals($components[1]->expr, '3 + 4'); } /** - * @dataProvider parseProvider - * * @param mixed $test + * + * @dataProvider parseProvider */ public function testParse($test) { @@ -48,9 +52,9 @@ class ArrayObjTest extends TestCase public function parseProvider() { - 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 b337cb1..2ea8f8b 100644 --- a/tests/Components/CaseExpressionTest.php +++ b/tests/Components/CaseExpressionTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; diff --git a/tests/Components/ComponentTest.php b/tests/Components/ComponentTest.php index 13dbdf4..1044289 100644 --- a/tests/Components/ComponentTest.php +++ b/tests/Components/ComponentTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -6,26 +7,25 @@ use PhpMyAdmin\SqlParser\Component; use PhpMyAdmin\SqlParser\Parser; use PhpMyAdmin\SqlParser\Tests\TestCase; use PhpMyAdmin\SqlParser\TokensList; +use Throwable; class ComponentTest extends TestCase { /** - * @expectedException \Exception - * @expectedExceptionMessage Not implemented yet. * @runInSeparateProcess * @preserveGlobalState disabled */ public function testParse() { + $this->expectExceptionMessage('Not implemented yet.'); + $this->expectException(Throwable::class); Component::parse(new Parser(), new TokensList()); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Not implemented yet. - */ public function testBuild() { + $this->expectExceptionMessage('Not implemented yet.'); + $this->expectException(Throwable::class); Component::build(null); } } diff --git a/tests/Components/ConditionTest.php b/tests/Components/ConditionTest.php index 27c6a4f..eb8cca1 100644 --- a/tests/Components/ConditionTest.php +++ b/tests/Components/ConditionTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; diff --git a/tests/Components/CreateDefinitionTest.php b/tests/Components/CreateDefinitionTest.php index d00feea..d0718c8 100644 --- a/tests/Components/CreateDefinitionTest.php +++ b/tests/Components/CreateDefinitionTest.php @@ -1,9 +1,11 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; use PhpMyAdmin\SqlParser\Components\CreateDefinition; use PhpMyAdmin\SqlParser\Parser; +use PhpMyAdmin\SqlParser\Statements\CreateStatement; use PhpMyAdmin\SqlParser\Tests\TestCase; class CreateDefinitionTest extends TestCase @@ -58,6 +60,7 @@ class CreateDefinitionTest extends TestCase 'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE' . ') ENGINE=InnoDB"' ); + $this->assertInstanceOf(CreateStatement::class, $parser->statements[0]); $this->assertEquals( 'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE', CreateDefinition::build($parser->statements[0]->fields[1]) @@ -74,6 +77,7 @@ class CreateDefinitionTest extends TestCase 'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE' . ') ENGINE=InnoDB"' ); + $this->assertInstanceOf(CreateStatement::class, $parser->statements[0]); $this->assertEquals( 'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE', CreateDefinition::build($parser->statements[0]->fields[2]) diff --git a/tests/Components/ExpressionArrayTest.php b/tests/Components/ExpressionArrayTest.php index f500f8a..597d0a3 100644 --- a/tests/Components/ExpressionArrayTest.php +++ b/tests/Components/ExpressionArrayTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -13,11 +14,11 @@ class ExpressionArrayTest extends TestCase $component = ExpressionArray::parse( new Parser(), $this->getTokensList('(expr)'), - array( - 'breakOnParentheses' => true - ) + [ + 'breakOnParentheses' => true, + ] ); - $this->assertEquals(array(), $component); + $this->assertEquals([], $component); } public function testParse2() @@ -25,9 +26,9 @@ class ExpressionArrayTest extends TestCase $component = ExpressionArray::parse( new Parser(), $this->getTokensList('(expr) +'), - array( - 'parenthesesDelimited' => true - ) + [ + '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 45b8be5..8e51e01 100644 --- a/tests/Components/ExpressionTest.php +++ b/tests/Components/ExpressionTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -21,10 +22,10 @@ class ExpressionTest extends TestCase } /** - * @dataProvider parseErrProvider - * * @param mixed $expr * @param mixed $error + * + * @dataProvider parseErrProvider */ public function testParseErr($expr, $error) { @@ -36,38 +37,38 @@ class ExpressionTest extends TestCase public function parseErrProvider() { - 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') - ); + 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..386b220 100644 --- a/tests/Components/FunctionCallTest.php +++ b/tests/Components/FunctionCallTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -10,13 +11,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..41ff89a 100644 --- a/tests/Components/GroupKeywordTest.php +++ b/tests/Components/GroupKeywordTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -12,11 +13,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/IntoKeywordTest.php b/tests/Components/IntoKeywordTest.php index 2ebf5ee..896c363 100644 --- a/tests/Components/IntoKeywordTest.php +++ b/tests/Components/IntoKeywordTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; diff --git a/tests/Components/JoinKeywordTest.php b/tests/Components/JoinKeywordTest.php index 8baf93f..91fd4a6 100644 --- a/tests/Components/JoinKeywordTest.php +++ b/tests/Components/JoinKeywordTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -23,7 +24,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/KeyTest.php b/tests/Components/KeyTest.php index c27b9d8..aeb403d 100644 --- a/tests/Components/KeyTest.php +++ b/tests/Components/KeyTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; diff --git a/tests/Components/LimitTest.php b/tests/Components/LimitTest.php index 9e00a65..18e7461 100644 --- a/tests/Components/LimitTest.php +++ b/tests/Components/LimitTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -20,9 +21,9 @@ class LimitTest extends TestCase } /** - * @dataProvider parseProvider - * * @param mixed $test + * + * @dataProvider parseProvider */ public function testParse($test) { @@ -31,9 +32,9 @@ class LimitTest extends TestCase public function parseProvider() { - 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 00d5ffb..2fc86bd 100644 --- a/tests/Components/LockExpressionTest.php +++ b/tests/Components/LockExpressionTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -26,10 +27,10 @@ class LockExpressionTest extends TestCase } /** - * @dataProvider parseErrProvider - * * @param mixed $expr * @param mixed $error + * + * @dataProvider parseErrProvider */ public function testParseErr($expr, $error) { @@ -41,28 +42,28 @@ class LockExpressionTest extends TestCase public function parseErrProvider() { - 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')) - ); + 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 a642f83..3904fdf 100644 --- a/tests/Components/OptionsArrayTest.php +++ b/tests/Components/OptionsArrayTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -13,26 +14,26 @@ class OptionsArrayTest extends TestCase $component = OptionsArray::parse( new Parser(), $this->getTokensList('A B = /*comment*/ (test) C'), - array( + [ 'A' => 1, - 'B' => array( + 'B' => [ 2, 'var', - ), - 'C' => 3 - ) + ], + 'C' => 3, + ] ); $this->assertEquals( - array( + [ 1 => 'A', - 2 => array( + 2 => [ 'name' => 'B', 'expr' => '(test)', 'value' => 'test', 'equals' => true, - ), + ], 3 => 'C', - ), + ], $component->options ); } @@ -42,17 +43,17 @@ class OptionsArrayTest extends TestCase $component = OptionsArray::parse( new Parser(), $this->getTokensList('SUM = (3 + 5) RESULT = 8'), - array( - 'SUM' => array( + [ + 'SUM' => [ 1, 'expr', - array('parenthesesDelimited' => true), - ), - 'RESULT' => array( + ['parenthesesDelimited' => true], + ], + 'RESULT' => [ 2, 'var', - ) - ) + ], + ] ); $this->assertEquals('(3 + 5)', (string) $component->has('SUM', true)); $this->assertEquals('8', $component->has('RESULT')); @@ -63,14 +64,14 @@ class OptionsArrayTest extends TestCase $component = OptionsArray::parse( new Parser(), $this->getTokensList('A B = /*comment*/ (test) C'), - array( + [ 'A' => 1, - 'B' => array( + 'B' => [ 2, 'var', - ), - 'C' => 3 - ) + ], + 'C' => 3, + ] ); $this->assertTrue($component->has('A')); $this->assertEquals('test', $component->has('B')); @@ -81,23 +82,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( + 'B' => [ 2, 'var', - ), - 'C' => 3 - ) + ], + 'C' => 3, + ] ); $this->assertEquals('test', $component->has('B')); $component->remove('B'); @@ -106,23 +107,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 bc07d03..11468fb 100644 --- a/tests/Components/OrderKeywordTest.php +++ b/tests/Components/OrderKeywordTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -12,10 +13,10 @@ class OrderKeywordTest extends TestCase { $this->assertEquals( OrderKeyword::build( - array( + [ new OrderKeyword(new Expression('a'), 'ASC'), - new OrderKeyword(new Expression('b'), 'DESC') - ) + new OrderKeyword(new Expression('b'), 'DESC'), + ] ), 'a ASC, b DESC' ); diff --git a/tests/Components/ParameterDefinitionTest.php b/tests/Components/ParameterDefinitionTest.php index 683eb3a..38d28e0 100644 --- a/tests/Components/ParameterDefinitionTest.php +++ b/tests/Components/ParameterDefinitionTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; diff --git a/tests/Components/PartitionDefinitionTest.php b/tests/Components/PartitionDefinitionTest.php index 3c9a847..2d26076 100644 --- a/tests/Components/PartitionDefinitionTest.php +++ b/tests/Components/PartitionDefinitionTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; diff --git a/tests/Components/ReferenceTest.php b/tests/Components/ReferenceTest.php index dc142fe..19768c7 100644 --- a/tests/Components/ReferenceTest.php +++ b/tests/Components/ReferenceTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -13,12 +14,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)); } } diff --git a/tests/Components/RenameOperationTest.php b/tests/Components/RenameOperationTest.php index 919c4bd..6f38605 100644 --- a/tests/Components/RenameOperationTest.php +++ b/tests/Components/RenameOperationTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; |