github sebastianbergmann/phpunit 13.5.0
PHPUnit 13.5.0

one hour ago

Added

  • #7038: --show-effective-configuration CLI option to show what a configuration will execute, without executing it
  • #7039: TestCase::suspendOutputBuffering() and TestCase::resumeOutputBuffering() methods for capturing the output of a test method that TestCase::invokeTestMethod() runs in a coroutine with its own output buffers
  • #7049: --random-seed <N> CLI option
  • #7086: --triggering-tests-limit CLI option and triggeringTestsLimit XML attribute to group and limit the tests listed for each issue
  • #7146: Run receipt that records what was run and how the run ended in Open Test Reporting logfile and the compact output
  • #7198: Result of the test run in JSON format (--json, --log-json)
  • phpunit/php-code-coverage #1056: The code coverage report in XML format includes branch and path coverage
  • phpunit/php-code-coverage 14.6: The code coverage report in HTML format shows, next to a line that is covered, how many tests cover it or, when the code coverage driver collects hit counts, how often the line was executed
  • phpunit/php-code-coverage 14.6: The code coverage report in HTML format has navigation between the pieces of code that are not covered: the n and p keys, and two buttons, jump to the next and to the previous one
  • --gaps-only CLI option and gapsOnly attribute for the <jsonl> element of the XML configuration file to limit the code coverage report in JSONL format to what is not covered: coverage.jsonl then has no record for a file that has nothing that is not covered, and no record for a method or function that is covered
  • --details-limit <n> CLI option to limit each message, each stack trace, and the output of each test that the compact output (--compact) prints, and each message, diff, and stack trace of the result of the test run in JSON format that is the output of --json, to <n> characters
  • exitCode() and signal() methods on the TestRunner\ChildProcessFinished and TestRunner\ChildProcessErrored events for the exit code of a child process and the signal that terminated it
  • outcome() method on the Application\Finished event for how the test run ended, as the run receipt records it: its status, the numbers of tests by outcome, and the numbers of the issues triggered by tests and by the test runner

Changed

  • #7049: Renamed phpunit:randomOrderSeed to phpunit:randomSeed in Open Test Reporting XML logfiles
  • #7051: Seed random number generators using --random-seed <N>, regardless of whether PHPUnit needs random number generation
  • phpunit/php-code-coverage #1407: The line of the right operand of a && (or and) that spans multiple lines is no longer reported as covered when it was not executed, as this operand is not evaluated when the left operand is false
  • phpunit/php-code-coverage 14.6: The line of the right operand of a || (or or) that spans multiple lines, and the lines of a method call or property fetch after ?-> that starts on a line of its own, are no longer reported as covered when they were not executed
  • phpunit/php-code-coverage 14.6: On PHP 8.6 and later, the executable lines of a file are determined from its bytecode instead of from its syntax when OPcache is enabled, compiles the code without optimizations (opcache.optimization_level=0), and does not skip recently modified files (opcache.file_update_protection=0): lines that PHP attributes no code to, such as the continuation lines of a multi-line function call, are then no longer counted as executable
  • phpunit/php-code-coverage 14.6: Processing the code coverage data of a test, and merging the code coverage data of tests that are run in separate processes, is faster
  • phpunit/php-code-coverage 14.6: The code coverage report in HTML format lists a directory that contains nothing but another directory, or nothing but a single file, together with what it contains instead of requiring a click for each level
  • phpunit/php-code-coverage 14.6: The view for branch coverage of the code coverage report in HTML format shows, next to a line that a branch with more than one successor ends on, which of the edges out of that branch were taken
  • The lines below the header of a record of the compact output (--compact) are now indented by two spaces: a message, a diff, a stack trace, and the output of a test can no longer be mistaken for the header of a record, the summary line, or the receipt of the test run, which begin in the first column
  • The compact output (--compact) now prints the path of a file inside the working directory relative to the working directory, which the receipt of the test run names, in the frames of a stack trace, in the header of the record for an issue, and in the location of a test that triggered an issue: the path to the project is no longer repeated in each of them, and a file outside the working directory stands out
  • The summary line of the compact output (--compact) no longer begins with OK when no test failed or errored but the test run was cut short: it begins with STOPPED when a --stop-on-* option ended the test run, with INTERRUPTED when a signal did, and with TIME LIMIT EXCEEDED when the time limit configured using --timeout was exceeded
  • The compact output (--compact) now prints that the test run was interrupted by a signal as a record of its own, after the summary line
  • The summary of the default output no longer says OK when no test failed or errored but the test run was cut short: it says STOPPED! when a --stop-on-* option ended the test run, INTERRUPTED! when a signal did, and TIME LIMIT EXCEEDED! when the time limit configured using --timeout was exceeded, followed by the numbers of tests and assertions
  • The default output now says which --stop-on-* option stopped the test run, in a line of its own before the result is printed, for instance The test run was stopped by --stop-on-failure.: a test run that was stopped after a test failed or errored was reported exactly like a test run that ran every selected test
  • A test run for which a time limit is configured using --timeout is no longer started when the time limit cannot be enforced because the pcntl extension is not available: the test runner then exits with an error message and shell exit code 2, instead of only checking the time limit between two tests
  • A test run is no longer started when the cache directory that is configured using --cache-directory or the cacheDirectory attribute cannot be created or cannot be written to: the test runner then exits with an error message that names the directory and with shell exit code 2, before the bootstrap script, the extensions, or the tests are loaded. This does not depend on whether the test run would write to the cache directory, and it also applies to --warm-coverage-cache. Until now, such a test run recorded its history elsewhere, or not at all, without saying so, or crashed when code coverage was collected
  • A cache directory configured using --cache-directory that cannot be created is no longer replaced, without saying so, by the cache directory that is configured in the XML configuration file
  • A PHP process that ends before the test run did and while no test is running, for instance because a bootstrap script, an extension, a data provider, or a before-first-test method calls exit(), or because PHP raises an error that ends the process while a code coverage report is written, is now reported as a premature end, as it already is when a test is running: a message such as Fatal error: Premature end of PHP process while the bootstrap script was loaded. is printed and the shell exit code is 2, also when exit(0) was called
  • The compact output (--compact) and the result of the test run in JSON format (--json, --log-json) now record a test run that did not reach its end because the PHP process ended while a bootstrap script, an extension, or the test suite was loaded, while tests were executed, or while the result of the test run was reported: the receipt and the JSON document are written with the status ended-prematurely
  • The Open Test Reporting XML logfile (--log-otr) of a test run that did not reach its end, because the PHP process ended although the test runner did not end it, because the test runner crashed, or because a second interrupt signal (SIGINT) ended the test run at once, is now a complete document: the test and the test suites that were not finished are reported as aborted, and the phpunit:outcome element is written with the status ended-prematurely, crashed, or interrupted and says why the test run did not reach its end in its phpunit:reason element
  • The compact output (--compact) and the result of the test run in JSON format (--json, --log-json) now record a test run during which the test runner crashed, with the status crashed, and a test run that a second interrupt signal (SIGINT) ended at once, with the status interrupted
  • The compact output (--compact) now records a test run that is not started, for instance because the cache directory cannot be written to, because the bootstrap script or a test file cannot be loaded, or because the time limit configured using --timeout cannot be enforced: the reason is printed as a NOT STARTED record, followed by the receipt of the test run with the status not-started and the shell exit code, instead of as a line of text without a receipt
  • The Open Test Reporting XML logfile (--log-otr) of a test run that is not started, for instance because the cache directory cannot be written to or because the bootstrap script or a test file cannot be loaded, is now a complete document: the phpunit:outcome element is written with the status not-started and says why the test run was not started in its phpunit:reason element, instead of the logfile ending after the event that starts the test run, without its root element being closed
  • The Application\Finished event is now also emitted for a test run that is not started after the extensions were loaded, for instance because a test file cannot be loaded or because the file configured using --test-id-filter-file does not exist: the outcome that the event carries then has the status not-started. A subscriber that does something when the test run has ended, for instance writing a report, is now also notified in these cases
  • A test run that was interrupted by a signal (SIGINT) now ends with shell exit code 130, no matter whether the tests that were run until then passed, instead of the shell exit code of a test run that ran every selected test
  • Before-first-test and after-last-test methods of a test class whose tests all run in separate processes are no longer called in the test runner's process
  • A test that is run in a separate process and a PHPT test are now aborted when the time limit for the test run configured using --timeout is exceeded while they are running: the child process is terminated and the test is reported as an error, instead of the test run being stopped only after such a test has finished
  • A before-first-test method, an after-last-test method, a data provider, and a SKIPIF section of a PHPT test that is not run in a separate process are now aborted, as a test already is, when they are running in the test runner's process when the time limit for the test run configured using --timeout is exceeded (this requires the pcntl extension)
  • An exceeded time limit for the test run is now also noticed, and reported using shell exit code 124, when no test is started or finished after the time limit was exceeded, for instance because it was exceeded by an after-last-test method
  • A test with a time limit of its own (--enforce-time-limit) is now aborted when the time limit for the test run is exceeded before the time limit for the test
  • A test run whose tests have not ended two seconds after the time limit for the test run configured using --timeout was exceeded, for instance because a test catches the exception it is aborted with or because the bootstrap script does not end, is now stopped: the test that was running is reported as an error, the result is printed, and the test runner exits with shell exit code 124 (this requires the pcntl extension)
  • A process that keeps the test runner from noticing that the time limit for the test run configured using --timeout was exceeded, for instance one that a test started using exec() and waits for, is now terminated one second after the time limit was exceeded, and the test runner itself is terminated when it has not ended the test run five seconds after the time limit was exceeded, for instance because the pcntl extension is not available and a test does not end (this requires the posix extension and is not available on Windows)
  • When a before-first-test method, for instance setUpBeforeClass(), of a test class whose tests all run in separate processes calls markTestSkipped() or markTestIncomplete(), fails, or errors, then a separate process is now started for each test of the class and each test is reported as skipped, failed, or errored, instead of the test class being reported once as skipped, failed, or errored
  • Version requirements of #[RequiresPhp], #[RequiresPhpExtension], and #[RequiresPhpunit] are handled using sebastian/version-requirement: a test errors when its version requirement is neither a version constraint such as ^8.5 nor a version comparison such as >= 8.5.0, for instance 8.5.0RC1, 8.5-dev, or >=8.3 <8.5, which were previously interpreted as >= 8.5.0RC1, 8.5.*, and < 8.5, respectively

Deprecated

  • #7049: --random-order-seed <N> CLI option
  • Calling markTestSkipped() or markTestIncomplete() in an after-test method, for instance tearDown(), or in an after-last-test method, for instance tearDownAfterClass()
  • Support for loading test runner extensions from PHARs using the extensionsDirectory XML configuration attribute

Fixed

  • assertFinite() does not tell PHPStan that the value is a finite float or an int, so the type of the value is not narrowed when test code is analysed with PHPStan (this requires PHPStan 2.3.6 or newer)
  • The process that runs a PHPT test with an --ENV-- section is started with an environment that is built from $_SERVER instead of the environment of the test runner's process: environment variables that were set using putenv(), for instance those configured using <env> in the XML configuration file, are missing, and elements of $_SERVER that are not environment variables, for instance those configured using <server> in the XML configuration file, are exported as environment variables
  • A test run history that cannot be written, for instance because the directory of the XML configuration file is read-only and no cache directory is configured, leads to a PHP warning that is printed as it is (fopen(): Failed to open stream: Permission denied) instead of a test runner warning
  • The test runner crashes (An error occurred inside PHPUnit.) when code coverage is collected and the directory in which the result of the static analysis is cached cannot be created: a test runner warning is now triggered and the result of the static analysis is not cached, and --warm-coverage-cache reports the directory it cannot use

Learn how to install or update PHPUnit 13.5 in the documentation.

Keep up to date with PHPUnit:

  • You can follow @phpunit@phpc.social to stay up to date with PHPUnit's development.
  • You can subscribe to the PHPUnit Updates newsletter to receive updates about and tips for PHPUnit.

Don't miss a new phpunit release

NewReleases is sending notifications on new releases.