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

Unexpected error code #5199

Closed
loevgaard opened this issue Feb 14, 2023 · 5 comments
Closed

Unexpected error code #5199

loevgaard opened this issue Feb 14, 2023 · 5 comments
Labels
feature/test-runner CLI test runner type/bug Something is broken version/10 Something affects PHPUnit 10

Comments

@loevgaard
Copy link

Q A
PHPUnit version 10.0.7
PHP version 8.1.13
Installation Method Composer

Summary

The problem can be summarized by this output:

➜  composer-file-changes-plugin git:(master) vendor/bin/phpunit
PHPUnit 10.0.7 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.1.13
Configuration: /Users/loevgaard/PhpstormProjects/composer-file-changes-plugin/phpunit.xml.dist

..                                                                  2 / 2 (100%)

Time: 00:00.050, Memory: 8.00 MB

There was 1 PHPUnit warning:

1) No code coverage driver available

WARNINGS!
Tests: 2, Assertions: 6, Warnings: 1.
➜  composer-file-changes-plugin git:(master) echo $?
1

As you can see PHPUnit runs with no errors, but with a warning and the exit code is 1. I haven't enabled the failOnWarning flag in my configuration, so I find this behaviour weird.

Output of composer info | sort



Direct dependencies:
Transitive dependencies:
amphp/amp                                      v2.6.2    A non-blocking concurrency framework for PHP applications.
amphp/byte-stream                              v1.8.1    A stream abstraction to make working with non-blocking I/O simple.
composer/ca-bundle                             1.3.5     Lets you find a path to the system CA bundle, and includes a fallback to the...
composer/class-map-generator                   1.0.0     Utilities to scan PHP code and generate class maps.
composer/composer                              2.5.3     Composer helps you declare, manage and install dependencies of PHP projects....
composer/metadata-minifier                     1.0.0     Small utility library that handles metadata minification and expansion.
composer/package-versions-deprecated           1.11.99.5 Composer plugin that provides efficient querying for installed package versi...
composer/pcre                                  3.1.0     PCRE wrapping library that offers type-safe preg_* replacements.
composer/semver                                3.3.2     Semver library that offers utilities, version constraint parsing and validat...
composer/spdx-licenses                         1.5.7     SPDX licenses list and validation library.
composer/xdebug-handler                        3.0.3     Restarts a process without Xdebug.
dealerdirect/phpcodesniffer-composer-installer v1.0.0    PHP_CodeSniffer Standards Composer Installer Plugin
dnoegel/php-xdg-base-dir                       v0.1.1    implementation of xdg base directory specification for php
ergebnis/composer-normalize                    2.29.0    Provides a composer plugin for normalizing composer.json.
ergebnis/json-normalizer                       2.1.0     Provides generic and vendor-specific normalizers for normalizing JSON docume...
ergebnis/json-printer                          3.3.0     Provides a JSON printer, allowing for flexible indentation.
ergebnis/json-schema-validator                 2.0.0     Provides a JSON schema validator, building on top of justinrainbow/json-schema.
felixfbecker/advanced-json-rpc                 v3.2.1    A more advanced JSONRPC implementation
felixfbecker/language-server-protocol          v1.5.2    PHP classes for the Language Server Protocol
fidry/cpu-core-counter                         0.4.1     Tiny utility to get the number of CPU cores.
justinrainbow/json-schema                      5.2.12    A library to validate a json schema.
localheinz/diff                                1.1.1     Fork of sebastian/diff for use with ergebnis/composer-normalize
myclabs/deep-copy                              1.11.0    Create deep copies (clones) of your objects
netresearch/jsonmapper                         v4.1.0    Map nested JSON structures onto PHP classes
nikic/php-parser                               v4.15.3   A PHP parser written in PHP
phar-io/manifest                               2.0.3     Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                                3.2.1     Library for handling version information and constraints
phpdocumentor/reflection-common                2.2.0     Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock              5.3.0     With this component, a library can provide support for annotations via DocBl...
phpdocumentor/type-resolver                    1.6.2     A PSR-5 based resolver of Class names, Types and Structural Element Names
phpstan/phpdoc-parser                          1.15.3    PHPDoc parser with support for nullable, intersection and generic types
phpstan/phpstan                                1.9.17    PHPStan - PHP Static Analysis Tool
phpunit/php-code-coverage                      10.0.0    Library that provides collection, processing, and rendering functionality fo...
phpunit/php-file-iterator                      4.0.1     FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-invoker                            4.0.0     Invoke callables with a timeout
phpunit/php-text-template                      3.0.0     Simple template engine.
phpunit/php-timer                              6.0.0     Utility class for timing
phpunit/phpunit                                10.0.7    The PHP Unit Testing framework.
psalm/plugin-phpunit                           0.18.4    Psalm plugin for PHPUnit
psr/container                                  2.0.2     Common Container Interface (PHP FIG PSR-11)
psr/log                                        3.0.0     Common interface for logging libraries
react/promise                                  v2.9.0    A lightweight implementation of CommonJS Promises/A for PHP
rector/rector                                  0.15.13   Instant Upgrade and Automated Refactoring of any PHP code
sebastian/cli-parser                           2.0.0     Library for parsing CLI options
sebastian/code-unit                            2.0.0     Collection of value objects that represent the PHP code units
sebastian/code-unit-reverse-lookup             3.0.0     Looks up which function or method a line of code belongs to
sebastian/comparator                           5.0.0     Provides the functionality to compare PHP values for equality
sebastian/complexity                           3.0.0     Library for calculating the complexity of PHP code units
sebastian/diff                                 5.0.0     Diff implementation
sebastian/environment                          6.0.0     Provides functionality to handle HHVM/PHP environments
sebastian/exporter                             5.0.0     Provides the functionality to export PHP variables for visualization
sebastian/global-state                         6.0.0     Snapshotting of global state
sebastian/lines-of-code                        2.0.0     Library for counting the lines of code in PHP source code
sebastian/object-enumerator                    5.0.0     Traverses array structures and object graphs to enumerate all referenced obj...
sebastian/object-reflector                     3.0.0     Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context                    5.0.0     Provides functionality to recursively process PHP variables
sebastian/type                                 4.0.0     Collection of value objects that represent the types of the PHP type system
sebastian/version                              4.0.1     Library that helps with managing the version number of Git-hosted PHP projects
seld/jsonlint                                  1.9.0     JSON Linter
seld/phar-utils                                1.2.1     PHAR file format utilities, for when PHP phars you up
seld/signal-handler                            2.0.1     Simple unix signal handler that silently fails where signals are not support...
setono/code-quality-pack                       v2.4.0    A pack that installs code quality tools.
slevomat/coding-standard                       8.8.0     Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding ...
spatie/array-to-xml                            2.17.1    Convert an array to xml
squizlabs/php_codesniffer                      3.7.1     PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violatio...
sylius-labs/coding-standard                    v4.3.0    Battle-tested coding standard configuration used in Sylius.
symfony/console                                v6.2.5    Eases the creation of beautiful and testable command line interfaces
symfony/deprecation-contracts                  v3.2.0    A generic function and convention to trigger deprecation notices
symfony/filesystem                             v6.2.5    Provides basic utilities for the filesystem
symfony/finder                                 v6.2.5    Finds files and directories via an intuitive fluent interface
symfony/polyfill-ctype                         v1.27.0   Symfony polyfill for ctype functions
symfony/polyfill-intl-grapheme                 v1.27.0   Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-normalizer               v1.27.0   Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring                      v1.27.0   Symfony polyfill for the Mbstring extension
symfony/polyfill-php73                         v1.27.0   Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/polyfill-php80                         v1.27.0   Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/polyfill-php81                         v1.27.0   Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions
symfony/process                                v6.2.5    Executes commands in sub-processes
symfony/service-contracts                      v3.2.0    Generic abstractions related to writing services
symfony/string                                 v6.2.5    Provides an object-oriented API to strings and deals with bytes, UTF-8 code ...
symplify/easy-coding-standard                  11.2.8    Use Coding Standard with 0-knowledge of PHP-CS-Fixer and PHP_CodeSniffer
theseer/tokenizer                              1.2.1     A small library for converting tokenized PHP source code into XML and potent...
vimeo/psalm                                    5.6.0     A static analysis tool for finding errors in PHP applications
webmozart/assert                               1.11.0    Assertions to validate method input/output with nice error messages.
webmozart/glob                                 4.6.0     A PHP implementation of Ant's glob.

@loevgaard loevgaard added the type/bug Something is broken label Feb 14, 2023
@sebastianbergmann sebastianbergmann added feature/test-runner CLI test runner version/10 Something affects PHPUnit 10 labels Feb 14, 2023
@sebastianbergmann
Copy link
Owner

I understand that this is unexpected to you, but to me it is not ;-) Let me explain.

There are different types of warnings:

  • Warnings from PHPUnit itself ("No code coverage driver available", for instance)
  • Warnings from PHP itself (E_WARNING)
  • Warnings from PHP code (E_USER_WARNING)

The failOnWarning attribute in the XML configuration file and the --fail-on-warning CLI option only control whether PHPUnit's test runner should exit with shell exit code that indicates failure when it comes to E_WARNING and E_USER_WARNING.

It is intentional that warnings from PHPUnit itself always lead to a shell exit code that indicates failure.

@loevgaard
Copy link
Author

Is it correct then that the No code coverage driver available warning has been converted to a 'real' error in PHPUnit 10? The reason I am asking is that I get status code 1 in PHPUnit 10 and status code 0 in PHPUnit 9.

@SmetDenis
Copy link

Good afternoon @sebastianbergmann

I have the same question.
Why do I get exit code 1 when I get the warning "No code coverage driver available"?

Sorry. Maybe I didn' understand something and would like to understand how to configure phpunit.xml now.

If I understand correctly, having one or more report types in the block forces me to use xdebug/pcov?

Do I have to change the phpunit.xml settings or install xdebug/pcov?

Is there an option to ignore the PHPUnit warning message?

I really appreciate any help you can provide.

@sebastianbergmann
Copy link
Owner

Why do I get exit code 1 when I get the warning "No code coverage driver available"?

I explained this in #5199 (comment): it is intentional that warnings from PHPUnit itself always lead to a shell exit code that indicates failure.

If I understand correctly, having one or more report types in the block forces me to use xdebug/pcov?
Do I have to change the phpunit.xml settings or install xdebug/pcov?

If you want a code coverage report then you need a code coverage driver, PCOV or Xdebug, installed and enabled. This is explained in the documentation.

Is there an option to ignore the PHPUnit warning message?

No.

@jrfnl
Copy link
Contributor

jrfnl commented Sep 3, 2024

Why do I get exit code 1 when I get the warning "No code coverage driver available"?

Is there an option to ignore the PHPUnit warning message?

No.

In my experience, there actually is a way to ignore the "No code coverage driver available" warning: run the tests with the --no-coverage flag.

Just posting this here for anyone still looking for a solution to this particular part of the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/test-runner CLI test runner type/bug Something is broken version/10 Something affects PHPUnit 10
Projects
None yet
Development

No branches or pull requests

4 participants