search

Home  >  Q&A  >  body text

PhpUnit 9 fails on php 8+

I tried using PHPUnit 9 but it does not support the latest version of PHP above 8.0 I get the 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} throws

in C:\xampp\php\pear\PHPUnit\Util\Getopt.php on line 80
P粉505917590P粉505917590301 days ago422

reply all(1)I'll reply

  • P粉010967136

    P粉0109671362024-01-29 10:28:15

    Make sure you are not using an older version of PHPUnit to install the global package.

    Check this answer to find globally installed packages.

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

    Maybe you are calling global instead of project.
    If you can remove it using

    composer global remove phpunit

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

    reply
    0
  • Cancelreply