Skip to content

phpunit Depends attribute broken with BypassFinals and cache enabled #55

@annadamm-check24

Description

@annadamm-check24
Q A
PHPUnit version 10.5.19
PHP version 8.2.18
Installation Method Composer
BypassFinals version 1.6.0

Summary

When using the #[Depends('xxx')] attribute, or @depends xxx annotation, tests are getting skipped when the original test fails, but are not getting executed when the test succeeds.

Current behavior

Tests are skipped when the origin function fails, but are not executed when it succeeds. It also does not appear in the "skipped" list

How to reproduce

<?php
// DependTest.php
declare(strict_types=1);

use PHPUnit\Framework\Attributes\Depends;
use PHPUnit\Framework\TestCase;

final class DependTest extends TestCase
{
    public function testWorks(): void
    {
        self::assertTrue(true);
    }

    public function testDoesNotWork(): void
    {
        self::assertTrue(false);
    }

    #[Depends('testWorks')]
    public function testDependsOnWorks(): void
    {
        self::assertTrue(true);
    }

    #[Depends('testDoesNotWork')]
    public function testDependsOnDoesNotWorks(): void
    {
        self::assertTrue(true);
    }
}
<?php
// BypassFinalsExtension
declare(strict_types=1);

use DG\BypassFinals;
use PHPUnit\Runner\Extension\Extension;
use PHPUnit\Runner\Extension\Facade;
use PHPUnit\Runner\Extension\ParameterCollection;
use PHPUnit\TextUI\Configuration\Configuration;

final class BypassFinalsExtension implements Extension
{
    public function bootstrap(Configuration $configuration, Facade $facade, ParameterCollection $parameters): void
    {
        BypassFinals::setCacheDirectory(__DIR__ . '/cache'); // with this line disabled, it works correctly
        BypassFinals::enable();
    }
}

execution:

vendor/bin/phpunit DependTest.php --display-skipped

output:

PHPUnit 10.5.19 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.18
Configuration: /Users/anna.damm/Projects/test/phpunit.xml.dist

.FS                                                                 3 / 3 (100%)

Time: 00:00.033, Memory: 10.00 MB

There was 1 failure:

1) DependTest::testDoesNotWork
Failed asserting that false is true.

/Users/anna.damm/Projects/test/DependTest.php:17

--

There was 1 skipped test:

1) DependTest::testDependsOnDoesNotWorks
This test depends on "DependTest::testDoesNotWork" to pass

FAILURES!
Tests: 3, Assertions: 2, Failures: 1, Skipped: 1.

With this test case, the "testDependsOnWorks" is not executed. Tests are:
testWorks -> gets executed successfully
testDoesNotWork -> fails
testDependsOnWorks -> is not executed
testDependsOnDoesNotWorks -> is skipped because of failed dependency

Expected behavior

Test functions with #[Depends(...)] or @depends xxx should be executed when the function they depend on are executed successfully

This refers to sebastianbergmann/phpunit#5826

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions