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

Skipping a test during setUp will not dispatch test finished event #5544

Closed
dmaicher opened this issue Oct 21, 2023 · 3 comments
Closed

Skipping a test during setUp will not dispatch test finished event #5544

dmaicher opened this issue Oct 21, 2023 · 3 comments
Labels
feature/events Issues related to PHPUnit's event system feature/test-runner CLI test runner type/bug Something is broken version/10 Something affects PHPUnit 10

Comments

@dmaicher
Copy link

Q A
PHPUnit version 10.4.1
PHP version 8.2
Installation Method Composer

Summary

I noticed that given the following test class

<?php

use PHPUnit\Framework\TestCase;

class SkippedTest extends TestCase
{
    protected function setUp(): void
    {
        parent::setUp();
        $this->markTestSkipped();
    }

    public function testSkipped(): void
    {
        $this->assertTrue(true);
    }
}

There is no PHPUnit\Event\Test\Finished event dispatched for the testSkipped test.

If I move the markTestSkipped into the test method itself then it is dispatched.

Is this on purpose? 🤔

@dmaicher dmaicher added type/bug Something is broken version/10 Something affects PHPUnit 10 version/9 Something affects PHPUnit 9 labels Oct 21, 2023
@sebastianbergmann sebastianbergmann added feature/test-runner CLI test runner feature/events Issues related to PHPUnit's event system and removed version/9 Something affects PHPUnit 9 labels Oct 21, 2023
@dcondrey
Copy link

These seems intentional.

@dmaicher
Copy link
Author

Interesting is that this worked fine with PHPUnit 8+9 and the AfterTestHook was called.

I noticed this when rolling back a database transaction in this extension: https://github.com/dmaicher/doctrine-test-bundle/blob/42b840b24232e71bd3fcaca712e333df20e32262/src/DAMA/DoctrineTestBundle/PHPUnit/PHPUnitExtension.php#L48

@dmaicher dmaicher closed this as not planned Won't fix, can't repro, duplicate, stale Nov 27, 2023
@bahag-schlachterk
Copy link

We just encountered the same issue when migrating our project to PHPUnit >= 10.x
In fact this behaviour also breaks the integration with PHPStorm / IntelliJ which lead to some serious confusion on our side as we could not explain this type of behaviour at first.
However this is exactly as described in the documentation:
https://docs.phpunit.de/en/11.0/writing-tests-for-phpunit.html#writing-tests-for-phpunit-skipping-tests-examples-databasetest-php
Moving the checks external dependencies (such as specific extensions or local command line tools) to setUpBeforeClass resolves the issue.

Not sure if this is a bug or just a thing that should be fixed in the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/events Issues related to PHPUnit's event system feature/test-runner CLI test runner type/bug Something is broken version/10 Something affects PHPUnit 10
Projects
None yet
Development

No branches or pull requests

4 participants