From 66fd29cb58a59e3fd7e0cb874052e91f702d102c Mon Sep 17 00:00:00 2001 From: nikic Date: Tue, 30 Sep 2014 20:38:09 +0200 Subject: [PATCH] Use stricter assertions where possible --- test/PhpParser/Builder/InterfaceTest.php | 6 +-- test/PhpParser/CommentTest.php | 14 +++--- test/PhpParser/ErrorTest.php | 16 +++---- test/PhpParser/Lexer/EmulativeTest.php | 22 ++++----- test/PhpParser/LexerTest.php | 10 ++-- test/PhpParser/Node/NameTest.php | 48 +++++++++---------- test/PhpParser/Node/Scalar/StringTest.php | 4 +- test/PhpParser/Node/Stmt/ClassTest.php | 2 +- test/PhpParser/NodeAbstractTest.php | 26 +++++----- test/PhpParser/NodeDumperTest.php | 2 +- .../NodeVisitor/NameResolverTest.php | 32 ++++++------- test/PhpParser/ParserTest.php | 4 +- test/PhpParser/PrettyPrinterTest.php | 2 +- 13 files changed, 94 insertions(+), 94 deletions(-) diff --git a/test/PhpParser/Builder/InterfaceTest.php b/test/PhpParser/Builder/InterfaceTest.php index 1891aab..7b08ff9 100644 --- a/test/PhpParser/Builder/InterfaceTest.php +++ b/test/PhpParser/Builder/InterfaceTest.php @@ -23,7 +23,7 @@ class InterfaceTest extends \PHPUnit_Framework_TestCase public function testEmpty() { $contract = $this->builder->getNode(); $this->assertInstanceOf('PhpParser\Node\Stmt\Interface_', $contract); - $this->assertEquals('Contract', $contract->name); + $this->assertSame('Contract', $contract->name); } public function testExtending() { @@ -41,7 +41,7 @@ class InterfaceTest extends \PHPUnit_Framework_TestCase public function testAddMethod() { $method = new Stmt\ClassMethod('doSomething'); $contract = $this->builder->addStmt($method)->getNode(); - $this->assertEquals(array($method), $contract->stmts); + $this->assertSame(array($method), $contract->stmts); } public function testAddConst() { @@ -49,7 +49,7 @@ class InterfaceTest extends \PHPUnit_Framework_TestCase new Node\Const_('SPEED_OF_LIGHT', new DNumber(299792458)) )); $contract = $this->builder->addStmt($const)->getNode(); - $this->assertEquals(299792458, $contract->stmts[0]->consts[0]->value->value); + $this->assertSame(299792458, $contract->stmts[0]->consts[0]->value->value); } public function testOrder() { diff --git a/test/PhpParser/CommentTest.php b/test/PhpParser/CommentTest.php index c216e8f..96db6e6 100644 --- a/test/PhpParser/CommentTest.php +++ b/test/PhpParser/CommentTest.php @@ -7,16 +7,16 @@ class CommentTest extends \PHPUnit_Framework_TestCase public function testGetSet() { $comment = new Comment('/* Some comment */', 1); - $this->assertEquals('/* Some comment */', $comment->getText()); - $this->assertEquals('/* Some comment */', (string) $comment); - $this->assertEquals(1, $comment->getLine()); + $this->assertSame('/* Some comment */', $comment->getText()); + $this->assertSame('/* Some comment */', (string) $comment); + $this->assertSame(1, $comment->getLine()); $comment->setText('/* Some other comment */'); $comment->setLine(10); - $this->assertEquals('/* Some other comment */', $comment->getText()); - $this->assertEquals('/* Some other comment */', (string) $comment); - $this->assertEquals(10, $comment->getLine()); + $this->assertSame('/* Some other comment */', $comment->getText()); + $this->assertSame('/* Some other comment */', (string) $comment); + $this->assertSame(10, $comment->getLine()); } /** @@ -24,7 +24,7 @@ class CommentTest extends \PHPUnit_Framework_TestCase */ public function testReformatting($commentText, $reformattedText) { $comment = new Comment($commentText); - $this->assertEquals($reformattedText, $comment->getReformattedText()); + $this->assertSame($reformattedText, $comment->getReformattedText()); } public function provideTestReformatting() { diff --git a/test/PhpParser/ErrorTest.php b/test/PhpParser/ErrorTest.php index 36bb25b..62c03dc 100644 --- a/test/PhpParser/ErrorTest.php +++ b/test/PhpParser/ErrorTest.php @@ -7,9 +7,9 @@ class ErrorTest extends \PHPUnit_Framework_TestCase public function testConstruct() { $error = new Error('Some error', 10); - $this->assertEquals('Some error', $error->getRawMessage()); - $this->assertEquals(10, $error->getRawLine()); - $this->assertEquals('Some error on line 10', $error->getMessage()); + $this->assertSame('Some error', $error->getRawMessage()); + $this->assertSame(10, $error->getRawLine()); + $this->assertSame('Some error on line 10', $error->getMessage()); return $error; } @@ -21,15 +21,15 @@ class ErrorTest extends \PHPUnit_Framework_TestCase $error->setRawMessage('Some other error'); $error->setRawLine(15); - $this->assertEquals('Some other error', $error->getRawMessage()); - $this->assertEquals(15, $error->getRawLine()); - $this->assertEquals('Some other error on line 15', $error->getMessage()); + $this->assertSame('Some other error', $error->getRawMessage()); + $this->assertSame(15, $error->getRawLine()); + $this->assertSame('Some other error on line 15', $error->getMessage()); } public function testUnknownLine() { $error = new Error('Some error'); - $this->assertEquals(-1, $error->getRawLine()); - $this->assertEquals('Some error on unknown line', $error->getMessage()); + $this->assertSame(-1, $error->getRawLine()); + $this->assertSame('Some error on unknown line', $error->getMessage()); } } \ No newline at end of file diff --git a/test/PhpParser/Lexer/EmulativeTest.php b/test/PhpParser/Lexer/EmulativeTest.php index dae9261..85eda32 100644 --- a/test/PhpParser/Lexer/EmulativeTest.php +++ b/test/PhpParser/Lexer/EmulativeTest.php @@ -19,8 +19,8 @@ class EmulativeTest extends \PHPUnit_Framework_TestCase public function testReplaceKeywords($keyword, $expectedToken) { $this->lexer->startLexing('assertEquals($expectedToken, $this->lexer->getNextToken()); - $this->assertEquals(0, $this->lexer->getNextToken()); + $this->assertSame($expectedToken, $this->lexer->getNextToken()); + $this->assertSame(0, $this->lexer->getNextToken()); } /** @@ -29,9 +29,9 @@ class EmulativeTest extends \PHPUnit_Framework_TestCase public function testNoReplaceKeywordsAfterObjectOperator($keyword) { $this->lexer->startLexing('' . $keyword); - $this->assertEquals(Parser::T_OBJECT_OPERATOR, $this->lexer->getNextToken()); - $this->assertEquals(Parser::T_STRING, $this->lexer->getNextToken()); - $this->assertEquals(0, $this->lexer->getNextToken()); + $this->assertSame(Parser::T_OBJECT_OPERATOR, $this->lexer->getNextToken()); + $this->assertSame(Parser::T_STRING, $this->lexer->getNextToken()); + $this->assertSame(0, $this->lexer->getNextToken()); } public function provideTestReplaceKeywords() { @@ -62,10 +62,10 @@ class EmulativeTest extends \PHPUnit_Framework_TestCase foreach ($expectedTokens as $expectedToken) { list($expectedTokenType, $expectedTokenText) = $expectedToken; - $this->assertEquals($expectedTokenType, $this->lexer->getNextToken($text)); - $this->assertEquals($expectedTokenText, $text); + $this->assertSame($expectedTokenType, $this->lexer->getNextToken($text)); + $this->assertSame($expectedTokenText, $text); } - $this->assertEquals(0, $this->lexer->getNextToken()); + $this->assertSame(0, $this->lexer->getNextToken()); } /** @@ -75,9 +75,9 @@ class EmulativeTest extends \PHPUnit_Framework_TestCase $stringifiedToken = '"' . addcslashes($code, '"\\') . '"'; $this->lexer->startLexing('assertEquals(Parser::T_CONSTANT_ENCAPSED_STRING, $this->lexer->getNextToken($text)); - $this->assertEquals($stringifiedToken, $text); - $this->assertEquals(0, $this->lexer->getNextToken()); + $this->assertSame(Parser::T_CONSTANT_ENCAPSED_STRING, $this->lexer->getNextToken($text)); + $this->assertSame($stringifiedToken, $text); + $this->assertSame(0, $this->lexer->getNextToken()); } public function provideTestLexNewFeatures() { diff --git a/test/PhpParser/LexerTest.php b/test/PhpParser/LexerTest.php index 5e07b92..2caa72f 100644 --- a/test/PhpParser/LexerTest.php +++ b/test/PhpParser/LexerTest.php @@ -18,7 +18,7 @@ class LexerTest extends \PHPUnit_Framework_TestCase try { $this->lexer->startLexing($code); } catch (Error $e) { - $this->assertEquals($message, $e->getMessage()); + $this->assertSame($message, $e->getMessage()); return; } @@ -42,8 +42,8 @@ class LexerTest extends \PHPUnit_Framework_TestCase while ($id = $this->lexer->getNextToken($value, $startAttributes, $endAttributes)) { $token = array_shift($tokens); - $this->assertEquals($token[0], $id); - $this->assertEquals($token[1], $value); + $this->assertSame($token[0], $id); + $this->assertSame($token[1], $value); $this->assertEquals($token[2], $startAttributes); $this->assertEquals($token[3], $endAttributes); } @@ -131,8 +131,8 @@ class LexerTest extends \PHPUnit_Framework_TestCase while (Parser::T_HALT_COMPILER !== $this->lexer->getNextToken()); - $this->assertEquals($this->lexer->handleHaltCompiler(), $remaining); - $this->assertEquals(0, $this->lexer->getNextToken()); + $this->assertSame($this->lexer->handleHaltCompiler(), $remaining); + $this->assertSame(0, $this->lexer->getNextToken()); } public function provideTestHaltCompiler() { diff --git a/test/PhpParser/Node/NameTest.php b/test/PhpParser/Node/NameTest.php index ebc9c25..1b20ae3 100644 --- a/test/PhpParser/Node/NameTest.php +++ b/test/PhpParser/Node/NameTest.php @@ -6,93 +6,93 @@ class NameTest extends \PHPUnit_Framework_TestCase { public function testConstruct() { $name = new Name(array('foo', 'bar')); - $this->assertEquals(array('foo', 'bar'), $name->parts); + $this->assertSame(array('foo', 'bar'), $name->parts); $name = new Name('foo\bar'); - $this->assertEquals(array('foo', 'bar'), $name->parts); + $this->assertSame(array('foo', 'bar'), $name->parts); } public function testGet() { $name = new Name('foo'); - $this->assertEquals('foo', $name->getFirst()); - $this->assertEquals('foo', $name->getLast()); + $this->assertSame('foo', $name->getFirst()); + $this->assertSame('foo', $name->getLast()); $name = new Name('foo\bar'); - $this->assertEquals('foo', $name->getFirst()); - $this->assertEquals('bar', $name->getLast()); + $this->assertSame('foo', $name->getFirst()); + $this->assertSame('bar', $name->getLast()); } public function testToString() { $name = new Name('foo\bar'); - $this->assertEquals('foo\bar', (string) $name); - $this->assertEquals('foo\bar', $name->toString()); - $this->assertEquals('foo_bar', $name->toString('_')); + $this->assertSame('foo\bar', (string) $name); + $this->assertSame('foo\bar', $name->toString()); + $this->assertSame('foo_bar', $name->toString('_')); } public function testSet() { $name = new Name('foo'); $name->set('foo\bar'); - $this->assertEquals('foo\bar', $name->toString()); + $this->assertSame('foo\bar', $name->toString()); $name->set(array('foo', 'bar')); - $this->assertEquals('foo\bar', $name->toString()); + $this->assertSame('foo\bar', $name->toString()); $name->set(new Name('foo\bar')); - $this->assertEquals('foo\bar', $name->toString()); + $this->assertSame('foo\bar', $name->toString()); } public function testSetFirst() { $name = new Name('foo'); $name->setFirst('bar'); - $this->assertEquals('bar', $name->toString()); + $this->assertSame('bar', $name->toString()); $name->setFirst('A\B'); - $this->assertEquals('A\B', $name->toString()); + $this->assertSame('A\B', $name->toString()); $name->setFirst('C'); - $this->assertEquals('C\B', $name->toString()); + $this->assertSame('C\B', $name->toString()); $name->setFirst('D\E'); - $this->assertEquals('D\E\B', $name->toString()); + $this->assertSame('D\E\B', $name->toString()); } public function testSetLast() { $name = new Name('foo'); $name->setLast('bar'); - $this->assertEquals('bar', $name->toString()); + $this->assertSame('bar', $name->toString()); $name->setLast('A\B'); - $this->assertEquals('A\B', $name->toString()); + $this->assertSame('A\B', $name->toString()); $name->setLast('C'); - $this->assertEquals('A\C', $name->toString()); + $this->assertSame('A\C', $name->toString()); $name->setLast('D\E'); - $this->assertEquals('A\D\E', $name->toString()); + $this->assertSame('A\D\E', $name->toString()); } public function testAppend() { $name = new Name('foo'); $name->append('bar'); - $this->assertEquals('foo\bar', $name->toString()); + $this->assertSame('foo\bar', $name->toString()); $name->append('bar\foo'); - $this->assertEquals('foo\bar\bar\foo', $name->toString()); + $this->assertSame('foo\bar\bar\foo', $name->toString()); } public function testPrepend() { $name = new Name('foo'); $name->prepend('bar'); - $this->assertEquals('bar\foo', $name->toString()); + $this->assertSame('bar\foo', $name->toString()); $name->prepend('foo\bar'); - $this->assertEquals('foo\bar\bar\foo', $name->toString()); + $this->assertSame('foo\bar\bar\foo', $name->toString()); } public function testIs() { diff --git a/test/PhpParser/Node/Scalar/StringTest.php b/test/PhpParser/Node/Scalar/StringTest.php index 2e64a1f..61ed613 100644 --- a/test/PhpParser/Node/Scalar/StringTest.php +++ b/test/PhpParser/Node/Scalar/StringTest.php @@ -8,7 +8,7 @@ class StringTest extends \PHPUnit_Framework_TestCase * @dataProvider provideTestParseEscapeSequences */ public function testParseEscapeSequences($expected, $string, $quote) { - $this->assertEquals( + $this->assertSame( $expected, String::parseEscapeSequences($string, $quote) ); @@ -18,7 +18,7 @@ class StringTest extends \PHPUnit_Framework_TestCase * @dataProvider provideTestParse */ public function testCreate($expected, $string) { - $this->assertEquals( + $this->assertSame( $expected, String::parse($string) ); diff --git a/test/PhpParser/Node/Stmt/ClassTest.php b/test/PhpParser/Node/Stmt/ClassTest.php index a689f7e..c2e30ac 100644 --- a/test/PhpParser/Node/Stmt/ClassTest.php +++ b/test/PhpParser/Node/Stmt/ClassTest.php @@ -37,6 +37,6 @@ class ClassTest extends \PHPUnit_Framework_TestCase ) )); - $this->assertEquals($methods, $class->getMethods()); + $this->assertSame($methods, $class->getMethods()); } } \ No newline at end of file diff --git a/test/PhpParser/NodeAbstractTest.php b/test/PhpParser/NodeAbstractTest.php index a8b7a3e..95fed40 100644 --- a/test/PhpParser/NodeAbstractTest.php +++ b/test/PhpParser/NodeAbstractTest.php @@ -25,13 +25,13 @@ class NodeAbstractTest extends \PHPUnit_Framework_TestCase 'PhpParser_Node_Dummy' ); - $this->assertEquals('Dummy', $node->getType()); - $this->assertEquals(array('subNode'), $node->getSubNodeNames()); - $this->assertEquals(10, $node->getLine()); - $this->assertEquals('/** doc comment */', $node->getDocComment()); - $this->assertEquals('value', $node->subNode); + $this->assertSame('Dummy', $node->getType()); + $this->assertSame(array('subNode'), $node->getSubNodeNames()); + $this->assertSame(10, $node->getLine()); + $this->assertSame('/** doc comment */', $node->getDocComment()->getText()); + $this->assertSame('value', $node->subNode); $this->assertTrue(isset($node->subNode)); - $this->assertEquals($attributes, $node->getAttributes()); + $this->assertSame($attributes, $node->getAttributes()); return $node; } @@ -40,7 +40,7 @@ class NodeAbstractTest extends \PHPUnit_Framework_TestCase * @depends testConstruct */ public function testGetDocComment(Node $node) { - $this->assertEquals('/** doc comment */', $node->getDocComment()); + $this->assertSame('/** doc comment */', $node->getDocComment()->getText()); array_pop($node->getAttribute('comments')); // remove doc comment $this->assertNull($node->getDocComment()); array_pop($node->getAttribute('comments')); // remove comment @@ -53,16 +53,16 @@ class NodeAbstractTest extends \PHPUnit_Framework_TestCase public function testChange(Node $node) { // change of line $node->setLine(15); - $this->assertEquals(15, $node->getLine()); + $this->assertSame(15, $node->getLine()); // direct modification $node->subNode = 'newValue'; - $this->assertEquals('newValue', $node->subNode); + $this->assertSame('newValue', $node->subNode); // indirect modification $subNode =& $node->subNode; $subNode = 'newNewValue'; - $this->assertEquals('newNewValue', $node->subNode); + $this->assertSame('newNewValue', $node->subNode); // removal unset($node->subNode); @@ -77,18 +77,18 @@ class NodeAbstractTest extends \PHPUnit_Framework_TestCase $node->setAttribute('key', 'value'); $this->assertTrue($node->hasAttribute('key')); - $this->assertEquals('value', $node->getAttribute('key')); + $this->assertSame('value', $node->getAttribute('key')); $this->assertFalse($node->hasAttribute('doesNotExist')); $this->assertNull($node->getAttribute('doesNotExist')); - $this->assertEquals('default', $node->getAttribute('doesNotExist', 'default')); + $this->assertSame('default', $node->getAttribute('doesNotExist', 'default')); $node->setAttribute('null', null); $this->assertTrue($node->hasAttribute('null')); $this->assertNull($node->getAttribute('null')); $this->assertNull($node->getAttribute('null', 'default')); - $this->assertEquals( + $this->assertSame( array( 'key' => 'value', 'null' => null, diff --git a/test/PhpParser/NodeDumperTest.php b/test/PhpParser/NodeDumperTest.php index 9fa6824..be88e33 100644 --- a/test/PhpParser/NodeDumperTest.php +++ b/test/PhpParser/NodeDumperTest.php @@ -11,7 +11,7 @@ class NodeDumperTest extends \PHPUnit_Framework_TestCase public function testDump($node, $dump) { $dumper = new NodeDumper; - $this->assertEquals($dump, $dumper->dump($node)); + $this->assertSame($dump, $dumper->dump($node)); } public function provideTestDump() { diff --git a/test/PhpParser/NodeVisitor/NameResolverTest.php b/test/PhpParser/NodeVisitor/NameResolverTest.php index 9b7ac07..010bd33 100644 --- a/test/PhpParser/NodeVisitor/NameResolverTest.php +++ b/test/PhpParser/NodeVisitor/NameResolverTest.php @@ -133,7 +133,7 @@ EOC; $stmts = $parser->parse($code); $stmts = $traverser->traverse($stmts); - $this->assertEquals($expectedCode, $prettyPrinter->prettyPrint($stmts)); + $this->assertSame($expectedCode, $prettyPrinter->prettyPrint($stmts)); } /** @@ -200,7 +200,7 @@ EOC; $stmts = $parser->parse($code); $stmts = $traverser->traverse($stmts); - $this->assertEquals($expectedCode, $prettyPrinter->prettyPrint($stmts)); + $this->assertSame($expectedCode, $prettyPrinter->prettyPrint($stmts)); } public function testNoResolveSpecialName() { @@ -234,14 +234,14 @@ EOC; $stmts = $traverser->traverse($stmts); - $this->assertEquals('NS\\A', (string) $stmts[0]->stmts[0]->namespacedName); - $this->assertEquals('NS\\B', (string) $stmts[0]->stmts[1]->namespacedName); - $this->assertEquals('NS\\C', (string) $stmts[0]->stmts[2]->namespacedName); - $this->assertEquals('NS\\D', (string) $stmts[0]->stmts[3]->consts[0]->namespacedName); - $this->assertEquals('A', (string) $stmts[1]->stmts[0]->namespacedName); - $this->assertEquals('B', (string) $stmts[1]->stmts[1]->namespacedName); - $this->assertEquals('C', (string) $stmts[1]->stmts[2]->namespacedName); - $this->assertEquals('D', (string) $stmts[1]->stmts[3]->consts[0]->namespacedName); + $this->assertSame('NS\\A', (string) $stmts[0]->stmts[0]->namespacedName); + $this->assertSame('NS\\B', (string) $stmts[0]->stmts[1]->namespacedName); + $this->assertSame('NS\\C', (string) $stmts[0]->stmts[2]->namespacedName); + $this->assertSame('NS\\D', (string) $stmts[0]->stmts[3]->consts[0]->namespacedName); + $this->assertSame('A', (string) $stmts[1]->stmts[0]->namespacedName); + $this->assertSame('B', (string) $stmts[1]->stmts[1]->namespacedName); + $this->assertSame('C', (string) $stmts[1]->stmts[2]->namespacedName); + $this->assertSame('D', (string) $stmts[1]->stmts[3]->consts[0]->namespacedName); } public function testAddTraitNamespacedName() { @@ -254,8 +254,8 @@ EOC; $stmts = $traverser->traverse($stmts); - $this->assertEquals('NS\\A', (string) $stmts[0]->stmts[0]->namespacedName); - $this->assertEquals('A', (string) $stmts[1]->stmts[0]->namespacedName); + $this->assertSame('NS\\A', (string) $stmts[0]->stmts[0]->namespacedName); + $this->assertSame('A', (string) $stmts[1]->stmts[0]->namespacedName); } /** @@ -329,7 +329,7 @@ EOC; $stmts = $traverser->traverse($stmts); $stmt = $stmts[0]; - $this->assertEquals(array('Bar', 'Baz'), $stmt->stmts[1]->expr->class->parts); + $this->assertSame(array('Bar', 'Baz'), $stmt->stmts[1]->expr->class->parts); } public function testSpecialClassNamesAreCaseInsensitive() { @@ -358,8 +358,8 @@ EOC; $classStmt = $stmts[0]; $methodStmt = $classStmt->stmts[0]->stmts[0]; - $this->assertEquals('SELF', (string)$methodStmt->stmts[0]->class); - $this->assertEquals('PARENT', (string)$methodStmt->stmts[1]->class); - $this->assertEquals('STATIC', (string)$methodStmt->stmts[2]->class); + $this->assertSame('SELF', (string)$methodStmt->stmts[0]->class); + $this->assertSame('PARENT', (string)$methodStmt->stmts[1]->class); + $this->assertSame('STATIC', (string)$methodStmt->stmts[2]->class); } } diff --git a/test/PhpParser/ParserTest.php b/test/PhpParser/ParserTest.php index 66d5532..e818975 100644 --- a/test/PhpParser/ParserTest.php +++ b/test/PhpParser/ParserTest.php @@ -14,7 +14,7 @@ class ParserTest extends CodeTestAbstract $dumper = new NodeDumper; $stmts = $parser->parse($code); - $this->assertEquals( + $this->assertSame( $this->canonicalize($dump), $this->canonicalize($dumper->dump($stmts)), $name @@ -36,7 +36,7 @@ class ParserTest extends CodeTestAbstract $this->fail(sprintf('"%s": Expected Error', $name)); } catch (Error $e) { - $this->assertEquals($msg, $e->getMessage(), $name); + $this->assertSame($msg, $e->getMessage(), $name); } } diff --git a/test/PhpParser/PrettyPrinterTest.php b/test/PhpParser/PrettyPrinterTest.php index 791c134..ba624ec 100644 --- a/test/PhpParser/PrettyPrinterTest.php +++ b/test/PhpParser/PrettyPrinterTest.php @@ -11,7 +11,7 @@ class PrettyPrinterTest extends CodeTestAbstract $prettyPrinter = new PrettyPrinter\Standard; $stmts = $parser->parse($code); - $this->assertEquals( + $this->assertSame( $this->canonicalize($dump), $this->canonicalize($prettyPrinter->$method($stmts)), $name