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

Abstract classes treated as tests, even when they used to not be #5523

Closed
Crell opened this issue Sep 23, 2023 · 5 comments
Closed

Abstract classes treated as tests, even when they used to not be #5523

Crell opened this issue Sep 23, 2023 · 5 comments
Labels
type/bug Something is broken version/10 Something affects PHPUnit 10

Comments

@Crell
Copy link

Crell commented Sep 23, 2023

Q A
PHPUnit version 10.3.5
PHP version 8.1
Installation Method Composer

Summary

I have some abstract classes in my tests, as a test hierarchy. The idea is that several different implementations of a thing all use the same tests in the base class, just providing an alternate implementation. I had the abstract base classes named FooTest, with child classes FooTypeATest, FooTypeBTest, etc. This worked fine in PHPUnit 9.

In 10.3, it still runs but I get a warning that the class is abstract. Which... yes, it is, but why would PHPUnit 9 rightly just ignore it, while PHPUnit 10 is giving me a warning? Is this deliberate?

@Crell Crell added type/bug Something is broken version/10 Something affects PHPUnit 10 labels Sep 23, 2023
@ghostwriter
Copy link
Contributor

#5132

@sebastianbergmann
Copy link
Owner

Yes, this is deliberate.

@borgogelli
Copy link

borgogelli commented Nov 3, 2023

Yes, this is deliberate.

@sebastianbergmann I think that it's counterintuitive and logically incorrect.

The problems generated are an avalanche:

  1. phpunit returns the exit code 1 even if the failOnWarning option is set to false
  2. So to solve the problem, the user is forced to transform the abstract class into a concrete one
  3. I have to create a dummy test method inside it to avoid other errors.

@ghostwriter
Copy link
Contributor

If an abstract class name ends in *Test (*Test.php), rename the class and file.

eg. Abstract*Test to Abstract*Testcase

@borgogelli
Copy link

borgogelli commented Nov 9, 2023

If an abstract class name ends in *Test (*Test.php), rename the class and file.

eg. Abstract*Test to Abstract*Testcase

I know that I can't use the Test suffix, but problem persists with PHPUnit 10.4.2
Could be the cause that I extends the class TestCase ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something is broken version/10 Something affects PHPUnit 10
Projects
None yet
Development

No branches or pull requests

4 participants