Skip to content

Using assertSame to make assert equals restricted #420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/BacktraceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function test_backtrace_in_failed_complex_matching() : void
// Uncomment when backtrace logic changes, run tests and then commit again.
\file_put_contents(__DIR__ . '/BacktraceTest/failed_complex_matching_expected_trace.txt', (string) $this->matcher->backtrace());

$this->assertEquals(
$this->assertSame(
\file_get_contents(__DIR__ . '/BacktraceTest/failed_complex_matching_expected_trace.txt'),
(string) $this->matcher->backtrace()
);
Expand Down Expand Up @@ -143,7 +143,7 @@ public function test_backtrace_in_succeed_complex_matching() : void
// Uncomment when backtrace logic changes, run tests and then commit again.
\file_put_contents(__DIR__ . '/BacktraceTest/succeed_complex_matching_expected_trace.txt', (string) $this->matcher->backtrace());

$this->assertEquals(
$this->assertSame(
\file_get_contents(__DIR__ . '/BacktraceTest/succeed_complex_matching_expected_trace.txt'),
(string) $this->matcher->backtrace()
);
Expand Down
36 changes: 18 additions & 18 deletions tests/LexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public function test_string_values(string $value) : void
$lexer = new Lexer();
$lexer->setInput($value);
$lexer->moveNext();
$this->assertEquals($lexer->lookahead['type'], Lexer::T_STRING);
$this->assertEquals($lexer->lookahead['value'], \trim(\trim($value, "'"), '"'));
$this->assertSame($lexer->lookahead['type'], Lexer::T_STRING);
$this->assertSame($lexer->lookahead['value'], \trim(\trim($value, "'"), '"'));
}

/**
Expand All @@ -98,8 +98,8 @@ public function test_number_values($value, $expectedValue) : void
$lexer = new Lexer();
$lexer->setInput($value);
$lexer->moveNext();
$this->assertEquals($lexer->lookahead['type'], Lexer::T_NUMBER);
$this->assertEquals($expectedValue, $lexer->lookahead['value']);
$this->assertSame($lexer->lookahead['type'], Lexer::T_NUMBER);
$this->assertSame($expectedValue, $lexer->lookahead['value']);
}

/**
Expand All @@ -110,8 +110,8 @@ public function test_boolean_values($value, $expectedValue) : void
$lexer = new Lexer();
$lexer->setInput($value);
$lexer->moveNext();
$this->assertEquals($lexer->lookahead['type'], Lexer::T_BOOLEAN);
$this->assertEquals($lexer->lookahead['value'], $expectedValue);
$this->assertSame($lexer->lookahead['type'], Lexer::T_BOOLEAN);
$this->assertSame($lexer->lookahead['value'], $expectedValue);
}

/**
Expand All @@ -122,7 +122,7 @@ public function test_null_values($value) : void
$lexer = new Lexer();
$lexer->setInput($value);
$lexer->moveNext();
$this->assertEquals($lexer->lookahead['type'], Lexer::T_NULL);
$this->assertSame($lexer->lookahead['type'], Lexer::T_NULL);
$this->assertNull($lexer->lookahead['value']);
}

Expand All @@ -134,47 +134,47 @@ public function test_non_token_values($value) : void
$lexer = new Lexer();
$lexer->setInput($value);
$lexer->moveNext();
$this->assertEquals($lexer->lookahead['type'], Lexer::T_NONE);
$this->assertSame($lexer->lookahead['type'], Lexer::T_NONE);
}

public function test_close_parenthesis() : void
{
$lexer = new Lexer();
$lexer->setInput(')');
$lexer->moveNext();
$this->assertEquals($lexer->lookahead['type'], Lexer::T_CLOSE_PARENTHESIS);
$this->assertSame($lexer->lookahead['type'], Lexer::T_CLOSE_PARENTHESIS);
}

public function test_close_open_brace() : void
{
$lexer = new Lexer();
$lexer->setInput('{');
$lexer->moveNext();
$this->assertEquals($lexer->lookahead['type'], Lexer::T_OPEN_CURLY_BRACE);
$this->assertSame($lexer->lookahead['type'], Lexer::T_OPEN_CURLY_BRACE);
}

public function test_close_curly_brace() : void
{
$lexer = new Lexer();
$lexer->setInput('}');
$lexer->moveNext();
$this->assertEquals($lexer->lookahead['type'], Lexer::T_CLOSE_CURLY_BRACE);
$this->assertSame($lexer->lookahead['type'], Lexer::T_CLOSE_CURLY_BRACE);
}

public function test_colon() : void
{
$lexer = new Lexer();
$lexer->setInput(':');
$lexer->moveNext();
$this->assertEquals($lexer->lookahead['type'], Lexer::T_COLON);
$this->assertSame($lexer->lookahead['type'], Lexer::T_COLON);
}

public function test_comma() : void
{
$lexer = new Lexer();
$lexer->setInput(',');
$lexer->moveNext();
$this->assertEquals($lexer->lookahead['type'], Lexer::T_COMMA);
$this->assertSame($lexer->lookahead['type'], Lexer::T_COMMA);
}

/**
Expand All @@ -185,8 +185,8 @@ public function test_type_pattern($value) : void
$lexer = new Lexer();
$lexer->setInput($value);
$lexer->moveNext();
$this->assertEquals($lexer->lookahead['type'], Lexer::T_TYPE_PATTERN);
$this->assertEquals($lexer->lookahead['value'], \trim($value, '@'));
$this->assertSame($lexer->lookahead['type'], Lexer::T_TYPE_PATTERN);
$this->assertSame($lexer->lookahead['value'], \trim($value, '@'));
}

/**
Expand All @@ -197,8 +197,8 @@ public function test_expander_name($value, $expectedTokenValue) : void
$lexer = new Lexer();
$lexer->setInput($value);
$lexer->moveNext();
$this->assertEquals($lexer->lookahead['type'], Lexer::T_EXPANDER_NAME);
$this->assertEquals($lexer->lookahead['value'], $expectedTokenValue);
$this->assertSame($lexer->lookahead['type'], Lexer::T_EXPANDER_NAME);
$this->assertSame($lexer->lookahead['value'], $expectedTokenValue);
}

public function test_ignore_whitespaces_between_parenthesis() : void
Expand All @@ -207,7 +207,7 @@ public function test_ignore_whitespaces_between_parenthesis() : void
$lexer = new Lexer();
$lexer->setInput("@[email protected]( 'arg1', 2 ,'arg3',4)");

$this->assertEquals($expectedTokens, $this->collectTokens($lexer));
$this->assertSame($expectedTokens, $this->collectTokens($lexer));
}

/**
Expand Down
28 changes: 14 additions & 14 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,32 +77,32 @@ public function test_simple_pattern_without_expanders() : void
{
$pattern = '@type@';

$this->assertEquals('type', $this->parser->getAST($pattern)->getType());
$this->assertSame('type', (string) $this->parser->getAST($pattern)->getType());
$this->assertFalse($this->parser->getAST($pattern)->hasExpanders());
}

public function test_single_expander_without_args() : void
{
$pattern = '@[email protected]()';

$this->assertEquals('type', $this->parser->getAST($pattern)->getType());
$this->assertSame('type', (string) $this->parser->getAST($pattern)->getType());
$expanders = $this->parser->getAST($pattern)->getExpanders();
$this->assertEquals('expander', $expanders[0]->getName());
$this->assertSame('expander', $expanders[0]->getName());
$this->assertFalse($expanders[0]->hasArguments());
}

public function test_single_expander_with_arguments() : void
{
$pattern = "@[email protected]('arg1', 2, 2.24, \"arg3\")";
$this->assertEquals('type', $this->parser->getAST($pattern)->getType());
$this->assertSame('type', (string) $this->parser->getAST($pattern)->getType());
$expanders = $this->parser->getAST($pattern)->getExpanders();
$expectedArguments = [
'arg1',
2,
2.24,
'arg3',
];
$this->assertEquals($expectedArguments, $expanders[0]->getArguments());
$this->assertSame($expectedArguments, $expanders[0]->getArguments());
}

public function test_many_expanders() : void
Expand All @@ -115,14 +115,14 @@ public function test_many_expanders() : void
];

$expanders = $this->parser->getAST($pattern)->getExpanders();
$this->assertEquals('type', $this->parser->getAST($pattern)->getType());
$this->assertEquals('expander', $expanders[0]->getName());
$this->assertEquals('expander1', $expanders[1]->getName());
$this->assertEquals('expander', $expanders[2]->getName());

$this->assertEquals($expanderArguments[0], $expanders[0]->getArguments());
$this->assertEquals($expanderArguments[1], $expanders[1]->getArguments());
$this->assertEquals($expanderArguments[2], $expanders[2]->getArguments());
$this->assertSame('type', (string) $this->parser->getAST($pattern)->getType());
$this->assertSame('expander', $expanders[0]->getName());
$this->assertSame('expander1', $expanders[1]->getName());
$this->assertSame('expander', $expanders[2]->getName());

$this->assertSame($expanderArguments[0], $expanders[0]->getArguments());
$this->assertSame($expanderArguments[1], $expanders[1]->getArguments());
$this->assertSame($expanderArguments[2], $expanders[2]->getArguments());
}

/**
Expand All @@ -131,7 +131,7 @@ public function test_many_expanders() : void
public function test_single_array_argument_with_string_key_value($pattern, $expectedArgument) : void
{
$expanders = $this->parser->getAST($pattern)->getExpanders();
$this->assertEquals($expectedArgument, $expanders[0]->getArguments());
$this->assertSame($expectedArgument, $expanders[0]->getArguments());
}

public function test_expanders_that_takes_other_expanders_as_arguments() : void
Expand Down