Php_codesniffer: Sniff unit tests - 'diff' not available in environment

Created on 26 Jul 2017  路  3Comments  路  Source: squizlabs/PHP_CodeSniffer

I tried to run all sniff unit tests using the PHP_CodeSniffer\Tests\Standards\AllSniffs class on a windows machine with phpcs 3.0.1; while the tests are running without problems, the log will be spammend with:

'diff' is not recognized as an internal or external command,
operable program or batch file.

A similar problem was mentioned here: #458
But since i am running the unit tests it seems it is not possible to use the --no-patch option.
Installing cygwin would be a hassle in my current environment.

Is there another way to suppress the message or something else i can do? ( I do not need/use phpcbf )

Most helpful comment

Just to explain why the tests do this: the unit tests for each sniff also run the fixers for the sniff over a test file, and then diff the output to an expected "fixed" test file. If the file contents do not match, then the sniff might be finding errors correctly but not fixing them.

All 3 comments

@ht-bs I've seen this quite often myself with Windows. There is a quite simple solution - presuming you use git and have it installed on your system -.
Git ships by default with the diff executable (and lots of others too). If you add the C:\Program Files (x86)\Git\usr\bin directory to your Windows PATH environment variable, the error will go away (presuming a standard 32 bit install, adjust the path if you've installed a different version/in a different directory).

Hope that helps.

Thank you, that did the trick!

Just to explain why the tests do this: the unit tests for each sniff also run the fixers for the sniff over a test file, and then diff the output to an expected "fixed" test file. If the file contents do not match, then the sniff might be finding errors correctly but not fixing them.

Was this page helpful?
0 / 5 - 0 ratings