Php_codesniffer: Unable to find LineLengthSniff.php when running unit tests

Created on 14 Apr 2020  路  6Comments  路  Source: squizlabs/PHP_CodeSniffer

Using version 3.5.4, when we run unit tests for our custom sniffs, we hit this error on some internal unit tests.

1) PHP_CodeSniffer\Tests\Core\Ruleset\RuleInclusionTest::testHasSniffCodes
PHP_CodeSniffer\Exceptions\RuntimeException: Referenced sniff "./src/Standards/Generic/Sniffs/Files/LineLengthSniff.php" does not exist in /home/travis/build/cakephp/cakephp-codesniffer/vendor/squizlabs/php_codesniffer/src/Ruleset.php:830

I don't see any way to disabled the internal unit tests when including our custom sniff tests.

All 6 comments

@othercorey What command do you use to run the unit tests ? (including the arguments)

I'd expect it to be something along the lines of:

phpunit --filter CakePHP /path/to/PHP_CodeSniffer/tests/AllTests.php

Is that correct ?

Also, you may want to try setting the PHPCS_IGNORE_TESTS environment variable either from your own test bootstrap or via phpunit.xml.

See #1146 for more information.

Hope that helps.

We run phpunit, but with a phpunit.xml file:

<phpunit
    bootstrap="vendor/squizlabs/php_codesniffer/tests/bootstrap.php"

    <testsuites>
        <testsuite name="CakePHP-CodeSniffer">
            <file>vendor/squizlabs/php_codesniffer/tests/AllTests.php</file>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist>
            <directory suffix=".php">CakePHP/Sniffs/</directory>
        </whitelist>
    </filter>

@othercorey The PHPUnit filter -> whitelist directives in the phpunit.xml file are only for filtering the code which is considered for calculating code coverage. This directive doesn't limit which tests are being run.

For that, you'd still need to use --filter CakePHP on the command-line.

In other words, the <filter> in the PHPUnit config file is unrelated to the --filter CLI argument and they have different functions and different effects.

Thanks! We will try it out!

Yea, the filter is for codecoverage, but wanted to show you what we used to help answer your question.

I think this works for us!

@jrfnl Thanks a lot for helping resolve this

Was this page helpful?
0 / 5 - 0 ratings