Documentation

GenerateDiffTest extends TestCase
in package

FinalYes

Tests for diff generation.

Note: these tests are specifically about the Fixer::generateDiff() method and do not test running the fixer itself, nor generating a diff based on a fixer run.

Tags
covers

Table of Contents

Properties

$phpcsFile  : LocalFile
A \PHP_CodeSniffer\Files\File object to compare the files against.

Methods

dataGenerateDiff()  : array<string, array<string, string>>
Data provider.
initializeFile()  : void
Initialize an \PHP_CodeSniffer\Files\File object with code.
testGenerateDiff()  : void
Test generating a diff between a PHPCS File object and a file on disk.
testGenerateDiffColoured()  : void
Test generating a diff between a PHPCS File object and a file on disk and colourizing the output.
testGenerateDiffDifferentLineEndings()  : void
Test generating a diff between a PHPCS File object using *nix line endings and a file on disk using Windows line endings.
testGenerateDiffNoFile()  : void
Test generating a diff on the file object itself.

Properties

Methods

dataGenerateDiff()

Data provider.

public static dataGenerateDiff() : array<string, array<string, string>>
Tags
see
testGenerateDiff()
Return values
array<string, array<string, string>>

initializeFile()

Initialize an \PHP_CodeSniffer\Files\File object with code.

public static initializeFile() : void

Things to take note of in the code snippet used for these tests:

  • Line endings are \n.
  • Tab indent.
  • Trailing whitespace.

Also note that the Config object is deliberately created without a tabWidth setting to prevent doing tab replacement when parsing the file. This is to allow for testing a diff with tabs vs spaces (which wouldn't yield a diff if tabs had already been replaced).

Tags
beforeClass

testGenerateDiff()

Test generating a diff between a PHPCS File object and a file on disk.

public testGenerateDiff(string $filePath) : void
Parameters
$filePath : string

The path to the file to compare the File object against.

Tags
dataProvider

dataGenerateDiff

testGenerateDiffColoured()

Test generating a diff between a PHPCS File object and a file on disk and colourizing the output.

public testGenerateDiffColoured() : void

testGenerateDiffDifferentLineEndings()

Test generating a diff between a PHPCS File object using *nix line endings and a file on disk using Windows line endings.

public testGenerateDiffDifferentLineEndings() : void

The point of this test is to verify that all lines are marked as having a difference. The actual lines endings used in the diff shown to the end-user are not relevant for this test. As the "diff" command is finicky with what type of line endings are used when the only difference on a line is the line ending, the test normalizes the line endings of the received diff before testing it.

testGenerateDiffNoFile()

Test generating a diff on the file object itself.

public testGenerateDiffNoFile() : void

        
On this page

Search results