Phpunit: Deprecation warning given too eagerly

Created on 10 Dec 2019  ยท  16Comments  ยท  Source: sebastianbergmann/phpunit

The Invocation with class name is deprecated warning is printed when a directory (and not a class name) is given:

$ tree
.
โ”œโ”€โ”€ build
โ”‚ย ย  โ””โ”€โ”€ code-coverage
โ”‚ย ย      โ”œโ”€โ”€ CanvasIterator.php.html
โ”‚ย ย      โ”œโ”€โ”€ Canvas.php.html
โ”‚ย ย      โ”œโ”€โ”€ Color.php.html
โ”‚ย ย      โ”œโ”€โ”€ dashboard.html
โ”‚ย ย      โ”œโ”€โ”€ exceptions
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ dashboard.html
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ Exception.php.html
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ index.html
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ InvalidArgumentException.php.html
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ RuntimeException.php.html
โ”‚ย ย      โ”œโ”€โ”€ index.html
โ”‚ย ย      โ”œโ”€โ”€ Matrix.php.html
โ”‚ย ย      โ”œโ”€โ”€ PortablePixmapMapper.php.html
โ”‚ย ย      โ””โ”€โ”€ Tuple.php.html
โ”œโ”€โ”€ build.xml
โ”œโ”€โ”€ phive.xml
โ”œโ”€โ”€ phpunit.xml
โ”œโ”€โ”€ psalm.xml
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ src
โ”‚ย ย  โ”œโ”€โ”€ autoload.php
โ”‚ย ย  โ”œโ”€โ”€ CanvasIterator.php
โ”‚ย ย  โ”œโ”€โ”€ Canvas.php
โ”‚ย ย  โ”œโ”€โ”€ Color.php
โ”‚ย ย  โ”œโ”€โ”€ exceptions
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ Exception.php
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ InvalidArgumentException.php
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ RuntimeException.php
โ”‚ย ย  โ”œโ”€โ”€ Matrix.php
โ”‚ย ย  โ”œโ”€โ”€ PortablePixmapMapper.php
โ”‚ย ย  โ””โ”€โ”€ Tuple.php
โ”œโ”€โ”€ tests
โ”‚ย ย  โ”œโ”€โ”€ CanvasTest.php
โ”‚ย ย  โ”œโ”€โ”€ ColorTest.php
โ”‚ย ย  โ”œโ”€โ”€ fixture
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ 10_20_empty.ppm
โ”‚ย ย  โ”œโ”€โ”€ MatrixTest.php
โ”‚ย ย  โ”œโ”€โ”€ PortablePixmapMapperTest.php
โ”‚ย ย  โ””โ”€โ”€ TupleTest.php
โ””โ”€โ”€ tools
    โ”œโ”€โ”€ phpab
    โ”œโ”€โ”€ php-cs-fixer
    โ”œโ”€โ”€ phpunit
    โ”œโ”€โ”€ phpunit.phar -> phpunit
    โ””โ”€โ”€ psalm

8 directories, 39 files
$ ./tools/phpunit tests
PHPUnit 8.5.0 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.4.0 with PCOV 1.0.6
Configuration: /usr/local/src/raytracer/phpunit.xml
Warning:       Invocation with class name is deprecated

...................................S.......................       59 / 59 (100%)

Time: 82 ms, Memory: 10.00 MB

There was 1 skipped test:

1) SebastianBergmann\Raytracer\MatrixTest::test_the_product_of_two_matrices_can_be_multiplied_by_its_inverse

/usr/local/src/raytracer/tests/MatrixTest.php:528

OK, but incomplete, skipped, or risky tests!
Tests: 59, Assertions: 385, Skipped: 1.

CC @flow-control

typbug

Most helpful comment

Hey Sebastian,

this is due to the "missing" trailing slash. I added tests for this and a is_dir check.

/Flo

All 16 comments

I'll have a look

Thanks!

Hey Sebastian,

this is due to the "missing" trailing slash. I added tests for this and a is_dir check.

/Flo

Thank for fixing this!

:+1: just stumbled across this issue, thanks y'all for being so quick to address it :)

I still have this issue how to get ride of that ?

Testing started at 1:41 AM ...
C:\xampp\php\php.exe C:/xampp/htdocs/Project/vendor/phpunit/phpunit/phpunit --configuration C:\xampp\htdocs\Project\phpunit.xml --filter "/(::it_has_a_path)( .*)?$/" Tests\Unit\ThreadTest C:\xampp\htdocs\Project\tests\Unit\ThreadTest.php --teamcity --cache-result-file=C:\xampp\htdocs\Project\.phpunit.result.cache
PHPUnit 8.5.0 by Sebastian Bergmann and contributors.

Warning:       Invocation with class name is deprecated




Time: 321 ms, Memory: 26.00 MB

OK (1 test, 1 assertion)

Process finished with exit code 0

one thing, I updated my phpunit to the last version, But i cannot see changes of this PR on my phpunit why?

Hey @foremtehan

try without Tests\Unit\ThreadTest in the call, that should do the trick.

Kind regards
Flo

@flow-control That path/namespace picked by phpstorm automatically :

Capture

How to prevent this ? Normally i do test my methods by mouse hovering around the method name and hit the shortcut key to run the test

Does the problem persist with PHPUnit 8.5.1?

@sebastianbergmann still Yes:

Testing started at 8:36 PM ...
C:\xampp\php\php.exe C:/xampp/htdocs/Project/vendor/phpunit/phpunit/phpunit --configuration C:\xampp\htdocs\Project\phpunit.xml --filter "/(::it_has_path)( .*)?$/" Tests\Unit\ThreadTest C:\xampp\htdocs\Project\tests\Unit\ThreadTest.php --teamcity --cache-result-file=C:\xampp\htdocs\Project\.phpunit.result.cache
PHPUnit 8.5.1 by Sebastian Bergmann and contributors.

Warning:       Invocation with class name is deprecated




Time: 319 ms, Memory: 26.00 MB

OK (1 test, 1 assertion)

Process finished with exit code 0

@sebastianbergmann / @foremtehan as I see it, the generated command has the class name in it, which is deprecated. Omitting the class name will fix it. If you have multiple classes in one file, you can use the filter as described here https://github.com/sebastianbergmann/phpunit/pull/3860#issuecomment-564011548
Also in this thread you can see, that the PHP Storm devs are already up to this

The problem still exists.
/** * Test if user can add item to wishlist * * @test * * @return void * @author Vladimir Nikolic<[email protected]> * */ public function it_ads_item_to_wishlist() { $user = factory(\App\User::class)->create(); // see if user have any wishlist $this->assertEquals(null, $user->wishlist); }

Result:
Testing started at 10:57 ...
/usr/local/Cellar/php/7.3.11/bin/php /Users/vladimir/Projects/agrilaravel/vendor/phpunit/phpunit/phpunit --configuration /Users/vladimir/Projects/agrilaravel/phpunit.xml --filter "/(::it_ads_item_to_wishlist)( .*)?$/" Tests\Feature\WishlistTest /Users/vladimir/Projects/agrilaravel/tests/Feature/WishlistTest.php --teamcity --cache-result-file=/Users/vladimir/Projects/agrilaravel/.phpunit.result.cache
PHPUnit 8.5.2 by Sebastian Bergmann and contributors.

Warning: Invocation with class name is deprecated

Time: 343 ms, Memory: 30.00 MB

OK (1 test, 1 assertion)
Process finished with exit code 0

@nezaboravi You have Tests\Feature\WishlistTest in your invocation. This is a test class name. Hence the "Invocation with class name is deprecated" warning is given correctly.

From the phpstorm team:

We've already fixed the issue and the fix should be available in 2019.3.x update

https://youtrack.jetbrains.com/issue/WI-50366

Yes, fixed with latest PHPStorm update, not showing anymore

Fix has been rollbacked according to https://youtrack.jetbrains.com/issue/WI-50201#focus=streamItem-27-3922274.0-0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sebastianbergmann picture sebastianbergmann  ยท  4Comments

klesun picture klesun  ยท  4Comments

rentalhost picture rentalhost  ยท  4Comments

keradus picture keradus  ยท  4Comments

ezzatron picture ezzatron  ยท  3Comments