Uncaught exception 'Illuminate\Contracts\Container\BindingResolutionException' #11192

PhillippOhlandt opened this Issue Dec 4, 2015 · 27 comments


None yet


when I install a fresh version of Laravel 5.1 through the Installer and run phpunit I get:

Fatal error: Call to undefined method PHPUnit_Framework_TestResult::warningCount() in /home/vagrant/.composer/vendor/phpunit/phpunit/src/TextUI/ResultPrinter.php on line 185
PHP Fatal error:  Uncaught exception 'Illuminate\Contracts\Container\BindingResolutionException' with message 'Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable.' in /home/vagrant/Private/test/vendor/laravel/framework/src/Illuminate/Container/Container.php:745
Stack trace:
#0 /home/vagrant/Private/test/vendor/laravel/framework/src/Illuminate/Container/Container.php(627): Illuminate\Container\Container->build('Illuminate\\Cont...', Array)
#1 /home/vagrant/Private/test/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(674): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#2 /home/vagrant/Private/test/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(154): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
#3 /home/vagrant/Private/test/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(79): Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler()
#4 /home/vagrant/Private/test/vendor/ in /home/vagrant/Private/test/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 745

Same error on php7.0 and php5.6.


What version of phpunit?


Only 4.x, and 5.0 are known to work with laravel.


5.1+ don't work correctly atm.


php 5.6.13 and laravel 5.1.23


What version of phpunit?


PHPUnit 4.8.19


Hmmm. Thanks for reporting. Ping @taylorotwell.

@GrahamCampbell GrahamCampbell added the bug label Dec 4, 2015

when I install a fresh version of Laravel 5.1 through the Installer

The installer doesn't generate .env, and most likely due to APP_KEY not being set due to the missing file, PHPUnit throws this exception.

Could you try running:

composer run-script post-root-package-install
php artisan key:generate

and run phpunit again.


@crynobone the .env file was generated with the installer, see:

Phillipps-MacBook-Pro ~/Private/Code/test$ cat .env




screen shot 2015-12-04 at 7 34 34 pm

Works fine with composer create-project.


Weird, tried it with 'composer create-project' and got the same error.


When i try it inside the vagrant vm, then it works, lol. But the version installed by the laravel Installer still fails.


could it be something installed in your composer global that could trigger the problem. That would explain why it work fine in vagrant vm.


I dont think so because the installer version fails and the composer create-project doesn't fail in the vm. But what's the difference?


Another weird thing is: I have to use 'sudo' on the laravel installer one when i run phpunit.


I solved it!

First I had to remove the vendor folder and install everything again, then I had to remove phpunit globally and set an alias for phpunit so it uses the local phpunit from the vendor folder. Now everything work.


The removal of vendor folder did not work for me. However, I was able to resolve the issue by upgrading phpunit from 4.8.19 to 5.0.


@husonghua I had to remove it because of wrong permissions on the binary. Reinstalling through composer set the right permissions then.


@phillippOhlandt, what version of PHPUnit are you using then? I'm having this problem when I run unit tests.

Laravel 5.1, PHPUnit 5.1.


Looks like a project my project lives inside had an autoloader which used their version of PHPUnit's files which were PHPUnit 5.0. Upgraded them to PHPUnit 5.1 and my issues are gone.


I solved this issue in my computer changing the phpunit version in my composer.json file.
(I have composer installed in my home directory, so I edited ~/.composer/composer.json file)

"require": {
"phpunit/phpunit": "~4.0"

Cause is the default version when you create a project (via composer or laravel new).
I guess I had this trouble because phpunit called ~/.composer/vendor/bin instead the local project. Actually the error was throw in ~/.composer/vendor/phpunit/phpunit/src/TextUI/ResultPrinter.php (See logs)


composer update 

At the end, I guess is more simple use vendor/bin directory to use phpunit

matiux commented Dec 28, 2015

I use Debian with phpunit 5.1.3 installed as a command in my system and I have the same problem:
Call to undefined method PHPUnit_Framework_TestResult::warningCount() in /usr/share/php/PHPUnit/TextUI/ResultPrinter.php on line 185

How can I solve?


I had the same problem. Updating to 5.1.3 fixed it for me.

JSheils commented May 1, 2016

I had the same problem and solved it by upgrading to phpunit 5.3.2. I suspect it has less to do with the version than with re-installing phpunit after maybe composer missed something the first time.

canaan5 commented May 9, 2016

is there no real fix for this error yet?


ResultPrinter.php issue has been fixed in newer versions. My issue is fixed after updating version of phpunit to 5.0 in composer.json and composer update.

"phpunit/phpunit": "~5.0",

tpraxl commented Jul 14, 2016 edited

I can confirm that updating in composer.json works.
My issue was:

  • laravel 5.2.* application with homestead
  • composer.json defined phpunit version to be ~4.0
  • local (host) system: linux, phpunit version 4.8.23
  • vagrant (guest) system: phpunit version 5.1.3 (installed with sudo apt-get install -y phpunit in {project-root}/after.sh)

phpunit would work when called on my local system, but not inside vagrant vm. Inside the vm it would fail with the message PHP Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable.

After changing composer.json to the below and running composer update, everything works fine again. Remember that I didn't touch my installed phpunit versions.

Update composer.json:

"require-dev": {
   "phpunit/phpunit": "~5.0", 

then run

composer update

Thanks for your hints. Helped me a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment