sebastianbergmann / phpunit

The PHP Unit Testing framework.

Home Page:https://phpunit.de/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Depends attribute and annotation only skip tests, but don't execute them on success

annadamm-check24 opened this issue · comments

Q A
PHPUnit version 10.5.19
PHP version 8.2.18
Installation Method Composer

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);
    }
}

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

I cannot reproduce this.

Issue5826Test.php

<?php declare(strict_types=1);
namespace PHPUnit\TestFixture\Issue5826;

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

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

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

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

    #[Depends('testFails')]
    public function testDependsOnFailingTest(): void
    {
        self::assertTrue(true);
    }
}
$ phpunit Issue5826Test.php --no-configuration --display-skipped
PHPUnit 10.5.19-20-g6da42eddf9 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.6

.F.S                                                                4 / 4 (100%)

Time: 00:00.010, Memory: 8.00 MB

There was 1 failure:

1) PHPUnit\TestFixture\Issue5826\Issue5826Test::testFails
Failed asserting that false is true.

/home/sb/Issue5826Test.php:16

--

There was 1 skipped test:

1) PHPUnit\TestFixture\Issue5826\Issue5826Test::testDependsOnFailingTest
This test depends on "PHPUnit\TestFixture\Issue5826\Issue5826Test::testFails" to pass

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

Okay, sorry for this. I could not reproduce it in an empty project but in ours and digged a bit deeper.
We use dg/bypass-finals to not have to add interfaces to every class we use internally. Apparently this is a bug in that extension..