From c6768821918b97b4e9e4c507d2aa58b4f8eda271 Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Mon, 19 Feb 2024 23:07:07 +0200 Subject: [PATCH] Apply the PHPUnitSetList::PHPUNIT_CODE_QUALITY set of rules --- rector.php | 3 +- src/Lexer/AbstractLexer.php | 1 + src/Lexer/Recognizer/RegexRecognizer.php | 1 + src/Lexer/Recognizer/SimpleRecognizer.php | 1 + src/Lexer/RegexLexer.php | 1 + src/Lexer/SimpleLexer.php | 1 + src/Lexer/StatefulLexer.php | 1 + src/Lexer/TokenStream/ArrayTokenStream.php | 1 + src/Parser/Grammar.php | 1 + src/Parser/LALR1/Analysis/Analyzer.php | 1 + src/Parser/LALR1/Analysis/Automaton.php | 1 + src/Parser/LALR1/Analysis/Item.php | 1 + .../LALR1/Analysis/KernelSet/KernelSet.php | 1 + src/Parser/LALR1/Analysis/State.php | 1 + src/Parser/LALR1/Dumper/AutomatonDumper.php | 1 + src/Parser/LALR1/Dumper/DebugTableDumper.php | 1 + .../LALR1/Dumper/ProductionTableDumper.php | 1 + src/Parser/LALR1/Parser.php | 1 + src/Parser/Rule.php | 1 + tests/Lexer/AbstractLexerTest.php | 26 +++--- .../Lexer/Recognizer/RegexRecognizerTest.php | 2 +- .../Lexer/Recognizer/SimpleRecognizerTest.php | 2 +- tests/Lexer/RegexLexerTest.php | 10 +-- tests/Lexer/SimpleLexerTest.php | 14 ++-- tests/Lexer/StatefulLexerTest.php | 8 +- .../TokenStream/ArrayTokenStreamTest.php | 16 ++-- tests/Parser/GrammarTest.php | 8 +- tests/Parser/LALR1/Analysis/AnalyzerTest.php | 84 +++++++++---------- tests/Parser/LALR1/Analysis/AutomatonTest.php | 2 +- tests/Parser/LALR1/Analysis/ItemTest.php | 6 +- .../Analysis/KernelSet/KernelSetTest.php | 10 +-- tests/Parser/LALR1/ParserTest.php | 14 ++-- tests/Parser/RuleTest.php | 2 +- 33 files changed, 122 insertions(+), 103 deletions(-) diff --git a/rector.php b/rector.php index 2ea5420..c216c38 100644 --- a/rector.php +++ b/rector.php @@ -32,5 +32,6 @@ // DeclareStrictTypesRector::class, ]) ->withSets([ - PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES + PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES, + PHPUnitSetList::PHPUNIT_CODE_QUALITY, ]); diff --git a/src/Lexer/AbstractLexer.php b/src/Lexer/AbstractLexer.php index 97fdd4a..9603914 100644 --- a/src/Lexer/AbstractLexer.php +++ b/src/Lexer/AbstractLexer.php @@ -16,6 +16,7 @@ * SimpleLexer and StatefulLexer extend this class. * * @author Jakub Lédl + * @see \Dissect\Lexer\AbstractLexerTest */ abstract class AbstractLexer implements Lexer { diff --git a/src/Lexer/Recognizer/RegexRecognizer.php b/src/Lexer/Recognizer/RegexRecognizer.php index 49d96cb..7956de2 100644 --- a/src/Lexer/Recognizer/RegexRecognizer.php +++ b/src/Lexer/Recognizer/RegexRecognizer.php @@ -9,6 +9,7 @@ * regular expression. * * @author Jakub Lédl + * @see \Dissect\Lexer\Recognizer\RegexRecognizerTest */ class RegexRecognizer implements Recognizer { diff --git a/src/Lexer/Recognizer/SimpleRecognizer.php b/src/Lexer/Recognizer/SimpleRecognizer.php index 43d1153..a03a5a7 100644 --- a/src/Lexer/Recognizer/SimpleRecognizer.php +++ b/src/Lexer/Recognizer/SimpleRecognizer.php @@ -9,6 +9,7 @@ * strpos match. * * @author Jakub Lédl + * @see \Dissect\Lexer\Recognizer\SimpleRecognizerTest */ class SimpleRecognizer implements Recognizer { diff --git a/src/Lexer/RegexLexer.php b/src/Lexer/RegexLexer.php index 759feac..673aacc 100644 --- a/src/Lexer/RegexLexer.php +++ b/src/Lexer/RegexLexer.php @@ -15,6 +15,7 @@ * @author Jonathan Wage * @author Roman Borschel * @author Jakub Lédl + * @see \Dissect\Lexer\RegexLexerTest */ abstract class RegexLexer implements Lexer { diff --git a/src/Lexer/SimpleLexer.php b/src/Lexer/SimpleLexer.php index 3168b1e..854ff6c 100644 --- a/src/Lexer/SimpleLexer.php +++ b/src/Lexer/SimpleLexer.php @@ -13,6 +13,7 @@ * without keeping track of state. * * @author Jakub Lédl + * @see \Dissect\Lexer\SimpleLexerTest */ class SimpleLexer extends AbstractLexer { diff --git a/src/Lexer/StatefulLexer.php b/src/Lexer/StatefulLexer.php index da12872..6a4ac5c 100644 --- a/src/Lexer/StatefulLexer.php +++ b/src/Lexer/StatefulLexer.php @@ -14,6 +14,7 @@ * but internally keeps notion of current lexer state. * * @author Jakub Lédl + * @see \Dissect\Lexer\StatefulLexerTest */ class StatefulLexer extends AbstractLexer { diff --git a/src/Lexer/TokenStream/ArrayTokenStream.php b/src/Lexer/TokenStream/ArrayTokenStream.php index ec55572..c31b631 100644 --- a/src/Lexer/TokenStream/ArrayTokenStream.php +++ b/src/Lexer/TokenStream/ArrayTokenStream.php @@ -12,6 +12,7 @@ * A simple array based implementation of a token stream. * * @author Jakub Lédl + * @see \Dissect\Lexer\TokenStream\ArrayTokenStreamTest */ class ArrayTokenStream implements TokenStream { diff --git a/src/Parser/Grammar.php b/src/Parser/Grammar.php index 116e50c..e795b36 100644 --- a/src/Parser/Grammar.php +++ b/src/Parser/Grammar.php @@ -10,6 +10,7 @@ * Represents a context-free grammar. * * @author Jakub Lédl + * @see \Dissect\Parser\GrammarTest */ class Grammar { diff --git a/src/Parser/LALR1/Analysis/Analyzer.php b/src/Parser/LALR1/Analysis/Analyzer.php index 63548d6..a6fefe4 100644 --- a/src/Parser/LALR1/Analysis/Analyzer.php +++ b/src/Parser/LALR1/Analysis/Analyzer.php @@ -17,6 +17,7 @@ * the result. * * @author Jakub Lédl + * @see \Dissect\Parser\LALR1\Analysis\AnalyzerTest */ class Analyzer { diff --git a/src/Parser/LALR1/Analysis/Automaton.php b/src/Parser/LALR1/Analysis/Automaton.php index 6bfba8a..03c4eb3 100644 --- a/src/Parser/LALR1/Analysis/Automaton.php +++ b/src/Parser/LALR1/Analysis/Automaton.php @@ -9,6 +9,7 @@ * grammar productions. * * @author Jakub Lédl + * @see \Dissect\Parser\LALR1\Analysis\AutomatonTest */ class Automaton { diff --git a/src/Parser/LALR1/Analysis/Item.php b/src/Parser/LALR1/Analysis/Item.php index 98dfbca..c517731 100644 --- a/src/Parser/LALR1/Analysis/Item.php +++ b/src/Parser/LALR1/Analysis/Item.php @@ -29,6 +29,7 @@ * can be reduced. * * @author Jakub Lédl + * @see \Dissect\Parser\LALR1\Analysis\ItemTest */ class Item { diff --git a/src/Parser/LALR1/Analysis/KernelSet/KernelSet.php b/src/Parser/LALR1/Analysis/KernelSet/KernelSet.php index 2bdb7f5..230f448 100644 --- a/src/Parser/LALR1/Analysis/KernelSet/KernelSet.php +++ b/src/Parser/LALR1/Analysis/KernelSet/KernelSet.php @@ -9,6 +9,7 @@ * of states by their kernel items. * * @author Jakub Lédl + * @see \Dissect\Parser\LALR1\Analysis\KernelSet\KernelSetTest */ class KernelSet { diff --git a/src/Parser/LALR1/Analysis/State.php b/src/Parser/LALR1/Analysis/State.php index 13a64ca..62e92b8 100644 --- a/src/Parser/LALR1/Analysis/State.php +++ b/src/Parser/LALR1/Analysis/State.php @@ -8,6 +8,7 @@ * A state in a handle-finding FSA. * * @author Jakub Lédl + * @see \Dissect\Parser\LALR1\Analysis\StateTest */ class State { diff --git a/src/Parser/LALR1/Dumper/AutomatonDumper.php b/src/Parser/LALR1/Dumper/AutomatonDumper.php index 30c77e2..2662a00 100644 --- a/src/Parser/LALR1/Dumper/AutomatonDumper.php +++ b/src/Parser/LALR1/Dumper/AutomatonDumper.php @@ -13,6 +13,7 @@ * format used by Graphviz. * * @author Jakub Lédl + * @see \Dissect\Parser\LALR1\Dumper\AutomatonDumperTest */ class AutomatonDumper { diff --git a/src/Parser/LALR1/Dumper/DebugTableDumper.php b/src/Parser/LALR1/Dumper/DebugTableDumper.php index 5116b15..7e49497 100644 --- a/src/Parser/LALR1/Dumper/DebugTableDumper.php +++ b/src/Parser/LALR1/Dumper/DebugTableDumper.php @@ -12,6 +12,7 @@ * parser. * * @author Jakub Lédl + * @see \Dissect\Parser\LALR1\Dumper\DebugTableDumperTest */ class DebugTableDumper implements TableDumper { diff --git a/src/Parser/LALR1/Dumper/ProductionTableDumper.php b/src/Parser/LALR1/Dumper/ProductionTableDumper.php index e678600..c4d288f 100644 --- a/src/Parser/LALR1/Dumper/ProductionTableDumper.php +++ b/src/Parser/LALR1/Dumper/ProductionTableDumper.php @@ -11,6 +11,7 @@ * without any comments. * * @author Jakub Lédl + * @see \Dissect\Parser\LALR1\Dumper\ProductionTableDumperTest */ class ProductionTableDumper implements TableDumper { diff --git a/src/Parser/LALR1/Parser.php b/src/Parser/LALR1/Parser.php index 1852b6b..2d5f71b 100644 --- a/src/Parser/LALR1/Parser.php +++ b/src/Parser/LALR1/Parser.php @@ -14,6 +14,7 @@ * A LR parser. * * @author Jakub Lédl + * @see \Dissect\Parser\LALR1\ParserTest */ class Parser implements P\Parser { diff --git a/src/Parser/Rule.php b/src/Parser/Rule.php index 631243a..6a7fde8 100644 --- a/src/Parser/Rule.php +++ b/src/Parser/Rule.php @@ -8,6 +8,7 @@ * Represents a rule in a context-free grammar. * * @author Jakub Lédl + * @see \Dissect\Parser\RuleTest */ class Rule { diff --git a/tests/Lexer/AbstractLexerTest.php b/tests/Lexer/AbstractLexerTest.php index d0b5819..eb33970 100644 --- a/tests/Lexer/AbstractLexerTest.php +++ b/tests/Lexer/AbstractLexerTest.php @@ -22,20 +22,20 @@ public function lexShouldDelegateToExtractTokenUpdatingTheLineAndOffsetAccording { $stream = $this->lexer->lex("ab\nc"); - $this->assertEquals('a', $stream->getCurrentToken()->getValue()); - $this->assertEquals(1, $stream->getCurrentToken()->getLine()); + $this->assertSame('a', $stream->getCurrentToken()->getValue()); + $this->assertSame(1, $stream->getCurrentToken()->getLine()); $stream->next(); - $this->assertEquals('b', $stream->getCurrentToken()->getValue()); - $this->assertEquals(1, $stream->getCurrentToken()->getLine()); + $this->assertSame('b', $stream->getCurrentToken()->getValue()); + $this->assertSame(1, $stream->getCurrentToken()->getLine()); $stream->next(); - $this->assertEquals("\n", $stream->getCurrentToken()->getValue()); - $this->assertEquals(1, $stream->getCurrentToken()->getLine()); + $this->assertSame("\n", $stream->getCurrentToken()->getValue()); + $this->assertSame(1, $stream->getCurrentToken()->getLine()); $stream->next(); - $this->assertEquals('c', $stream->getCurrentToken()->getValue()); - $this->assertEquals(2, $stream->getCurrentToken()->getLine()); + $this->assertSame('c', $stream->getCurrentToken()->getValue()); + $this->assertSame(2, $stream->getCurrentToken()->getLine()); } #[\PHPUnit\Framework\Attributes\Test] @@ -44,8 +44,8 @@ public function lexShouldAppendAnEofTokenAutomatically(): void $stream = $this->lexer->lex("abc"); $stream->seek(3); - $this->assertEquals(Parser::EOF_TOKEN_TYPE, $stream->getCurrentToken()->getType()); - $this->assertEquals(1, $stream->getCurrentToken()->getLine()); + $this->assertSame(Parser::EOF_TOKEN_TYPE, $stream->getCurrentToken()->getType()); + $this->assertSame(1, $stream->getCurrentToken()->getLine()); } #[\PHPUnit\Framework\Attributes\Test] @@ -55,7 +55,7 @@ public function lexShouldThrowAnExceptionOnAnUnrecognizableToken(): void $this->lexer->lex("abcd"); $this->fail('Expected a RecognitionException.'); } catch (RecognitionException $e) { - $this->assertEquals(1, $e->getSourceLine()); + $this->assertSame(1, $e->getSourceLine()); } } @@ -63,13 +63,13 @@ public function lexShouldThrowAnExceptionOnAnUnrecognizableToken(): void public function lexShouldNormalizeLineEndingsBeforeLexing(): void { $stream = $this->lexer->lex("a\r\nb"); - $this->assertEquals("\n", $stream->get(1)->getValue()); + $this->assertSame("\n", $stream->get(1)->getValue()); } #[\PHPUnit\Framework\Attributes\Test] public function lexShouldSkipTokensIfToldToDoSo(): void { $stream = $this->lexer->lex('aeb'); - $this->assertNotEquals('e', $stream->get(1)->getType()); + $this->assertNotSame('e', $stream->get(1)->getType()); } } diff --git a/tests/Lexer/Recognizer/RegexRecognizerTest.php b/tests/Lexer/Recognizer/RegexRecognizerTest.php index 8517e0f..26072d8 100644 --- a/tests/Lexer/Recognizer/RegexRecognizerTest.php +++ b/tests/Lexer/Recognizer/RegexRecognizerTest.php @@ -16,7 +16,7 @@ public function recognizerShouldMatchAndPassTheValueByReference(): void $this->assertTrue($result); $this->assertNotNull($value); - $this->assertEquals('lorem', $value); + $this->assertSame('lorem', $value); } #[\PHPUnit\Framework\Attributes\Test] diff --git a/tests/Lexer/Recognizer/SimpleRecognizerTest.php b/tests/Lexer/Recognizer/SimpleRecognizerTest.php index 095cb4e..da0212b 100644 --- a/tests/Lexer/Recognizer/SimpleRecognizerTest.php +++ b/tests/Lexer/Recognizer/SimpleRecognizerTest.php @@ -16,7 +16,7 @@ public function recognizerShouldMatchAndPassTheValueByReference(): void $this->assertTrue($result); $this->assertNotNull($value); - $this->assertEquals('class', $value); + $this->assertSame('class', $value); } #[\PHPUnit\Framework\Attributes\Test] diff --git a/tests/Lexer/RegexLexerTest.php b/tests/Lexer/RegexLexerTest.php index 83e8535..c70b6d9 100644 --- a/tests/Lexer/RegexLexerTest.php +++ b/tests/Lexer/RegexLexerTest.php @@ -22,9 +22,9 @@ public function itShouldCallGetTypeToRetrieveTokenType(): void $stream = $this->lexer->lex('5 + 6'); $this->assertCount(4, $stream); - $this->assertEquals('INT', $stream->get(0)->getType()); - $this->assertEquals('+', $stream->get(1)->getType()); - $this->assertEquals(Parser::EOF_TOKEN_TYPE, $stream->get(3)->getType()); + $this->assertSame('INT', $stream->get(0)->getType()); + $this->assertSame('+', $stream->get(1)->getType()); + $this->assertSame(Parser::EOF_TOKEN_TYPE, $stream->get(3)->getType()); } #[\PHPUnit\Framework\Attributes\Test] @@ -32,7 +32,7 @@ public function itShouldTrackLineNumbers(): void { $stream = $this->lexer->lex("5\n+\n\n5"); - $this->assertEquals(2, $stream->get(1)->getLine()); - $this->assertEquals(4, $stream->get(2)->getLine()); + $this->assertSame(2, $stream->get(1)->getLine()); + $this->assertSame(4, $stream->get(2)->getLine()); } } diff --git a/tests/Lexer/SimpleLexerTest.php b/tests/Lexer/SimpleLexerTest.php index 07ef9fd..1f920f4 100644 --- a/tests/Lexer/SimpleLexerTest.php +++ b/tests/Lexer/SimpleLexerTest.php @@ -30,10 +30,10 @@ public function simpleLexerShouldWalkThroughTheRecognizers(): void { $stream = $this->lexer->lex('a (b) c'); - $this->assertEquals(6, $stream->count()); // with EOF - $this->assertEquals('(', $stream->get(1)->getType()); - $this->assertEquals(1, $stream->get(3)->getLine()); - $this->assertEquals('C', $stream->get(4)->getType()); + $this->assertSame(6, $stream->count()); // with EOF + $this->assertSame('(', $stream->get(1)->getType()); + $this->assertSame(1, $stream->get(3)->getLine()); + $this->assertSame('C', $stream->get(4)->getType()); } #[\PHPUnit\Framework\Attributes\Test] @@ -42,7 +42,7 @@ public function simpleLexerShouldSkipSpecifiedTokens(): void $stream = $this->lexer->lex('a (b) c'); foreach ($stream as $token) { - $this->assertNotEquals('WS', $token->getType()); + $this->assertNotSame('WS', $token->getType()); } } @@ -54,7 +54,7 @@ public function simpleLexerShouldReturnTheBestMatch(): void $stream = $this->lexer->lex('class classloremipsum'); - $this->assertEquals('CLASS', $stream->getCurrentToken()->getType()); - $this->assertEquals('WORD', $stream->lookAhead(1)->getType()); + $this->assertSame('CLASS', $stream->getCurrentToken()->getType()); + $this->assertSame('WORD', $stream->lookAhead(1)->getType()); } } diff --git a/tests/Lexer/StatefulLexerTest.php b/tests/Lexer/StatefulLexerTest.php index 7d1cfde..a33798c 100644 --- a/tests/Lexer/StatefulLexerTest.php +++ b/tests/Lexer/StatefulLexerTest.php @@ -52,9 +52,9 @@ public function theStateMechanismShouldCorrectlyPushAndPopStatesFromTheStack(): $stream = $this->lexer->lex('foo bar "long \\" string" baz quux'); $this->assertCount(8, $stream); - $this->assertEquals('STRING_CONTENTS', $stream->get(3)->getType()); - $this->assertEquals('long \\" string', $stream->get(3)->getValue()); - $this->assertEquals('quux', $stream->get(6)->getValue()); + $this->assertSame('STRING_CONTENTS', $stream->get(3)->getType()); + $this->assertSame('long \\" string', $stream->get(3)->getValue()); + $this->assertSame('quux', $stream->get(6)->getValue()); } #[\PHPUnit\Framework\Attributes\Test] @@ -70,6 +70,6 @@ public function defaultActionShouldBeNop(): void $this->lexer->start('root'); $stream = $this->lexer->lex('foo bar'); - $this->assertEquals(3, $stream->count()); + $this->assertSame(3, $stream->count()); } } diff --git a/tests/Lexer/TokenStream/ArrayTokenStreamTest.php b/tests/Lexer/TokenStream/ArrayTokenStreamTest.php index b9ae22b..64c2ba7 100644 --- a/tests/Lexer/TokenStream/ArrayTokenStreamTest.php +++ b/tests/Lexer/TokenStream/ArrayTokenStreamTest.php @@ -26,7 +26,7 @@ protected function setUp(): void #[\PHPUnit\Framework\Attributes\Test] public function theCursorShouldBeOnFirstTokenByDefault(): void { - $this->assertEquals('6', $this->stream->getCurrentToken()->getValue()); + $this->assertSame('6', $this->stream->getCurrentToken()->getValue()); } #[\PHPUnit\Framework\Attributes\Test] @@ -35,13 +35,13 @@ public function getPositionShouldReturnCurrentPosition(): void $this->stream->seek(2); $this->stream->next(); - $this->assertEquals(3, $this->stream->getPosition()); + $this->assertSame(3, $this->stream->getPosition()); } #[\PHPUnit\Framework\Attributes\Test] public function lookAheadShouldReturnTheCorrectToken(): void { - $this->assertEquals('5', $this->stream->lookAhead(2)->getValue()); + $this->assertSame('5', $this->stream->lookAhead(2)->getValue()); } #[\PHPUnit\Framework\Attributes\Test] @@ -54,7 +54,7 @@ public function lookAheadShouldThrowAnExceptionWhenInvalid(): void #[\PHPUnit\Framework\Attributes\Test] public function getShouldReturnATokenByAbsolutePosition(): void { - $this->assertEquals('3', $this->stream->get(4)->getValue()); + $this->assertSame('3', $this->stream->get(4)->getValue()); } #[\PHPUnit\Framework\Attributes\Test] @@ -68,7 +68,7 @@ public function getShouldThrowAnExceptionWhenInvalid(): void public function moveShouldMoveTheCursorByToAnAbsolutePosition(): void { $this->stream->move(2); - $this->assertEquals('5', $this->stream->getCurrentToken()->getValue()); + $this->assertSame('5', $this->stream->getCurrentToken()->getValue()); } #[\PHPUnit\Framework\Attributes\Test] @@ -82,7 +82,7 @@ public function moveShouldThrowAnExceptionWhenInvalid(): void public function seekShouldMoveTheCursorByRelativeOffset(): void { $this->stream->seek(4); - $this->assertEquals('3', $this->stream->getCurrentToken()->getValue()); + $this->assertSame('3', $this->stream->getCurrentToken()->getValue()); } #[\PHPUnit\Framework\Attributes\Test] @@ -96,10 +96,10 @@ public function seekShouldThrowAnExceptionWhenInvalid(): void public function nextShouldMoveTheCursorOneTokenAhead(): void { $this->stream->next(); - $this->assertEquals('PLUS', $this->stream->getCurrentToken()->getType()); + $this->assertSame('PLUS', $this->stream->getCurrentToken()->getType()); $this->stream->next(); - $this->assertEquals('5', $this->stream->getCurrentToken()->getValue()); + $this->assertSame('5', $this->stream->getCurrentToken()->getValue()); } #[\PHPUnit\Framework\Attributes\Test] diff --git a/tests/Parser/GrammarTest.php b/tests/Parser/GrammarTest.php index fef6982..d890f5f 100644 --- a/tests/Parser/GrammarTest.php +++ b/tests/Parser/GrammarTest.php @@ -20,19 +20,19 @@ public function ruleAlternativesShouldHaveTheSameName(): void { $rules = $this->grammar->getRules(); - $this->assertEquals('Foo', $rules[1]->getName()); - $this->assertEquals('Foo', $rules[2]->getName()); + $this->assertSame('Foo', $rules[1]->getName()); + $this->assertSame('Foo', $rules[2]->getName()); } #[\PHPUnit\Framework\Attributes\Test] public function theGrammarShouldBeAugmentedWithAStartRule(): void { - $this->assertEquals( + $this->assertSame( Grammar::START_RULE_NAME, $this->grammar->getStartRule()->getName() ); - $this->assertEquals( + $this->assertSame( array('Foo'), $this->grammar->getStartRule()->getComponents() ); diff --git a/tests/Parser/LALR1/Analysis/AnalyzerTest.php b/tests/Parser/LALR1/Analysis/AnalyzerTest.php index 7055ca3..c48d997 100644 --- a/tests/Parser/LALR1/Analysis/AnalyzerTest.php +++ b/tests/Parser/LALR1/Analysis/AnalyzerTest.php @@ -27,11 +27,11 @@ public function automatonShouldBeCorrectlyBuilt(): void $result = $this->getAnalysisResult($grammar); $table = $result->getAutomaton()->getTransitionTable(); - $this->assertEquals(1, $table[0]['S']); - $this->assertEquals(2, $table[0]['a']); - $this->assertEquals(2, $table[2]['a']); - $this->assertEquals(3, $table[2]['S']); - $this->assertEquals(4, $table[3]['b']); + $this->assertSame(1, $table[0]['S']); + $this->assertSame(2, $table[0]['a']); + $this->assertSame(2, $table[2]['a']); + $this->assertSame(3, $table[2]['S']); + $this->assertSame(4, $table[3]['b']); } #[\PHPUnit\Framework\Attributes\Test] @@ -58,32 +58,32 @@ public function lookaheadShouldBeCorrectlyPumped(): void $automaton = $this->getAnalysisResult($grammar)->getAutomaton(); - $this->assertEquals( + $this->assertSame( array(Parser::EOF_TOKEN_TYPE), $automaton->getState(1)->get(0, 1)->getLookahead() ); - $this->assertEquals( + $this->assertSame( array('b'), $automaton->getState(3)->get(2, 1)->getLookahead() ); - $this->assertEquals( + $this->assertSame( array('d'), $automaton->getState(4)->get(4, 0)->getLookahead() ); - $this->assertEquals( + $this->assertSame( array('d'), $automaton->getState(5)->get(3, 1)->getLookahead() ); - $this->assertEquals( + $this->assertSame( array(Parser::EOF_TOKEN_TYPE), $automaton->getState(7)->get(1, 4)->getLookahead() ); - $this->assertEquals( + $this->assertSame( array(Parser::EOF_TOKEN_TYPE), $automaton->getState(8)->get(5, 1)->getLookahead() ); @@ -103,29 +103,29 @@ public function parseTableShouldBeCorrectlyBuilt(): void $table = $this->getAnalysisResult($grammar)->getParseTable(); // shift(2) - $this->assertEquals(2, $table['action'][0]['a']); + $this->assertSame(2, $table['action'][0]['a']); // reduce(S -> ) - $this->assertEquals(-2, $table['action'][0][Parser::EOF_TOKEN_TYPE]); + $this->assertSame(-2, $table['action'][0][Parser::EOF_TOKEN_TYPE]); // accept - $this->assertEquals(0, $table['action'][1][Parser::EOF_TOKEN_TYPE]); + $this->assertSame(0, $table['action'][1][Parser::EOF_TOKEN_TYPE]); // shift(2) - $this->assertEquals(2, $table['action'][2]['a']); + $this->assertSame(2, $table['action'][2]['a']); // reduce(S -> ) - $this->assertEquals(-2, $table['action'][2]['b']); + $this->assertSame(-2, $table['action'][2]['b']); // shift(4) - $this->assertEquals(4, $table['action'][3]['b']); + $this->assertSame(4, $table['action'][3]['b']); // reduce(S -> a S b) - $this->assertEquals(-1, $table['action'][4]['b']); - $this->assertEquals(-1, $table['action'][4][Parser::EOF_TOKEN_TYPE]); + $this->assertSame(-1, $table['action'][4]['b']); + $this->assertSame(-1, $table['action'][4][Parser::EOF_TOKEN_TYPE]); - $this->assertEquals(1, $table['goto'][0]['S']); - $this->assertEquals(3, $table['goto'][2]['S']); + $this->assertSame(1, $table['goto'][0]['S']); + $this->assertSame(3, $table['goto'][2]['S']); } #[\PHPUnit\Framework\Attributes\Test] @@ -149,10 +149,10 @@ public function unexpectedConflictsShouldThrowAnException(): void $this->getAnalysisResult($grammar); $this->fail('Expected an exception warning of a reduce/reduce conflict.'); } catch(ReduceReduceConflictException $e) { - $this->assertEquals(3, $e->getStateNumber()); - $this->assertEquals('d', $e->getLookahead()); - $this->assertEquals(3, $e->getFirstRule()->getNumber()); - $this->assertEquals(4, $e->getSecondRule()->getNumber()); + $this->assertSame(3, $e->getStateNumber()); + $this->assertSame('d', $e->getLookahead()); + $this->assertSame(3, $e->getFirstRule()->getNumber()); + $this->assertSame(4, $e->getSecondRule()->getNumber()); } } @@ -175,32 +175,32 @@ public function expectedConflictsShouldBeRecorded(): void $conflict = $conflicts[0]; - $this->assertEquals(3, $conflict['state']); - $this->assertEquals('b', $conflict['lookahead']); - $this->assertEquals(2, $conflict['rule']->getNumber()); - $this->assertEquals(Grammar::SHIFT, $conflict['resolution']); + $this->assertSame(3, $conflict['state']); + $this->assertSame('b', $conflict['lookahead']); + $this->assertSame(2, $conflict['rule']->getNumber()); + $this->assertSame(Grammar::SHIFT, $conflict['resolution']); $conflict = $conflicts[1]; - $this->assertEquals(4, $conflict['state']); - $this->assertEquals('b', $conflict['lookahead']); - $this->assertEquals(1, $conflict['rule']->getNumber()); - $this->assertEquals(Grammar::SHIFT, $conflict['resolution']); + $this->assertSame(4, $conflict['state']); + $this->assertSame('b', $conflict['lookahead']); + $this->assertSame(1, $conflict['rule']->getNumber()); + $this->assertSame(Grammar::SHIFT, $conflict['resolution']); $conflict = $conflicts[2]; - $this->assertEquals(4, $conflict['state']); - $this->assertEquals(Parser::EOF_TOKEN_TYPE, $conflict['lookahead']); - $this->assertEquals(1, $conflict['rules'][0]->getNumber()); - $this->assertEquals(2, $conflict['rules'][1]->getNumber()); - $this->assertEquals(Grammar::LONGER_REDUCE, $conflict['resolution']); + $this->assertSame(4, $conflict['state']); + $this->assertSame(Parser::EOF_TOKEN_TYPE, $conflict['lookahead']); + $this->assertSame(1, $conflict['rules'][0]->getNumber()); + $this->assertSame(2, $conflict['rules'][1]->getNumber()); + $this->assertSame(Grammar::LONGER_REDUCE, $conflict['resolution']); $conflict = $conflicts[3]; - $this->assertEquals(4, $conflict['state']); - $this->assertEquals('b', $conflict['lookahead']); - $this->assertEquals(2, $conflict['rule']->getNumber()); - $this->assertEquals(Grammar::SHIFT, $conflict['resolution']); + $this->assertSame(4, $conflict['state']); + $this->assertSame('b', $conflict['lookahead']); + $this->assertSame(2, $conflict['rule']->getNumber()); + $this->assertSame(Grammar::SHIFT, $conflict['resolution']); } protected function getAnalysisResult(Grammar $grammar): AnalysisResult diff --git a/tests/Parser/LALR1/Analysis/AutomatonTest.php b/tests/Parser/LALR1/Analysis/AutomatonTest.php index cfaebd5..7bafd0f 100644 --- a/tests/Parser/LALR1/Analysis/AutomatonTest.php +++ b/tests/Parser/LALR1/Analysis/AutomatonTest.php @@ -23,7 +23,7 @@ public function addingATransitionShouldBeVisibleInTheTransitionTable(): void $this->automaton->addTransition(0, 'a', 1); $table = $this->automaton->getTransitionTable(); - $this->assertEquals(1, $table[0]['a']); + $this->assertSame(1, $table[0]['a']); } #[\PHPUnit\Framework\Attributes\Test] diff --git a/tests/Parser/LALR1/Analysis/ItemTest.php b/tests/Parser/LALR1/Analysis/ItemTest.php index 7faf688..e0021e7 100644 --- a/tests/Parser/LALR1/Analysis/ItemTest.php +++ b/tests/Parser/LALR1/Analysis/ItemTest.php @@ -14,7 +14,7 @@ public function getActiveComponentShouldReturnTheComponentAboutToBeEncountered() { $item = new Item(new Rule(1, 'A', ['a', 'b', 'c']), 1); - $this->assertEquals('b', $item->getActiveComponent()); + $this->assertSame('b', $item->getActiveComponent()); } #[\PHPUnit\Framework\Attributes\Test] @@ -54,7 +54,7 @@ public function itemShouldPumpTheSameLookaheadOnlyOnce(): void $item2->expects($this->once()) ->method('pump') - ->with($this->equalTo('d')); + ->with('d'); $item1->connect($item2); @@ -67,6 +67,6 @@ public function getUnrecognizedComponentsShouldReturnAllComponentAfterTheDottedO { $item = new Item(new Rule(1, 'A', ['a', 'b', 'c']), 1); - $this->assertEquals(['c'], $item->getUnrecognizedComponents()); + $this->assertSame(['c'], $item->getUnrecognizedComponents()); } } diff --git a/tests/Parser/LALR1/Analysis/KernelSet/KernelSetTest.php b/tests/Parser/LALR1/Analysis/KernelSet/KernelSetTest.php index 825ecc3..7399ad1 100644 --- a/tests/Parser/LALR1/Analysis/KernelSet/KernelSetTest.php +++ b/tests/Parser/LALR1/Analysis/KernelSet/KernelSetTest.php @@ -11,7 +11,7 @@ class KernelSetTest extends TestCase #[\PHPUnit\Framework\Attributes\Test] public function kernelsShouldBeProperlyHashedAndOrdered(): void { - $this->assertEquals(array(1, 3, 6, 7), KernelSet::hashKernel(array( + $this->assertSame(array(1, 3, 6, 7), KernelSet::hashKernel(array( array(2, 1), array(1, 0), array(2, 0), @@ -24,19 +24,19 @@ public function insertShouldInsertANewNodeIfNoIdenticalKernelExists(): void { $set = new KernelSet(); - $this->assertEquals(0, $set->insert([ + $this->assertSame(0, $set->insert([ [2, 1], ])); - $this->assertEquals(1, $set->insert([ + $this->assertSame(1, $set->insert([ [2, 2], ])); - $this->assertEquals(2, $set->insert([ + $this->assertSame(2, $set->insert([ [1, 1], ])); - $this->assertEquals(0, $set->insert([ + $this->assertSame(0, $set->insert([ [2, 1], ])); } diff --git a/tests/Parser/LALR1/ParserTest.php b/tests/Parser/LALR1/ParserTest.php index cd5728e..5eaafb8 100644 --- a/tests/Parser/LALR1/ParserTest.php +++ b/tests/Parser/LALR1/ParserTest.php @@ -21,16 +21,16 @@ protected function setUp(): void #[\PHPUnit\Framework\Attributes\Test] public function parserShouldProcessTheTokenStreamAndUseGrammarCallbacksForReductions(): void { - $this->assertEquals(-2, $this->parser->parse($this->lexer->lex( + $this->assertSame(-2, $this->parser->parse($this->lexer->lex( '-1 - 1'))); - $this->assertEquals(11664, $this->parser->parse($this->lexer->lex( + $this->assertSame(11664, $this->parser->parse($this->lexer->lex( '6 ** (1 + 1) ** 2 * (5 + 4)'))); - $this->assertEquals(-4, $this->parser->parse($this->lexer->lex( + $this->assertSame(-4, $this->parser->parse($this->lexer->lex( '3 - 5 - 2'))); - $this->assertEquals(262144, $this->parser->parse($this->lexer->lex( + $this->assertSame(262144, $this->parser->parse($this->lexer->lex( '4 ** 3 ** 2'))); } @@ -41,9 +41,9 @@ public function parserShouldThrowAnExceptionOnInvalidInput(): void $this->parser->parse($this->lexer->lex('6 ** 5 3')); $this->fail('Expected an UnexpectedTokenException.'); } catch (UnexpectedTokenException $e) { - $this->assertEquals('INT', $e->getToken()->getType()); - $this->assertEquals(array('$eof', '+', '-', '*', '/', '**', ')'), $e->getExpected()); - $this->assertEquals(<<assertSame('INT', $e->getToken()->getType()); + $this->assertSame(array('$eof', '+', '-', '*', '/', '**', ')'), $e->getExpected()); + $this->assertSame(<<assertEquals('y', $r->getComponent(1)); + $this->assertSame('y', $r->getComponent(1)); $this->assertNull($r->getComponent(2)); } }