Laravel undefined testing method

I am trying to write tests in laravel, but I can not even run the test, bcs example I get an error:

λ phpunit PHP Fatal error: Uncaught Error: Call to undefined method PHPUnit_Util_Configuration::getTestdoxGroupConfiguration() in E:\www\ikcms\vendor\phpunit\phpunit\src\TextUI\TestRunner.php:1042 Stack trace: #0 E:\www\ikcms\vendor\phpunit\phpunit\src\TextUI\TestRunner.php(163): PHPUnit_TextUI_TestRunner->handleConfiguration(Array) #1 E:\xampp\php\pear\PHPUnit\TextUI\Command.php(176): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array) #2 E:\xampp\php\pear\PHPUnit\TextUI\Command.php(129): PHPUnit_TextUI_Command->run(Array, true) #3 E:\xampp\php\phpunit(46): PHPUnit_TextUI_Command::main() #4 {main} thrown in E:\www\ikcms\vendor\phpunit\phpunit\src\TextUI\TestRunner.php on line 1042 Fatal error: Uncaught Error: Call to undefined method PHPUnit_Util_Configuration::getTestdoxGroupConfiguration() in E:\www\ikcms\vendor\phpunit\phpunit\src\TextUI\TestRunner.php:1042 Stack trace: #0 E:\www\ikcms\vendor\phpunit\phpunit\src\TextUI\TestRunner.php(163): PHPUnit_TextUI_TestRunner->handleConfiguration(Array) #1 E:\xampp\php\pear\PHPUnit\TextUI\Command.php(176): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array) #2 E:\xampp\php\pear\PHPUnit\TextUI\Command.php(129): PHPUnit_TextUI_Command->run(Array, true) #3 E:\xampp\php\phpunit(46): PHPUnit_TextUI_Command::main() #4 {main} thrown in E:\www\ikcms\vendor\phpunit\phpunit\src\TextUI\TestRunner.php on line 1042 

Of course, this happens after laravel is loaded.

Laravel Version: 5.3 PHPUnit: 5.0

+6
source share
4 answers

If you use phpunit for several projects, it is often easier not to contact the globally installed phpunit, but to run it from the project provider folder.

You can check your project with:

 composer info phpunit/phpunit 

(If you see [InvalidArgumentException] Package phpunit/phpunit not found , then I would composer require phpunit/phpunit --dev )

Since Laravel includes phpunit by default , you will most likely be able to run

 ./vendor/bin/phpunit … 

as well as

 composer exec 'phpunit …' 

and you can be sure that you are using the phpunit version specified in this composer.json project.

+3
source

I get the same error before updating Laravel dependencies implementing phpunit. The update gives PHPUnit version 5.7.6 instead of version 5.6. *. If you use PHPUnit in your computer path, it will give you this error. I think this will be fixed, but for now you can execute PHPUnit with the binary code included in your Composer provider by writing php vendor/bin/phpunit in the root of your project. It works for me, you can try.

+1
source

As @ julien-metral said, the version of PHPUnit installed globally on your computer is older than the version used in Laravel 5.4. You can update it by editing the ~/.composer/composer.json file and changing the phpunit/phpunit dependency version to

 "phpunit/phpunit": "~5.0", 

After that, you should run composer global update .

0
source

If you are on Windows. Just create phpunit.bat next to phpunit.xml and then put this script in phpunit.bat.

CALL vendor \ bin \ phpunit

that's all. Then just try running phpunit.

0
source

Source: https://habr.com/ru/post/1014367/


All Articles