sebastianbergmann / phpunit

The PHP Unit Testing framework.
https://phpunit.de/
BSD 3-Clause "New" or "Revised" License
19.66k stars 2.2k forks source link

`@depends clone` may cause Phpunit to silently die because of Exception thrown by DeepClone lib when cloning failed #3866

Closed Arkemlar closed 1 week ago

Arkemlar commented 5 years ago
Q A
PHPUnit version 7.5.14
PHP version 7.3.6
Installation Method Composer

Composer deps (some of them):

myclabs/deep-copy                                 1.9.1               Create deep copies (clones) of your objects
myclabs/php-enum                                  1.7.1               PHP Enum implementation
phpspec/prophecy                                  1.8.1               Highly opinionated mocking framework for PHP 5.3+
phpstan/phpdoc-parser                             0.3.5               PHPDoc parser with support for nullable, intersection and generic types
phpstan/phpstan                                   0.11.12             PHPStan - PHP Static Analysis Tool
phpstan/phpstan-doctrine                          0.11.5              Doctrine extensions for PHPStan
phpstan/phpstan-symfony                           0.11.6              Symfony Framework extensions and rules for PHPStan
phpunit/php-code-coverage                         6.1.4               Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator                         2.0.2               FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-text-template                         1.2.1               Simple template engine.
phpunit/php-timer                                 2.1.2               Utility class for timing
phpunit/php-token-stream                          3.1.0               Wrapper around PHP's tokenizer extension.
phpunit/phpunit                                   7.5.14              The PHP Unit Testing framework.

Summary

Just tried using @depends clone and it failed - phpunit just silently skipped that test.


    public function testFirst(): Notification
    {
        $notification = $this->createNotification(1);
        $this->assertEquals(1,1);

        return $notification;
    }

    /**
     * @depends clone testFirst
     */
    public function testSecond(Notification $notification): Notification
    {
        // whatever code with some asserts

        return $notification;
    }

Output:

bin/phpunit --filter Billing --debug
PHPUnit 7.5.14 by Sebastian Bergmann and contributors.

Testing 
Test 'Tests\Billing\Domain\Notification\NotificationTest::testFirst' started
Test 'Tests\Billing\Domain\Notification\NotificationTest::testFirst' ended

Notification class is a classic object, some fields contains nested objects.

If I remove clone word in @depends or replace it by shallowClone - then second test will be executed.

Current behavior

Phpunit doesn't properly recognize @depends clone testName expression

How to reproduce

Use code above?

Expected behavior

Expected behavior described in documentation and in this issue https://github.com/sebastianbergmann/phpunit/issues/1780

After update (read first comment below) expected behavior is to show some error message or at least passthrough the original DeepCloner's exception but not silence it.

Arkemlar commented 5 years ago

UPD: I tried to use deep_copy from MyClabs manually:

$notification = deep_copy($notification);

And got such an error: DeepCopy\Exception\CloneException: The class "App\Billing\Domain\Notification\NotificationProcessStatus" is not cloneable. So actually the problem is that MyClabs cloner failed to clone but Phpunit silenced this exception and just skipped test case (or silently died, I dont exactly know). Phpunit should notice us if it fails to clone the object!

Arkemlar commented 5 years ago

UPD2: It seems that Phpunit actually dies at this exception when using @depends clone.

Here is my output when I use deep_copy manually and exception raised inside test case scope.

Testing 
...............................................................  63 / 252 ( 25%)
............................................................... 126 / 252 ( 50%)
............................................................... 189 / 252 ( 75%)
..........ESSSSS............................................... 252 / 252 (100%)

And here is my output when I use Phpunit's cloning and exception raised somewhere inside its code:

Testing 
...............................................................  63 / 252 ( 25%)
............................................................... 126 / 252 ( 50%)
............................................................... 189 / 252 ( 75%)
..........
kubawerlos commented 1 week ago

Is this still an issue? I cannot reproduce it even on branch 8.5.