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

phpunit Depends attribute broken with BypassFinals and cache enabled #55

Open
annadamm-check24 opened this issue Apr 24, 2024 · 1 comment

Comments

@annadamm-check24
Copy link

annadamm-check24 commented Apr 24, 2024

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

@dg
Copy link
Owner

dg commented Apr 25, 2024

I don't use PHPUnit, so I can't help with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants