Skip to content

Commit 10e6502

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 45c61f5 commit 10e6502

24 files changed

+399
-0
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
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
Lines changed: 10 additions & 0 deletions
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+
-
Lines changed: 11 additions & 0 deletions
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+
Lines changed: 9 additions & 0 deletions
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;
Lines changed: 10 additions & 0 deletions
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+
}
Lines changed: 8 additions & 0 deletions
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) {
Lines changed: 6 additions & 0 deletions
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+
}
Lines changed: 8 additions & 0 deletions
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+
}
Lines changed: 8 additions & 0 deletions
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.

0 commit comments

Comments
 (0)