Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class 'PHP_CodeSniffer\Tests\FileList' not found #3021

Closed
gz-ang opened this issue Jul 17, 2020 · 3 comments
Closed

Class 'PHP_CodeSniffer\Tests\FileList' not found #3021

gz-ang opened this issue Jul 17, 2020 · 3 comments

Comments

@gz-ang
Copy link

gz-ang commented Jul 17, 2020

I'm testing my code using phpcs and wpcs on Travis CI and I received this error when the build failed.

Fatal error: Uncaught Error: Class 'PHP_CodeSniffer\Tests\FileList' not found in /home/travis/build/nepmisdev/partners_arissto/vendor/squizlabs/php_codesniffer/tests/Core/AllTests.php:42

Stack trace:

#0 /home/travis/build/nepmisdev/partners_arissto/vendor/squizlabs/php_codesniffer/tests/AllTests.php(59): PHP_CodeSniffer\Tests\Core\AllTests::suite()

#1 [internal function]: PHP_CodeSniffer\Tests\PHP_CodeSniffer_AllTests::suite('PHP_CodeSniffer...')

#2 /home/travis/build/nepmisdev/partners_arissto/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php(125): ReflectionMethod->invoke(NULL, 'PHP_CodeSniffer...')

#3 /home/travis/build/nepmisdev/partners_arissto/vendor/phpunit/phpunit/src/TextUI/Command.php(183): PHPUnit\Runner\BaseTestRunner->getTest('./vendor/squizl...', '/home/travis/bu...', Array)

#4 /home/travis/build/nepmisdev/partners_arissto/vendor/phpunit/phpunit/src/TextUI/Command.php(162): PHPUnit\TextUI\Command->run(Array, true)

#5 /home/travis/build/nepmisdev/partners_arissto/vendor/phpunit/phpunit/phpunit(61): PHPUnit in /home/travis/build/nepmisdev/partners_arissto/vendor/squizlabs/php_codesniffer/tests/Core/AllTests.php on line 42

What I understand from the error is that the class 'PHP_CodeSniffer\Tests\FileList' can't be loaded due to the 'T' in the 'Test' directory being capitalized while the directory should be 'test', am I interpreting this correctly?

This is the .travis.yml for my project

dist: trusty

cache:
apt: true
directories:
# Cache directory for older Composer versions.
- $HOME/.composer/cache/files
# Cache directory for more recent Composer versions.
- $HOME/.cache/composer/files

language: php

php:
- 7.1
- 7.2
- 7.3
- 7.4
- "nightly"

env:
# PHPCS master.
- PHPCS_BRANCH="dev-master" LINT=1
# Lowest supported release in the 3.x series with which WPCS is compatible.
- PHPCS_BRANCH="3.5.0"

# Define the stages used.
# For non-PRs, only the sniff, ruleset and quicktest stages are run.
# For pull requests and merges, the full script is run (skipping quicktest).
# Note: for pull requests, "develop" should be the base branch name.
# See: https://docs.travis-ci.com/user/conditions-v1
stages:
- name: sniff
- name: quicktest
if: branch NOT IN (master, develop)
- name: test
if: branch IN (master, develop)

jobs:
fast_finish: true
include:
#### SNIFF STAGE ####
- stage: sniff
php: 7.4
env: PHPCS_BRANCH="dev-master"
addons:
apt:
packages:
- libxml2-utils
before_script:
- export PHPCS_DIR=/tmp/phpcs
- export SNIFFS_DIR=/tmp/sniffs
- git clone -b master --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git $PHPCS_DIR
- git clone -b master --depth 1 https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git $SNIFFS_DIR
script:
# WordPress Coding Standards.
# @link https://github.com/WordPress/WordPress-Coding-Standards
# @link http://pear.php.net/package/PHP_CodeSniffer/
# - $PHPCS_DIR/bin/phpcs --runtime-set ignore_warnings_on_exit 1

    _# Validate the xml files.
    # @link http://xmlsoft.org/xmllint.html
    # For the build to properly error when validating against a scheme, these each have to be in their own condition.
    - xmllint --noout --schema $PHPCS_DIR/phpcs.xsd ./*/ruleset.xml
    # - xmllint --noout --schema $PHPCS_DIR/phpcs.xsd $PHPCS_DIR/phpcs.xml.dist.sample_

    _# Check the code-style consistency of the xml files.
    - diff -B --tabsize=4 $SNIFFS_DIR/WordPress/ruleset.xml <(xmllint --format "$SNIFFS_DIR/WordPress/ruleset.xml")
    - diff -B --tabsize=4 $SNIFFS_DIR/WordPress-Core/ruleset.xml <(xmllint --format "$SNIFFS_DIR/WordPress-Core/ruleset.xml")
    - diff -B --tabsize=4 $SNIFFS_DIR/WordPress-Docs/ruleset.xml <(xmllint --format "$SNIFFS_DIR/WordPress-Docs/ruleset.xml")
    - diff -B --tabsize=4 $SNIFFS_DIR/WordPress-Extra/ruleset.xml <(xmllint --format "$SNIFFS_DIR/WordPress-Extra/ruleset.xml")
    - diff -B --tabsize=4 $SNIFFS_DIR/phpcs.xml.dist.sample <(xmllint --format "$SNIFFS_DIR/phpcs.xml.dist.sample")_

    _# Validate the composer.json file.
    # @link https://getcomposer.org/doc/03-cli.md#validate
    - composer validate --no-check-all --strict_

    _# Check that the sniffs available are feature complete.
    # For now, just check that all sniffs have unit tests.
    # At a later stage the documentation check can be activated.
    - composer check-complete_

_#### QUICK TEST STAGE ####
# This is a much quicker test which only runs the unit tests and linting against the low/high
# supported PHP/PHPCS combinations.
- stage: quicktest
  php: 7.4
  env: PHPCS_BRANCH="dev-master" LINT=1
- php: 7.3
  env: PHPCS_BRANCH="3.5.0"
- php: 7.0
  env: PHPCS_BRANCH="3.5.0"
- php: 5.4
  env: PHPCS_BRANCH="3.5.0"_

_#### TEST STAGE ####
# Add extra build to test against PHPCS 4.
- stage: test
  php: 7.4
  env: PHPCS_BRANCH="4.0.x-dev as 3.9.99"_

allow_failures:
# Allow failures for unstable builds.
- php: "nightly"
- env: PHPCS_BRANCH="4.0.x-dev as 3.9.99"

before_install:
# Speed up build time by disabling Xdebug.
# https://johnblackbourn.com/reducing-travis-ci-build-times-for-wordpress-projects/
# https://twitter.com/kelunik/status/954242454676475904
- phpenv config-rm xdebug.ini || echo 'No xdebug config.'

_# On stable PHPCS versions, allow for PHP deprecation notices.
# Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore.
- |
  if [[ "${TRAVIS_BUILD_STAGE_NAME^}" != "Sniff" && $PHPCS_BRANCH != "dev-master" ]]; then
    echo 'error_reporting = E_ALL & ~E_DEPRECATED' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
  fi
- export XMLLINT_INDENT="	"_

install:

_- |
  if [[ ${PHPCS_BRANCH:0:2} == "4." ]]; then
    # Set Composer up to download only PHPCS from source for PHPCS 4.x.
    # The source is needed to get the base testcase from PHPCS.
    composer config preferred-install.squizlabs/php_codesniffer source
  else
    composer config preferred-install.squizlabs/php_codesniffer auto
  fi
- composer require squizlabs/php_codesniffer:"${PHPCS_BRANCH}" --no-update --no-suggest --no-scripts
- |
  if [[ $TRAVIS_PHP_VERSION == "nightly" ]]; then
    # PHPUnit 7.x does not allow for installation on PHP 8, so ignore platform
    # requirements to get PHPUnit 7.x to install on nightly.
    composer install --ignore-platform-reqs --no-suggest
  else
    # Do a normal dev install in all other cases.
    composer install --no-suggest
  fi

script:
# Lint the PHP files against parse errors.
- if [[ "$LINT" == "1" ]]; then composer lint; fi_

# Run the unit tests.
- composer run-tests

So, is there any workaround for this or am I doing something wrong cause this shouldn't be an issue?

P.S.: this is my first issue, please let me know if i did something bad on opening issues

@jrfnl
Copy link
Contributor

jrfnl commented Jul 17, 2020

@gz-ang I'm guessing you are using a test version of Composer 2.0 ? As that sounds like an error coming from the stricter PSR-4 checks in Composer 2.0.

I think it could actually be solved by the autoload-dev being changed to use lowercase for the directory name, though I'd need to test to be sure.

Having said that, looking over your script, I have a lot of questions: you seem to be running largely the script of the WordPressCS standard, but you also seem to be cloning WPCS.... and using composer install etc...

Unless you are contributing to WPCS, this is not the script you should be using and if you are contributing to WPCS, you should be using the proper script.

@jrfnl
Copy link
Contributor

jrfnl commented Jul 17, 2020

Just tested with WPCS develop and Composer 2.0 and still can't reproduce the issue. This is not a PHPCS issue, nor a WPCS issue, but something to do with your own setup.

Having taken a quick look at the repo: I don't even know where to start... but let me just say this:

  • You seem to have a complete WP install committed, INCLUDING PASSWORDS in wp-config.php....
  • The above problem seems to be caused by you using most of the WPCS composer.json and .travis.yml files, but missing the phpunit.xml.dist file which would trigger the PHPUnit bootstrap file for WPCS to be loaded.

Suggestion: close.

@gz-ang
Copy link
Author

gz-ang commented Jul 17, 2020

Thank you for the advise, I think I might have confused myself by cloning the WPCS and using composer at the same time. I just realized what I did was really dumb and redundant. Thanks for the heads up.

Now that you mentioned, I should remove that as well. Alright, I think I'll have to be clear to use only one method instead of mixing it up. Again, thanks a lot. :)

@gz-ang gz-ang closed this as completed Jul 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants