Skip to content

Commit 562e47c

Browse files
authored
Tests: use strict assertions (sirbrillig#247)
`assertEquals()` comes down to a loose type `==` comparison, while `assertSame()` does a strict type `===` comparison, so if at all possible, one should always use `assertSame()` instead of `assertEquals()`. Co-authored-by: jrfnl <jrfnl@users.noreply.github.com>
1 parent 310ed23 commit 562e47c

11 files changed

+110
-110
lines changed

Tests/VariableAnalysisSniff/ArrayAssignmentShortcutTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function testArrayAssignmentReportsCorrectLines() {
1616
28,
1717
29,
1818
];
19-
$this->assertEquals($expectedWarnings, $lines);
19+
$this->assertSame($expectedWarnings, $lines);
2020
}
2121

2222
public function testArrayAssignmentHasCorrectSniffCodes() {
@@ -25,9 +25,9 @@ public function testArrayAssignmentHasCorrectSniffCodes() {
2525
$phpcsFile->process();
2626

2727
$warnings = $phpcsFile->getWarnings();
28-
$this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable', $warnings[21][5][0]['source']);
29-
$this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable', $warnings[27][5][0]['source']);
30-
$this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable', $warnings[28][5][0]['source']);
31-
$this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable', $warnings[29][10][0]['source']);
28+
$this->assertSame('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable', $warnings[21][5][0]['source']);
29+
$this->assertSame('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable', $warnings[27][5][0]['source']);
30+
$this->assertSame('VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable', $warnings[28][5][0]['source']);
31+
$this->assertSame('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable', $warnings[29][10][0]['source']);
3232
}
3333
}

Tests/VariableAnalysisSniff/ArrowFunctionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testArrowFunctions() {
2727
67,
2828
71,
2929
];
30-
$this->assertEquals($expectedWarnings, $lines);
30+
$this->assertSame($expectedWarnings, $lines);
3131
}
3232

3333
public function testArrowFunctionsWithoutUnusedBeforeUsed() {
@@ -55,6 +55,6 @@ public function testArrowFunctionsWithoutUnusedBeforeUsed() {
5555
67,
5656
71,
5757
];
58-
$this->assertEquals($expectedWarnings, $lines);
58+
$this->assertSame($expectedWarnings, $lines);
5959
}
6060
}

Tests/VariableAnalysisSniff/ClosingPhpTagsTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ public function testVariableWarningsWhenClosingTagsAreUsed() {
1515
13,
1616
16,
1717
];
18-
$this->assertEquals($expectedWarnings, $lines);
18+
$this->assertSame($expectedWarnings, $lines);
1919
}
2020

2121
public function testVariableWarningsHaveCorrectSniffCodesWhenClosingTagsAreUsed() {
2222
$fixtureFile = $this->getFixture('ClosingPhpTagsFixture.php');
2323
$phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile);
2424
$phpcsFile->process();
2525
$warnings = $phpcsFile->getWarnings();
26-
$this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable', $warnings[6][1][0]['source']);
27-
$this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable', $warnings[8][6][0]['source']);
28-
$this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable', $warnings[13][1][0]['source']);
29-
$this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable', $warnings[16][6][0]['source']);
26+
$this->assertSame('VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable', $warnings[6][1][0]['source']);
27+
$this->assertSame('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable', $warnings[8][6][0]['source']);
28+
$this->assertSame('VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable', $warnings[13][1][0]['source']);
29+
$this->assertSame('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable', $warnings[16][6][0]['source']);
3030
}
3131
}

Tests/VariableAnalysisSniff/GlobalScopeTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function testGlobalScopeWarnings() {
2020
10,
2121
13,
2222
];
23-
$this->assertEquals($expectedErrors, $lines);
23+
$this->assertSame($expectedErrors, $lines);
2424
}
2525

2626
public function testGlobalScopeWarningsWithAllowUndefinedVariablesInFileScope() {
@@ -38,7 +38,7 @@ public function testGlobalScopeWarningsWithAllowUndefinedVariablesInFileScope()
3838
10,
3939
13,
4040
];
41-
$this->assertEquals($expectedErrors, $lines);
41+
$this->assertSame($expectedErrors, $lines);
4242
}
4343

4444
public function testGlobalScopeWarningsWithAllowUnusedVariablesInFileScope() {
@@ -55,6 +55,6 @@ public function testGlobalScopeWarningsWithAllowUnusedVariablesInFileScope() {
5555
7,
5656
10,
5757
];
58-
$this->assertEquals($expectedErrors, $lines);
58+
$this->assertSame($expectedErrors, $lines);
5959
}
6060
}

Tests/VariableAnalysisSniff/IfConditionTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testIfConditionWarnings() {
3333
176,
3434
179,
3535
];
36-
$this->assertEquals($expectedWarnings, $lines);
36+
$this->assertSame($expectedWarnings, $lines);
3737
}
3838

3939
public function testIfConditionWarningsWithValidUndefinedVariableNames() {
@@ -64,7 +64,7 @@ public function testIfConditionWarningsWithValidUndefinedVariableNames() {
6464
176,
6565
179,
6666
];
67-
$this->assertEquals($expectedWarnings, $lines);
67+
$this->assertSame($expectedWarnings, $lines);
6868
}
6969

7070
public function testInlineIfConditionWarnings() {
@@ -96,7 +96,7 @@ public function testInlineIfConditionWarnings() {
9696
152,
9797
154,
9898
];
99-
$this->assertEquals($expectedWarnings, $lines);
99+
$this->assertSame($expectedWarnings, $lines);
100100
}
101101

102102
public function testInlineIfConditionWarningsWithValidUndefinedVariableNames() {
@@ -127,6 +127,6 @@ public function testInlineIfConditionWarningsWithValidUndefinedVariableNames() {
127127
152,
128128
154,
129129
];
130-
$this->assertEquals($expectedWarnings, $lines);
130+
$this->assertSame($expectedWarnings, $lines);
131131
}
132132
}

Tests/VariableAnalysisSniff/IssetTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ public function testIssetVariableUse() {
1313
4,
1414
23, // ideally this should not be a warning, but will be because it is difficult to know: https://github.com/sirbrillig/phpcs-variable-analysis/issues/202#issuecomment-688507314
1515
];
16-
$this->assertEquals($expectedWarnings, $lines);
16+
$this->assertSame($expectedWarnings, $lines);
1717
}
1818
}

Tests/VariableAnalysisSniff/UnsetTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function testUnsetReportsUndefinedVariables() {
1414
6,
1515
11,
1616
];
17-
$this->assertEquals($expectedWarnings, $lines);
17+
$this->assertSame($expectedWarnings, $lines);
1818
}
1919

2020
public function testUnsetHasCorrectSniffCodes() {
@@ -23,7 +23,7 @@ public function testUnsetHasCorrectSniffCodes() {
2323
$phpcsFile->process();
2424

2525
$warnings = $phpcsFile->getWarnings();
26-
$this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedUnsetVariable', $warnings[6][7][0]['source']);
27-
$this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedUnsetVariable', $warnings[11][9][0]['source']);
26+
$this->assertSame('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedUnsetVariable', $warnings[6][7][0]['source']);
27+
$this->assertSame('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedUnsetVariable', $warnings[11][9][0]['source']);
2828
}
2929
}

Tests/VariableAnalysisSniff/UnusedFollowedByRequireTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testUnusedFollowedByRequireWarnsByDefault() {
2323
21,
2424
22,
2525
];
26-
$this->assertEquals($expectedWarnings, $lines);
26+
$this->assertSame($expectedWarnings, $lines);
2727
}
2828

2929
public function testUnusedFollowedByRequireDoesNotWarnWhenSet() {
@@ -42,7 +42,7 @@ public function testUnusedFollowedByRequireDoesNotWarnWhenSet() {
4242
16,
4343
22,
4444
];
45-
$this->assertEquals($expectedWarnings, $lines);
45+
$this->assertSame($expectedWarnings, $lines);
4646
}
4747

4848
public function testUnusedFollowedByRequireDoesNotBreakOtherThingsWhenSet() {
@@ -69,6 +69,6 @@ public function testUnusedFollowedByRequireDoesNotBreakOtherThingsWhenSet() {
6969
18,
7070
19,
7171
];
72-
$this->assertEquals($expectedWarnings, $lines);
72+
$this->assertSame($expectedWarnings, $lines);
7373
}
7474
}

0 commit comments

Comments
 (0)