PHPUNIT 6.* Error

I recently upgraded PhpUnit in my PhpStorm project using Composer.  When running any unit test I get this error:
Can not parse PHPUnit version output:
Fatal error: Cannot use PHPUnit\Framework\MockObject\Stub as Stub because the name is already in use in phar://D:/dev/common-tools/phpunit/phpunit-6.5.0.phar/phpunit-mock-objects/Builder/InvocationMocker.php on line 16

Tried switching to the phpunit.phar in settings\Languages & Frameworks\PHP\Test Frameworks.  Clicked 'Download phpunit.phar' and changed to 'Path to phpunit.phar'

Got the same result then tried older versions

6.5.0 - same result

6.0.0 - similar error:
Can not parse PHPUnit version output: Fatal error: Cannot use PHPUnit\Framework\Exception as Exception because the name is already in use in phar://D:/dev/common-tools/phpunit/phpunit-6.0.0.phar/phpunit/Framework/Constraint/ExceptionMessageRegularExpression.php on line 12

5.7.9  - WORKS!

Sounds like namespace issus in PHPUnit.  I can live with 5.7.9, but it would be nice to be able to run the latest versions.  Does anyone know a solution?

 

 

 

0
6 comments
Avatar
Permanently deleted user

Hello,

What PhpStorm version do you use?

1
Avatar
Permanently deleted user

PhpStorm 2017.3.2
Build #PS-173.4127.29, built on December 22, 2017

JRE: 1.8.0_152-release-1024-b8 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0

PHP: 7.0.10
server: WAMP / apache 2.4.24

I wondered if I had a conflicting version of PHP_Unit installed but haven't found anything.

thanks.

0

What if you run the test via CMD? Does it run when using the v6 PHPUnit PHAR?
If it doesn't, it must be something wrong with the test itself. Maybe you could share it with us?

0
Avatar
Permanently deleted user

I have found a solution to this problem and I have answered it on Stack. It answered to running "--version" but works with any argument. 

https://stackoverflow.com/questions/47909147/phpunit-install-error-cannot-use-phpunit-framework-mockobject-stub-as-stub/48388364#48388364

1
Avatar
Permanently deleted user

Forgive me, I'm still bewildered.  This issue manifests when running via CMD either against the phar or the composer installation. Happens for any test or command line.

I'm not sure I understand the solution posted on Stack.  Here's what I have tried.

Where working directory is the same as location of my phar files:

>php phpunit-6.5.0.phar --version

Fatal error: Cannot use PHPUnit\Framework\MockObject\Stub as Stub because the name is already in use in phar://D:/dev/common-tools/phpunit/phpunit-6.5.0.phar/phpunit-mock-objects/Builder/InvocationMocker.php on line 16

>php phpunit-6.0.0.phar --version

Fatal error: Cannot use PHPUnit\Framework\Exception as Exception because the name is already in use in phar://D:/dev/common-tools/phpunit/phpunit-6.0.0.phar/phpunit/Framework/Constraint/ExceptionMessageRegularExpression.php on line 12

D:\dev\common-tools\phpunit>php phpunit-5.7.9.phar --version
PHPUnit 5.7.9 by Sebastian Bergmann and contributors.

I think it does the same when run from the composer directory, vendor/phpunit/phpunit, as php phpunit --version, but I'll need to reinstall the later version and test again.

 

 

0
Avatar
Permanently deleted user

When you are running PHPUnit you will have a bin folder inside your project.

For instance I had my application called "my_project" inside my github repository called "SymfonyTest7".

When the composer installation had finished it saved the PHPUnit file in the bin folder:

C:\Users\wamp\www\SymfonyTest7\my_project\bin\

For it to work I had to be inside the application folder. In this case "my_project"

> cd my_project

>php bin/PHPUnit --version

That was what my answer was saying. Ensure your in the folder of your application and not your bin folder.

 

1

Please sign in to leave a comment.