Skip to content

Commit 22cc768

Browse files
committed
Fixer::generateDiff(): add tests
These tests test the functionality and document the behaviour of the `Fixer::generateDiff()` method, with a particular focus on (trailing) whitespace handling in the diff as this was noted in the method itself as a potential point of failure. Related to 146
1 parent 3b2ab17 commit 22cc768

24 files changed

+399
-0
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ phpunit.xml.dist export-ignore
2121
*WinTest.inc text eol=crlf
2222
*WinTest.php text eol=crlf
2323
src/Standards/Generic/Tests/Files/LineEndingsUnitTest*.inc text eol=crlf
24+
tests/Core/Fixer/Fixtures/GenerateDiffTest-WindowsLineEndings.inc text eol=crlf
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--- tests/Core/Fixer/Fixtures/GenerateDiffTest-BlankLinesAtEnd.inc
2+
+++ PHP_CodeSniffer
3+
@@ -5,7 +5,3 @@
4+
if ($var) {
5+
echo 'This line is tab indented';
6+
}
7+
-
8+
-
9+
-
10+
-
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
// Comment with 2 spaces trailing whitespace.
3+
$var = FALSE;
4+
5+
if ($var) {
6+
echo 'This line is tab indented';
7+
}
8+
9+
10+
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--- tests/Core/Fixer/Fixtures/GenerateDiffTest-BlankLinesAtStart.inc
2+
+++ PHP_CodeSniffer
3+
@@ -1,6 +1,3 @@
4+
-
5+
-
6+
-
7+
<?php
8+
// Comment with 2 spaces trailing whitespace.
9+
$var = FALSE;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
3+
4+
<?php
5+
// Comment with 2 spaces trailing whitespace.
6+
$var = FALSE;
7+
8+
if ($var) {
9+
echo 'This line is tab indented';
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--- tests/Core/Fixer/Fixtures/GenerateDiffTest-LineAdded.inc
2+
+++ PHP_CodeSniffer
3+
@@ -1,4 +1,5 @@
4+
<?php
5+
+// Comment with 2 spaces trailing whitespace.
6+
$var = FALSE;
7+
8+
if ($var) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
$var = FALSE;
3+
4+
if ($var) {
5+
echo 'This line is tab indented';
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--- tests/Core/Fixer/Fixtures/GenerateDiffTest-LineRemoved.inc
2+
+++ PHP_CodeSniffer
3+
@@ -4,5 +4,4 @@
4+
5+
if ($var) {
6+
echo 'This line is tab indented';
7+
- echo 'And this line is not';
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
// Comment with 2 spaces trailing whitespace.
3+
$var = FALSE;
4+
5+
if ($var) {
6+
echo 'This line is tab indented';
7+
echo 'And this line is not';
8+
}

tests/Core/Fixer/Fixtures/GenerateDiffTest-NoDiff.diff

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
// Comment with 2 spaces trailing whitespace.
3+
$var = FALSE;
4+
5+
if ($var) {
6+
echo 'This line is tab indented';
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--- tests/Core/Fixer/Fixtures/GenerateDiffTest-NoTrailingWhitespace.inc
2+
+++ PHP_CodeSniffer
3+
@@ -1,5 +1,5 @@
4+
<?php
5+
-// Comment with 2 spaces trailing whitespace.
6+
+// Comment with 2 spaces trailing whitespace.
7+
$var = FALSE;
8+
9+
if ($var) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
// Comment with 2 spaces trailing whitespace.
3+
$var = FALSE;
4+
5+
if ($var) {
6+
echo 'This line is tab indented';
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--- tests/Core/Fixer/Fixtures/GenerateDiffTest-TabsToSpaces.inc
2+
+++ PHP_CodeSniffer
3+
@@ -3,5 +3,5 @@
4+
$var = FALSE;
5+
6+
if ($var) {
7+
- echo 'This line is tab indented';
8+
+ echo 'This line is tab indented';
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
// Comment with 2 spaces trailing whitespace.
3+
$var = FALSE;
4+
5+
if ($var) {
6+
echo 'This line is tab indented';
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--- tests/Core/Fixer/Fixtures/GenerateDiffTest-VarNameChanged.inc
2+
+++ PHP_CodeSniffer
3+
@@ -1,7 +1,7 @@
4+
<?php
5+
// Comment with 2 spaces trailing whitespace.
6+
-$rav = FALSE;
7+
+$var = FALSE;
8+
9+
-if ($rav) {
10+
+if ($var) {
11+
echo 'This line is tab indented';
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
// Comment with 2 spaces trailing whitespace.
3+
$rav = FALSE;
4+
5+
if ($rav) {
6+
echo 'This line is tab indented';
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--- tests/Core/Fixer/Fixtures/GenerateDiffTest-WhiteSpaceAtEnd.inc
2+
+++ PHP_CodeSniffer
3+
@@ -4,4 +4,4 @@
4+
5+
if ($var) {
6+
echo 'This line is tab indented';
7+
-}
8+
+}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
// Comment with 2 spaces trailing whitespace.
3+
$var = FALSE;
4+
5+
if ($var) {
6+
echo 'This line is tab indented';
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--- tests/Core/Fixer/Fixtures/GenerateDiffTest-WhiteSpaceAtStart.inc
2+
+++ PHP_CodeSniffer
3+
@@ -1,4 +1,4 @@
4+
- <?php
5+
+<?php
6+
// Comment with 2 spaces trailing whitespace.
7+
$var = FALSE;
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
// Comment with 2 spaces trailing whitespace.
3+
$var = FALSE;
4+
5+
if ($var) {
6+
echo 'This line is tab indented';
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
// Comment with 2 spaces trailing whitespace.
3+
$var = FALSE;
4+
5+
if ($var) {
6+
echo 'This line is tab indented';
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
// Comment with 2 spaces trailing whitespace.
3+
$var = FALSE;
4+
5+
if ($var) {
6+
echo 'This line is tab indented';
7+
}

0 commit comments

Comments
 (0)