Skip to content

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 #26874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
missing0023 opened this issue Dec 17, 2018 · 25 comments

Comments

@missing0023
Copy link

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...')
    ReflectionException #1 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(646): Illuminate\Container\Container->build('Illuminate\Cont...')
    Fix Fatal error on Class 'Illuminate\Filesystem' load #2 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(601): Illuminate\Container\Container->resolve('Illuminate\Cont...', Array)
    Migration doesn't account for prefix when checking if migration table exists [bug] #3 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(734): Illuminate\Container\Container->make('Illuminate\Cont...', Array)
    Update src/Illuminate/Events/Dispatcher.php #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...')
    ReflectionException #1 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(646): Illuminate\Container\Container->build('Illuminate\Cont...')
    Fix Fatal error on Class 'Illuminate\Filesystem' load #2 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(601): Illuminate\Container\Container->resolve('Illuminate\Cont...', Array)
    Migration doesn't account for prefix when checking if migration table exists [bug] #3 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(734): Illuminate\Container\Container->make('Illuminate\Cont...', Array)
    Update src/Illuminate/Events/Dispatcher.php #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...')
    ReflectionException #1 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(646): Illuminate\Container\Container->build('Illuminate\Cont...')
    Fix Fatal error on Class 'Illuminate\Filesystem' load #2 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(601): Illuminate\Container\Container->resolve('Illuminate\Cont...', Array)
    Migration doesn't account for prefix when checking if migration table exists [bug] #3 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(734): Illuminate\Container\Container->make('Illuminate\Cont...', Array)
    Update src/Illuminate/Events/Dispatcher.php #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...')
    ReflectionException #1 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(646): Illuminate\Container\Container->build('Illuminate\Cont...')
    Fix Fatal error on Class 'Illuminate\Filesystem' load #2 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(601): Illuminate\Container\Container->resolve('Illuminate\Cont...', Array)
    Migration doesn't account for prefix when checking if migration table exists [bug] #3 /home/vagrant/code/portal/backend/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(734): Illuminate\Container\Container->make('Illuminate\Cont...', Array)
    Update src/Illuminate/Events/Dispatcher.php #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
@missing0023
Copy link
Author

missing0023 commented Dec 17, 2018

@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

@driesvints
Copy link
Member

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
Copy link

@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.

@driesvints
Copy link
Member

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

@anthonygore
Copy link

Ah okay, thanks

@charlie-callahan
Copy link

@anthonygore did upgrading Laravel fix it?

@anthonygore
Copy link

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

@missing0023
Copy link
Author

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

@mohsinintazar
Copy link

mohsinintazar commented May 29, 2019

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

@secmohammed
Copy link

secmohammed commented Jun 7, 2019

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

@thejacer87
Copy link

thejacer87 commented Jun 11, 2019

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

@stafot
Copy link

stafot commented Jul 2, 2019

laravel 5.8
php 7.3
phpunit 8.2.3

Problem persists.

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

@ggdx
Copy link

ggdx commented Oct 18, 2019

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

@DWMcload
Copy link

DWMcload commented Oct 18, 2019

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)

@Mpreyzner
Copy link

Mpreyzner commented Oct 25, 2019

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

@meinder-a
Copy link

hey, 2k20 still not fixed, any hint?

@mfn
Copy link
Contributor

mfn commented Jan 2, 2020

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

@robjbrain
Copy link
Contributor

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.

@kaphert
Copy link

kaphert commented Feb 5, 2020

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

@abronin
Copy link

abronin commented Apr 29, 2020

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

@robjbrain
Copy link
Contributor

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.

@abronin
Copy link

abronin commented Apr 30, 2020

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

@summea
Copy link

summea commented Aug 20, 2020

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!

@trckster
Copy link
Contributor

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!

That was helpful enough, thanks! The problem was I tried to run tests inside container and user had no permissions to create .phpunit.result.cache, so php vendor/bin/phpunit --do-not-cache or php artisan test --do-not-cache was my solution

@summea
Copy link

summea commented Jan 18, 2022

@trckster Glad to hear that the earlier post was kind of helpful! After seeing your post, I wonder if I also was running into a permissions issue with that cache file at the time. Thanks for taking the time to post about your situation, too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests