Skip to content

Commit

Permalink
Refactoring tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carusogabriel committed Dec 15, 2017
1 parent acd10db commit 768a0d7
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 36 deletions.
16 changes: 8 additions & 8 deletions tests/Components/Array2dTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function testParseErr3()
{
$parser = new Parser();
Array2d::parse($parser, $this->getTokensList(')'));
$this->assertEquals(
$this->assertCount(
1,
count($parser->errors)
$parser->errors
);
$this->assertEquals(
'An opening bracket followed by a set of values was expected.',
Expand All @@ -58,9 +58,9 @@ public function testParseErr4()
{
$parser = new Parser();
Array2d::parse($parser, $this->getTokensList('TABLE'));
$this->assertEquals(
$this->assertCount(
1,
count($parser->errors)
$parser->errors
);
$this->assertEquals(
'An opening bracket followed by a set of values was expected.',
Expand All @@ -72,9 +72,9 @@ public function testParseErr5()
{
$parser = new Parser();
Array2d::parse($parser, $this->getTokensList('(1, 2),'));
$this->assertEquals(
$this->assertCount(
1,
count($parser->errors)
$parser->errors
);
$this->assertEquals(
'An opening bracket followed by a set of values was expected.',
Expand All @@ -86,9 +86,9 @@ public function testParseErr6()
{
$parser = new Parser();
Array2d::parse($parser, $this->getTokensList('(1, 2),(3)'));
$this->assertEquals(
$this->assertCount(
1,
count($parser->errors)
$parser->errors
);
$this->assertEquals(
'2 values were expected, but found 1.',
Expand Down
2 changes: 1 addition & 1 deletion tests/Components/CreateDefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testParseErr1()
$parser,
$this->getTokensList('(str TEXT, FULLTEXT INDEX indx (str)')
);
$this->assertEquals(2, count($component));
$this->assertCount(2, $component);

$this->assertEquals(
'A closing bracket was expected.',
Expand Down
2 changes: 1 addition & 1 deletion tests/Components/ExpressionArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testParse2()
'parenthesesDelimited' => true,
)
);
$this->assertEquals(1, count($component));
$this->assertCount(1, $component);
$this->assertEquals('(expr)', $component[0]->expr);
}
}
10 changes: 5 additions & 5 deletions tests/Components/JoinKeywordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ class JoinKeywordTest extends TestCase
public function testParseIncomplete()
{
$component = JoinKeyword::parse(new Parser(), $this->getTokensList('JOIN a'));
$this->assertEquals(1, count($component));
$this->assertCount(1, $component);
$this->assertEquals('a', $component[0]->expr->expr);
$this->assertEquals(null, $component[0]->on);
$this->assertEquals(null, $component[0]->using);
$this->assertNull($component[0]->on);
$this->assertNull($component[0]->using);
}

public function testParseIncompleteUsing()
{
$component = JoinKeyword::parse(new Parser(), $this->getTokensList('JOIN table2 USING (id)'));
$this->assertEquals(1, count($component));
$this->assertCount(1, $component);
$this->assertEquals('table2', $component[0]->expr->expr);
$this->assertEquals(null, $component[0]->on);
$this->assertNull($component[0]->on);
$this->assertEquals(array('id'), $component[0]->using->values);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Components/KeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public function testParse()
new Parser(),
$this->getTokensList('')
);
$this->assertEquals(null, $component->name);
$this->assertNull($component->name);
}
}
8 changes: 4 additions & 4 deletions tests/Lexer/ContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ public function testLoad()
{
// Default context is 5.7.0.
$this->assertEquals('\\PhpMyAdmin\\SqlParser\\Contexts\\ContextMySql50700', Context::$loadedContext);
$this->assertTrue(isset(Context::$KEYWORDS['STORED']));
$this->assertFalse(isset(Context::$KEYWORDS['AUTHORS']));
$this->assertArrayHasKey('STORED', Context::$KEYWORDS);
$this->assertArrayNotHasKey('AUTHORS', Context::$KEYWORDS);

// Restoring context.
Context::load('');
$this->assertEquals('\\PhpMyAdmin\\SqlParser\\Contexts\\ContextMySql50700', Context::$defaultContext);
$this->assertTrue(isset(Context::$KEYWORDS['STORED']));
$this->assertFalse(isset(Context::$KEYWORDS['AUTHORS']));
$this->assertArrayHasKey('STORED', Context::$KEYWORDS);
$this->assertArrayNotHasKey('AUTHORS', Context::$KEYWORDS);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions tests/Lexer/IsMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public function testIsKeyword()
);

$this->assertEquals(1 | Token::FLAG_KEYWORD_RESERVED, Context::isKeyword('FROM', true));
$this->assertEquals(null, Context::isKeyword('MODIFY', true));
$this->assertNull(Context::isKeyword('MODIFY', true));

$this->assertEquals(null, Context::isKeyword('foo'));
$this->assertEquals(null, Context::isKeyword('bar baz'));
$this->assertNull(Context::isKeyword('foo'));
$this->assertNull(Context::isKeyword('bar baz'));
}

public function testIsOperator()
Expand All @@ -40,7 +40,7 @@ public function testIsOperator()
$this->assertEquals(Token::FLAG_OPERATOR_ASSIGNMENT, Context::isOperator(':='));
$this->assertEquals(Token::FLAG_OPERATOR_SQL, Context::isOperator(','));

$this->assertEquals(Context::isOperator('a'), null);
$this->assertNull(Context::isOperator('a'));
}

public function testIsWhitespace()
Expand Down Expand Up @@ -68,7 +68,7 @@ public function testIsComment()
$this->assertEquals(Token::FLAG_COMMENT_C, Context::isComment('/*comment */'));
$this->assertEquals(Token::FLAG_COMMENT_SQL, Context::isComment('-- my comment'));

$this->assertEquals(null, Context::isComment('--not a comment'));
$this->assertNull(Context::isComment('--not a comment'));
}

public function testIsBool()
Expand Down
10 changes: 5 additions & 5 deletions tests/Lexer/TokensListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ public function testGetNext()
$this->assertEquals($this->tokens[2], $list->getNext());
$this->assertEquals($this->tokens[4], $list->getNext());
$this->assertEquals($this->tokens[6], $list->getNext());
$this->assertEquals(null, $list->getNext());
$this->assertNull($list->getNext());
}

public function testGetNextOfType()
{
$list = new TokensList($this->tokens);
$this->assertEquals($this->tokens[0], $list->getNextOfType(Token::TYPE_KEYWORD));
$this->assertEquals($this->tokens[4], $list->getNextOfType(Token::TYPE_KEYWORD));
$this->assertEquals(null, $list->getNextOfType(Token::TYPE_KEYWORD));
$this->assertNull($list->getNextOfType(Token::TYPE_KEYWORD));
}

public function testGetNextOfTypeAndValue()
{
$list = new TokensList($this->tokens);
$this->assertEquals($this->tokens[0], $list->getNextOfTypeAndValue(Token::TYPE_KEYWORD, 'SELECT'));
$this->assertEquals(null, $list->getNextOfTypeAndValue(Token::TYPE_KEYWORD, 'SELECT'));
$this->assertNull($list->getNextOfTypeAndValue(Token::TYPE_KEYWORD, 'SELECT'));
}

public function testArrayAccess()
Expand All @@ -90,8 +90,8 @@ public function testArrayAccess()
}

// offsetExists($offset)
$this->assertTrue(isset($list[2]));
$this->assertFalse(isset($list[8]));
$this->assertArrayHasKey(2, $list);
$this->assertArrayNotHasKey(8, $list);

// offsetUnset($offset)
unset($list[2]);
Expand Down
10 changes: 5 additions & 5 deletions tests/Misc/UtfStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ public function testArrayAccess()
$str = new UtfString(static::TEST_PHRASE);

// offsetExists
$this->assertTrue(isset($str[static::TEST_PHRASE_LEN - 1]));
$this->assertFalse(isset($str[-1]));
$this->assertFalse(isset($str[static::TEST_PHRASE_LEN]));
$this->assertArrayHasKey(static::TEST_PHRASE_LEN - 1, $str);
$this->assertArrayNotHasKey(-1, $str);
$this->assertArrayNotHasKey(static::TEST_PHRASE_LEN, $str);

// offsetGet
$this->assertEquals('.', $str[static::TEST_PHRASE_LEN - 1]);
$this->assertEquals(null, $str[-1]);
$this->assertEquals(null, $str[static::TEST_PHRASE_LEN]);
$this->assertNull($str[-1]);
$this->assertNull($str[static::TEST_PHRASE_LEN]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Utils/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ public function testGetFirstStatement()
$delimiter = null;
list($statement, $query, $delimiter) =
Query::getFirstStatement($query, $delimiter);
$this->assertEquals(null, $statement);
$this->assertNull($statement);
$this->assertEquals('USE saki', $query);

$query = 'USE sakila; ' .
Expand Down

0 comments on commit 768a0d7

Please sign in to comment.