Framework: PHP Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php:933

Created on 17 Dec 2018  Â·  23Comments  Â·  Source: laravel/framework

php 7.2
laravel 5.6
phpunit 7.4

test_code
public function testGetMenusTwoRolesHaveRepeatMenus()
{
$user = factory(User::class)->create();
$role0 = factory(Role::class)->create();
$role1 = factory(Role::class)->create();

    $userRepo = new UserRepository($user);
    $userRepo->addRoles([$role0->id, $role1->id]);

    $menu = 'menu';
    $menu0 = factory(Menu::class)->create();
    $menu1 = factory(Menu::class)->create();
    $menu2 = factory(Menu::class)->create();
    $roleRepo0 = new RoleRepository($role0);
    $roleRepo1 = new RoleRepository($role1);
    $roleRepo0->addMenus([$menu0->id, $menu2->id]);
    $roleRepo1->addMenus([$menu1->id, $menu2->id]);

    //var_dump(111);
    $userMenus = $userRepo->getMenus();
   // var_dump();
    $this->assertEquals(3, $userMenus->count());
    $userMenus->each(function($userMenu, $key) use($menu, $menu0, $menu1, $menu2) {
        $menu = $menu.$key;
        var_dump($userMenu->name) ;
        var_dump($name = $$menu->name) ;
        $this->assertEquals($userMenu->name, $menu0->name);  //this line is error
    });
}

PHPUnit 7.4.5 by Sebastian Bergmann and contributors.

E.......... 11 / 11 (100%)

Time: 12.36 seconds, Memory: 6.00MB

There was 1 error:

1) Tests\Unit\Backstage\UserTest::testGetMenusTwoRolesHaveRepeatMenus
PHPUnit\Framework\Exception: PHP Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php:933
Stack trace:

0 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(773): Illuminate\Container\Container->notInstantiable('Illuminate\Cont...')

1 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(646): Illuminate\Container\Container->build('Illuminate\Cont...')

2 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(601): Illuminate\Container\Container->resolve('Illuminate\Cont...', Array)

3 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(734): Illuminate\Container\Container->make('Illuminate\Cont...', Array)

4 /home/vagrant/code/portal/backend/vendor/laravel/framework/sr in /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 933

Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php:933
Stack trace:

0 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(773): Illuminate\Container\Container->notInstantiable('Illuminate\Cont...')

1 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(646): Illuminate\Container\Container->build('Illuminate\Cont...')

2 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(601): Illuminate\Container\Container->resolve('Illuminate\Cont...', Array)

3 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(734): Illuminate\Container\Container->make('Illuminate\Cont...', Array)

4 /home/vagrant/code/portal/backend/vendor/laravel/framework/sr in /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 933

PHP Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php:933
Stack trace:

0 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(773): Illuminate\Container\Container->notInstantiable('Illuminate\Cont...')

1 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(646): Illuminate\Container\Container->build('Illuminate\Cont...')

2 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(601): Illuminate\Container\Container->resolve('Illuminate\Cont...', Array)

3 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(734): Illuminate\Container\Container->make('Illuminate\Cont...', Array)

4 /home/vagrant/code/portal/backend/vendor/laravel/framework/sr in /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 933

Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php:933
Stack trace:

0 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(773): Illuminate\Container\Container->notInstantiable('Illuminate\Cont...')

1 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(646): Illuminate\Container\Container->build('Illuminate\Cont...')

2 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(601): Illuminate\Container\Container->resolve('Illuminate\Cont...', Array)

3 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(734): Illuminate\Container\Container->make('Illuminate\Cont...', Array)

4 /home/vagrant/code/portal/backend/vendor/laravel/framework/sr in /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 933

Most helpful comment

Heya, unfortunately we don't support this version anymore. Can you please try to upgrade to the latest version and see if your problem persists? If so feel free to reply and we'll try to have a look.

@anthonygore did upgrading Laravel fix it?

laravel 5.7 and 5.8 have this problem too

All 23 comments

@desertnightsky thinks for your reply. sorry i don't understand。 getMenus() return Collection (use
unique(),i try use foreach then $this->assertEquals($userMenu->name, $menu0->name) it‘s ok .But i use each then
$this->assertEquals($userMenu->name, $menu0->name) it's Exception

Heya, unfortunately we don't support this version anymore. Can you please try to upgrade to the latest version and see if your problem persists? If so feel free to reply and we'll try to have a look.

@driesvints can you clarify... the version of what is not supported? Upgrade what to the latest? I've also got this issue on Laravel 5.6, PHPUnit 7.2.

@anthonygore we don't support 5.6 anymore: https://laravel.com/docs/5.7/releases#support-policy

Ah okay, thanks

@anthonygore did upgrading Laravel fix it?

I can't remember, sorry! But I'm still at Laravel 5.6 so I must have found another solution

Heya, unfortunately we don't support this version anymore. Can you please try to upgrade to the latest version and see if your problem persists? If so feel free to reply and we'll try to have a look.

@anthonygore did upgrading Laravel fix it?

laravel 5.7 and 5.8 have this problem too

Hi, did anyone fixed this issue in Laravel 5.6 with PHP 7.2? I have an interface which is being used in a constructor and that is causing this error. I have read that adding your class in config/app.php will resolve this error but how can we add interface in config/app.php?

Illuminate\Contracts\Container\BindingResolutionException: Target [...] is not instantiable while building [App\Http\Controllers\...]. in file /home/apidev/public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 933

any solution for this issue yet? , working with Laravel 5.8 and php 7.3.6

PHP Fatal error:  Cannot redeclare Mockery_4_Illuminate_Support_Facades_Hash::shouldReceive() in /Users/mohammed/projects/laravel-test/server/vendor/mockery/mockery/library/Mockery/Loader/EvalLoader.php(34) : eval()'d code on line 963
PHP Fatal error:  Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /Users/mohammed/projects/laravel-test/server/vendor/laravel/framework/src/Illuminate/Container/Container.php:958

laravel: 5.8.21
phpunit: 8.2.1
php: 7.3.4

i'm getting this error (after adding https://github.com/sebastiaanluca/laravel-auto-morph-map via composer). when i run phpunit i get a few fatal errors. not sure how/why the package would have messed it up. so any help would be great!

PHP Fatal error:  Cannot declare class App\Middleware\FixedStartSession, because the name is already in use in /app/app/Http/Middleware/FixedStartSession.php on line 21

PHP Fatal error:  Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /app/vendor/laravel/framework/src/Illuminate/Container/Container.php:958

Fatal error: Cannot declare class App\Middleware\FixedStartSession, because the name is already in use in /app/app/Http/Middleware/FixedStartSession.php on line 21

Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /app/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 958

Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /app/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 958

laravel 5.8
php 7.3
phpunit 8.2.3

Problem persists.

Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Http\Kernel] is not instantiable.

This is still an issue on Laravel 6.0 (PHP 7.2, PHPUnit 8.3.5)

Auch, last comment 2 hours ago.
I also experienced this issue right now. Latest Laravel, PHPUnit 8.4.1, PHP 7.3.
I tried to run:
phpunit --testdox tests/Feature/Auth (that's a dir with tests)

How come this got closed when error still occurs in 5.8? Can you reopen this issue @driesvints please?

hey, 2k20 still not fixed, any hint?

I've seen this particular error in _strange cases_ a few times. They always "went" away after some code was fixed.

So this is very unspecific but I've seen cases where code had an error, like a PHPUnit listener had a typo or something, and the actual error was _overshadowed_ by this one.

What helped me is: debugging. I can only recommend stepping through your code and trying to pinpoint when it starts to throw the exceptions, that's how I found some bugs (in my / other, not Laraval) code.

I'll try to remember when I encounter it the next time to try to figure out what is particularly overshadowing here. Maybe it's a problem with the exception handler/the debug component, a combination of thereof, etc.

HTH

I'm having this same issue but odly only when I run phpunit --testdox it works perfectly when running phpunit.

All "Report test execution progress in TestDox format" does is display the output in a different format. Which is confusing.

I'm recently moved to a new laptop using Laravel Valet after previously using Homestead (which worked perfectly) so it may be a setup issue.

I'm having this same issue but odly only when I run phpunit --testdox it works perfectly when running phpunit.

Similar here. phpunit --testdox is working but phpunit --testdox-xml is not (throwing the BindingResolutionException). L5.5 PHPUnit 6.5

When I delete setUp() function from my test, there is no problem anymore. Even with empty setUp() there is the error.

When I delete setUp() function from my test, there is no problem anymore. Even with empty setUp() there is the error.

That makes complete sense. You need to be calling parent::setUp(). If you delete it the parent will be called automatically, if it's empty then the parent won't be called.

Wow, you're right. Such a stupid mistake. Thank you very much!

This might not help, but this "PHP Fatal error" error message (or something like it) was happening for me when I was running some Laravel project (Laravel 5.8) tests with PHPUnit (PHPUnit 7.5.20) using a service account user.

Something that resolved this issue for me involved deleting the following PHPUnit cache file and then running the phpunit tests again: rm .phpunit.result.cache. This file was found in the base directory of my Laravel project.

Hope that helps!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lzp819739483 picture lzp819739483  Â·  3Comments

progmars picture progmars  Â·  3Comments

gabriellimo picture gabriellimo  Â·  3Comments

jackmu95 picture jackmu95  Â·  3Comments

felixsanz picture felixsanz  Â·  3Comments