Framework: Uncaught exception 'Illuminate\Contracts\Container\BindingResolutionException'

Created on 4 Dec 2015  路  28Comments  路  Source: laravel/framework

Hey,

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.

bug

Most helpful comment

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",

All 28 comments

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.

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
APP_ENV=local
APP_DEBUG=true
APP_KEY=V4Y9bY6YFVHzPQEALF2qzfz3IqbUAuDW

DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

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)

Then:

composer update 

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

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.

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.

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",

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.

@GrahamCampbell another example of why this issue still exists, people still running into it way after you've closed this. I even have this duplicated with phpunit 6

Was this page helpful?
0 / 5 - 0 ratings