Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel testing undefined method

I try to write tests in laravel, but I can't even run example test, bcs I get 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, it happens after downloading laravel.

Laravel version: 5.3 PHPUnit: 5.0

like image 873
Ivan Avatar asked Jan 24 '17 12:01

Ivan


2 Answers

If you use phpunit across multiple projects it's often easier to not mess with a globally installed phpunit but to run it from your project's vendor folder.

You can check your project with:

composer info phpunit/phpunit

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

Since Laravel includes phpunit by default you more than likely can run

./vendor/bin/phpunit …

and also

composer exec 'phpunit …'

and you can be certain that you're running the version of phpunit specified in that project's composer.json.

like image 137
Mark Fox Avatar answered Nov 09 '22 18:11

Mark Fox


I get the same error before upgrading Laravel's dependencies inculding phpunit. The update gives the version 5.7.6 of PHPUnit instead of the version 5.6.*. If you use the PHPUnit of your computer path it will gives you this error. I think it will be fixed but for the moment you can execute PHPUnit with the binary included in your Composer's vendor by writing php vendor/bin/phpunit on your project root. For me it works, you can try it.

like image 37
Julien METRAL Avatar answered Nov 09 '22 18:11

Julien METRAL