Framework: Laravel 5.1 PHPUnit Issue with PHP 7 and PHPUnit 5.1.3

Created on 24 Apr 2016  Â·  13Comments  Â·  Source: laravel/framework

I decided to move to Ubuntu 16.04 where the default PHP version is PHP7 and for this PHPUnit 5.1.3 was installed. I installed Laravel 5.1 and run the phpunit and it shows the following error. What will be the solution for this situation?

PHPUnit 4.8.24 by Sebastian Bergmann and contributors.

...                                                                 3 / 3 (100%)

Time: 294 ms, Memory: 14.00Mb


PHP Fatal error:  Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php:749
Stack trace:
#0 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(631): Illuminate\Container\Container->build('Illuminate\\Cont...', Array)
#1 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(674): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#2 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(154): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
#3 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(79): Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler( in /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 749
PHP Fatal error:  Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php:749
Stack trace:
#0 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(631): Illuminate\Container\Container->build('Illuminate\\Cont...', Array)
#1 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(674): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#2 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(154): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
#3 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(79): Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler( in /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 749

Most helpful comment

yes, there might be some issues with the phpunit installation. earlier i installed via apt-get (sudo apt-get install phpunit) now phar. Now the installed version is PHPUnit 5.3.2.

These are the steps i followed, this might help someone else who may face this issue

  • Uninstalled phpunit:

sudo apt-get remove phpunit

  • Uninstall phpunit and it's dependencies

sudo apt-get remove --auto-remove phpunit

*Purged config/data too

sudo apt-get purge phpunit
sudo apt-get purge --auto-remove phpunit

then followed the installation instruction from https://phpunit.de/manual/current/en/installation.html

$ wget https://phar.phpunit.de/phpunit.phar
$ chmod +x phpunit.phar
$ sudo mv phpunit.phar /usr/local/bin/phpunit
$ phpunit --version

Laravel 5.1 is working fine with the PHPUnit 5.3.2 on PHP 7

All 13 comments

We don't support phpunit 5 officially until L5.3.

Does this happen only with code coverage enabled?

@GrahamCampbell thanks for the response.

the code coverage was not enabled, i just ran the phpunit command. somehow i overlooked, but while i run the command phpunit it shows that PHPUnit 4.8.24 is running but the phpunit --version shows that my phpunit version is PHPUnit 5.1.3

I read some other issues and you mentioned that phpunit 5 is not supported and may be available at L5.3. But on the phppunit website it is mentioned that phpunit 4.8 does not cover the php7.

My point is Ubuntu has released new LTS version and the default php version has been updated to php7. So from now on all the users will face this same issue. What will be the solution then?

phpunit it shows that PHPUnit 4.8.24 is running but the phpunit --version shows that my phpunit version is PHPUnit 5.1.3

Sounds like you have a problem with your phpunit install, causing this issue.

yes, there might be some issues with the phpunit installation. earlier i installed via apt-get (sudo apt-get install phpunit) now phar. Now the installed version is PHPUnit 5.3.2.

These are the steps i followed, this might help someone else who may face this issue

  • Uninstalled phpunit:

sudo apt-get remove phpunit

  • Uninstall phpunit and it's dependencies

sudo apt-get remove --auto-remove phpunit

*Purged config/data too

sudo apt-get purge phpunit
sudo apt-get purge --auto-remove phpunit

then followed the installation instruction from https://phpunit.de/manual/current/en/installation.html

$ wget https://phar.phpunit.de/phpunit.phar
$ chmod +x phpunit.phar
$ sudo mv phpunit.phar /usr/local/bin/phpunit
$ phpunit --version

Laravel 5.1 is working fine with the PHPUnit 5.3.2 on PHP 7

Laravel 5.1 is working fine with the PHPUnit 5.3.2 on PHP 7

While that may be true in most cases, we only officially support PHPUnit 4.X in Laravel 5.1 and 5.2. We officially switch to PHPUnit 5.x in L5.3 since we drop PHP 5.5 support then, allowing us to do that.

@nasirkhan 's solution saved the day for me. I recommend it if anyone is trying to use PHPUnit with a Laravel 5.1, 5.2 project on Ubuntu 16.04.

Something that worked for me…

  1. Remove your vendor folder and your composer.lock:

shell rm -r vendor rm composer.lock

  1. Remove the line in composer.json where phpunit is defined.
  2. Install your composer dependencies:

shell composer install

  1. Require phpunit:

shell composer require phpunit/phpunit --dev

What should happen is it will pull in the newer version which will work with PHP7, so you should be able to just run phpunit from the project root without any errors.

Good job @marando

Thank you @marando It was very useful!

After following @marando instructions, I got the following message:

phpunit/phpunit 5.4.6 requires ext-dom * -> the requested PHP extension dom is missing from your system.

To solve this issue, just run one of the following commands, according to your PHP version:
sudo apt-get install php5.6-xml
sudo apt-get install php7.0-xml

It seems that this php xml package installs the phpunit dependencies.
I got this from this link http://stackoverflow.com/questions/30868608/laravel-production-issue-updating-composer-with-laravel-4-1-x

Same deal for me. I'm running Laravel 5.2, PHP7.0 on Ubuntu 16.04 and updating to phpunit 5 worked for me to resolve. Already had php7.0-xml installed.

I'm seeing this in PHPUnit 6.0.13 Laravel 5.4.21 PHP 7.1

You can try this => sudo apt-get install php-xml
that did the trick for me

Was this page helpful?
0 / 5 - 0 ratings