sebastianbergmann / phpunit

The PHP Unit Testing framework.
https://phpunit.de/
BSD 3-Clause "New" or "Revised" License
19.69k stars 2.2k forks source link

[10.1.3] Class ControllerAbstractTestCase declared in ControllerAbstractTestCase.php is abstract #5402

Closed eusonlito closed 1 year ago

eusonlito commented 1 year ago

Related with https://github.com/sebastianbergmann/phpunit/issues/5181#issuecomment-1570382464

Q A
PHPUnit version 10.1.3
PHP version 8.2.6
Installation Method Composer

Summary

I have this open source project based in Laravel 10 using PHPUnit 10.1.3: https://github.com/eusonlito/Password-Manager

After migrate to PHPUnit 10 I get this warnings:

./vendor/bin/phpunit    
PHPUnit 10.1.3 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.6
Configuration: /var/www/phpunit.xml

...............................................................  63 / 316 ( 19%)
............................................................... 126 / 316 ( 39%)
............................................................... 189 / 316 ( 59%)
............................................................... 252 / 316 ( 79%)
............................................................... 315 / 316 ( 99%)
.                                                               316 / 316 (100%)

Time: 00:11.671, Memory: 56.50 MB

There were 8 PHPUnit test runner warnings:

1) Class App\Domains\App\Test\Controller\ControllerAbstractTestCase declared in /var/www/app/Domains/App/Test/Controller/ControllerAbstractTestCase.php is abstract

2) Class App\Domains\Dashboard\Test\Controller\ControllerAbstractTestCase declared in /var/www/app/Domains/Dashboard/Test/Controller/ControllerAbstractTestCase.php is abstract

3) Class App\Domains\PWA\Test\Controller\ControllerAbstractTestCase declared in /var/www/app/Domains/PWA/Test/Controller/ControllerAbstractTestCase.php is abstract

4) Class App\Domains\Tag\Test\Controller\ControllerAbstractTestCase declared in /var/www/app/Domains/Tag/Test/Controller/ControllerAbstractTestCase.php is abstract

5) Class App\Domains\Team\Test\Controller\ControllerAbstractTestCase declared in /var/www/app/Domains/Team/Test/Controller/ControllerAbstractTestCase.php is abstract

6) Class App\Domains\User\Test\Controller\ControllerAbstractTestCase declared in /var/www/app/Domains/User/Test/Controller/ControllerAbstractTestCase.php is abstract

7) Class App\Domains\User\Test\ControllerApi\ControllerApiAbstractTestCase declared in /var/www/app/Domains/User/Test/ControllerApi/ControllerApiAbstractTestCase.php is abstract

8) Class App\Domains\Tag\Test\Unit\UnitAbstractTestCase declared in /var/www/app/Domains/Tag/Test/Unit/UnitAbstractTestCase.php is abstract

WARNINGS!
Tests: 316, Assertions: 1417, Warnings: 8.

How to reproduce

git clone https://github.com/eusonlito/Password-Manager.git

cd Password-Manager

cp .env.example .env

composer install

php artisan key:generate

php artisan config:clear

./vendor/bin/phpunit

Expected behavior

Print output without any warning.

Thanks

Thanks a lot for your time on this tool.

sebastianbergmann commented 1 year ago

Your reproducing example is neither minimal nor self-contained.

eusonlito commented 1 year ago

I don't know how to create a minimal version of this tests (and not attached to Laravel).

I will close the issue for now then and try to create a version compatible with the issue in the future. Thanks anyway :)

eusonlito commented 1 year ago

I have found the issue. My Test folders include the base Abstract Classes and the tests was loaded with <directory> tag, then the abstract classes also was loaded.

I have Updated my phpunit.xml tests from:

<testsuites>
  <testsuite name="Controller">
    <directory suffix=".php">./app/Domains/App/Test/Controller</directory>
    <directory suffix=".php">./app/Domains/Dashboard/Test/Controller</directory>
    <directory suffix=".php">./app/Domains/PWA/Test/Controller</directory>
    <directory suffix=".php">./app/Domains/Tag/Test/Controller</directory>
    <directory suffix=".php">./app/Domains/Team/Test/Controller</directory>
    <directory suffix=".php">./app/Domains/User/Test/Controller</directory>
    <directory suffix=".php">./app/Domains/User/Test/ControllerApi</directory>
  </testsuite>

  <testsuite name="Unit">
    <directory suffix=".php">./app/Domains/Tag/Test/Unit</directory>
  </testsuite>
</testsuites>

to

<testsuites>
  <testsuite name="Controller">
    <directory suffix=".php">./app/Domains/App/Test/Controller</directory>
    <directory suffix=".php">./app/Domains/Dashboard/Test/Controller</directory>
    <directory suffix=".php">./app/Domains/PWA/Test/Controller</directory>
    <directory suffix=".php">./app/Domains/Tag/Test/Controller</directory>
    <directory suffix=".php">./app/Domains/Team/Test/Controller</directory>
    <directory suffix=".php">./app/Domains/User/Test/Controller</directory>
    <directory suffix=".php">./app/Domains/User/Test/ControllerApi</directory>

    <exclude>./app/Domains/App/Test/Controller/ControllerAbstractTestCase.php</exclude>
    <exclude>./app/Domains/Dashboard/Test/Controller/ControllerAbstractTestCase.php</exclude>
    <exclude>./app/Domains/PWA/Test/Controller/ControllerAbstractTestCase.php</exclude>
    <exclude>./app/Domains/Tag/Test/Controller/ControllerAbstractTestCase.php</exclude>
    <exclude>./app/Domains/Team/Test/Controller/ControllerAbstractTestCase.php</exclude>
    <exclude>./app/Domains/User/Test/Controller/ControllerAbstractTestCase.php</exclude>
    <exclude>./app/Domains/User/Test/ControllerApi/ControllerApiAbstractTestCase.php</exclude>
  </testsuite>

  <testsuite name="Unit">
    <directory suffix=".php">./app/Domains/Tag/Test/Unit</directory>

    <exclude>./app/Domains/Tag/Test/Unit/UnitAbstractTestCase.php</exclude>
  </testsuite>
</testsuites>

And the error is gone.