1

I tried using PHPUnit 9 but it is not supporting the latest version of PHP above 8.0 I am receiving this following error

Fatal error: Uncaught Error: Call to undefined function each() in C:\xampp\php\pear\PHPUnit\Util\Getopt.php:80 Stack trace: #0 C:\xampp\php\pear\PHPUnit\TextUI\Command.php(242): PHPUnit_Util_Getopt::getopt(Array, 'd:c:hv', Array) #1 C:\xampp\php\pear\PHPUnit\TextUI\Command.php(138): PHPUnit_TextUI_Command->handleArguments(Array) #2 C:\xampp\php\pear\PHPUnit\TextUI\Command.php(129): PHPUnit_TextUI_Command->run(Array, true) #3 C:\xampp\php\phpunit(46): PHPUnit_TextUI_Command::main() #4 {main} thrown in C:\xampp\php\pear\PHPUnit\Util\Getopt.php on line 80

O. Jones
  • 103,626
  • 17
  • 118
  • 172
  • `each()` is now deprecated. – Markus Zeller Jun 22 '22 at 11:13
  • 2
    I don't think you're actually using the latest version of PHPUnit 9. Getopt.php no longer exists in the repository. https://github.com/sebastianbergmann/phpunit/issues/4629 has some suggestions – aynber Jun 22 '22 at 11:45
  • is there any solution for it? or any other platform where we can test WordPress Plugins – Mehuol Dhanji Jun 22 '22 at 11:46
  • @aynber I have rechecked it, I am using PHPUnit 9.5.21. And I used the following command `➜ composer require --dev phpunit/phpunit ^9` to install in my root directory **C:\xampp\htdocs\test** and when I try to run the command `phpuni` in my plugin directory **C:\xampp\htdocs\test\wp-content\plugins\mypluginname** then it gives me this error. I am not sure where I am making mistake. – Mehuol Dhanji Jun 22 '22 at 11:59

1 Answers1

0

Ensure that you don't have a Global package installed with a lower version of PHPUnit.

Check this answer to find the globally installed packages.

cd $(composer -n config --global home) && ls -la vendor

Maybe you are calling the global rather than the project one.
In case you can remove it with

composer global remove phpunit

I suppose your environment PATH variable includes the global Composer folder, so by default phpunit calls that one.
Otherwise, use ./vendor/bin/phpunit (from the directory C:\xampp\htdocs\test) to call the specific version that you installed inside the project.

Kamafeather
  • 8,663
  • 14
  • 69
  • 99