Skip to content

Commit b19075b

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 795136c commit b19075b

16 files changed

+317
-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: 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.
Lines changed: 7 additions & 0 deletions
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+
}
Lines changed: 9 additions & 0 deletions
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) {
Lines changed: 7 additions & 0 deletions
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+
}
Lines changed: 9 additions & 0 deletions
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+
}

0 commit comments

Comments
 (0)