-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Q | A |
---|---|
PHPUnit version | 12.4.1 |
PHP version | 8.4.12 |
Installation Method | Composer |
$ composer info | sort
myclabs/deep-copy 1.13.4 Create deep copies (clones) of your objects
nikic/php-parser 5.6.1 A PHP parser written in PHP
phar-io/manifest 2.0.4 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
phpunit/php-code-coverage 12.4.0 Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator 6.0.0 FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-invoker 6.0.0 Invoke callables with a timeout
phpunit/php-text-template 5.0.0 Simple template engine.
phpunit/php-timer 8.0.0 Utility class for timing
phpunit/phpunit 12.4.1 The PHP Unit Testing framework.
sebastian/cli-parser 4.2.0 Library for parsing CLI options
sebastian/comparator 7.1.3 Provides the functionality to compare PHP values for equality
sebastian/complexity 5.0.0 Library for calculating the complexity of PHP code units
sebastian/diff 7.0.0 Diff implementation
sebastian/environment 8.0.3 Provides functionality to handle HHVM/PHP environments
sebastian/exporter 7.0.2 Provides the functionality to export PHP variables for visualization
sebastian/global-state 8.0.2 Snapshotting of global state
sebastian/lines-of-code 4.0.0 Library for counting the lines of code in PHP source code
sebastian/object-enumerator 7.0.0 Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector 5.0.0 Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context 7.0.1 Provides functionality to recursively process PHP variables
sebastian/type 6.0.3 Collection of value objects that represent the types of the PHP type system
sebastian/version 6.0.0 Library that helps with managing the version number of Git-hosted PHP projects
staabm/side-effects-detector 1.0.5 A static analysis tool to detect side effects in PHP code
theseer/tokenizer 1.2.3 A small library for converting tokenized PHP source code into XML and potentially other formats
$ vendor/bin/phpunit --check-php-configuration
PHPUnit 12.4.1 by Sebastian Bergmann and contributors.
Checking whether PHP is configured according to https://docs.phpunit.de/en/12.4/installation.html#configuring-php-for-development
display_errors = On ... not ok ()
display_startup_errors = On ... not ok ()
error_reporting = -1 ... not ok (22527)
zend.assertions = 1 ... ok
assert.exception = 1 ... ok
memory_limit = -1 ... ok
(I have normal dev settings, not sure why it says "not ok")
Summary
Preconditions:
- Static property backup is enabled
- A value class V forbids serialization by throwing an error in
__unserialize
- There exists somewhere a static property holding an instance of V
- This static property is initialized before tests run
- PHPUnit tries to backup that static property
The thrown error will be swallowed silently and not reported to the user.
Current behavior
There is no trace that an error occurred. Other tests in the same test class will not run. The only way to find out that something is wrong is by noticing that the number of executed tests is "lower than usual", or by individually running a test and noticing that it doesn't execute. For a codebase with many tests, errors could remain unnoticed for a long time.
How to reproduce
Minimal test case:
ValueClass.php
<?php
class ValueClass {
public static $instance;
public function __unserialize( array $data ): void {
throw new Error("Cannot unserialize '$this'");
}
}
MyTest.php
<?php
require 'ValueClass.php';
use PHPUnit\Framework\TestCase;
class MyTest extends TestCase {
public static function setUpBeforeClass(): void {
ValueClass::$instance = new ValueClass;
}
public function testFoo() {
$this->assertTrue( true );
}
}
And then run:
composer require --dev "phpunit/phpunit"
vendor/bin/phpunit --static-backup MyTest.php
Expected behavior
I'm not sure because I didn't check why exactly the error is swallowed. However, I think PHPUnit should either ignore the error and continue executing the test, or report the error to the user, together with the fact that the test was not executed (similar to when there is an error in a data provider).