framework: [5.1] [5.2] Error handler hides PHPUnit errors
I discovered a bug in PHPUnit (https://github.com/sebastianbergmann/phpunit/issues/1935) while working on a Laravel 5.1 project:
$ composer create-project laravel/laravel --prefer-dist
$ cd laravel
$ ./vendor/bin/phpunit --coverage-html /does-not-exist
PHPUnit 4.8.16 by Sebastian Bergmann and contributors.
.
Time: 429 ms, Memory: 18.75Mb
OK (1 test, 2 assertions)
Generating code coverage report in HTML format ...PHP Fatal error: Uncaught exception 'Illuminate\Contracts\Container\BindingResolutionException' with message 'Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable.' in /home/sb/test/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php:745
Stack trace:
#0 /home/sb/test/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(627): Illuminate\Container\Container->build('Illuminate\\Cont...', Array)
#1 /home/sb/test/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(674): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#2 /home/sb/test/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(154): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
#3 /home/sb/test/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(79): Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler()
#4 [internal function]: Illuminate\Foundation\Bootstrap\Handle in /home/sb/test/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 745
PHP Fatal error: Uncaught exception 'Illuminate\Contracts\Container\BindingResolutionException' with message 'Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable.' in /home/sb/test/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php:745
Stack trace:
#0 /home/sb/test/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(627): Illuminate\Container\Container->build('Illuminate\\Cont...', Array)
#1 /home/sb/test/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(674): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#2 /home/sb/test/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(154): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
#3 /home/sb/test/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(79): Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler()
#4 /home/sb/test/laravel/vendor/laravel/framework/src/Illumina in /home/sb/test/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 745
The reason why I am opening this ticket is because nowhere in the stacktrace do I see PHPUnit and/or PHP_CodeCoverage. The fact that PHPUnit was not handling an exception raised by PHP_CodeCoverage was not apparent at all from looking at the error I got. Maybe the error handler is too eager?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 7
- Comments: 95 (30 by maintainers)
Commits related to this issue
- test with processIsolation="true" travis build fails when generating code coverage only on php 7.2 see also: https://github.com/laravel/framework/issues/10808 — committed to razorbacks/laravel-shibboleth by jpuck 7 years ago
- test with processIsolation="true" travis build fails when generating code coverage only on php 7.2 see also: https://github.com/laravel/framework/issues/10808 — committed to razorbacks/laravel-shibboleth by jpuck 7 years ago
- Source a little bit refactored - Source and tests a little bit refactored - Blade directives use contract instead abstract container bind alias - Abstract tests bootstrapper class removed - PHPUnit H... — committed to avto-dev/app-version-laravel by deleted user 6 years ago
I had the same issue. (Using Laravel 5.2) The problem was that i had a newer version of phpunit installed globally (5.4.4). So by running
phpunitcommand the global one was used.Solutions:
./vendor/bin/phpunitinstead;phpunitcommand regularly.Or just don’t globally require PHPUnit.
Hope somebody finds this useful.
Ping @taylorotwell Merciful, God, what kind of begging/bribery/weeping will get this fixed? This issue has beet floating around for years now.Would setting up a Crowdfunder.com help???
Now I gotta go into work Wednesday and explain to my boss, who is not an open-source fan, why it took days to find a trivial error in my config file.
OK (36 tests, 2155 assertions)
Generating code coverage report in PHP format …PHP Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /home/vagrant/repos/toto/vendor/laravel/framework/src/Illuminate/Container/Container.php:895 Stack trace: #0 /home/vagrant/repos/toto/vendor/laravel/framework/src/Illuminate/Container/Container.php(735): Illuminate\Container\Container->notInstantiable(‘Illuminate\Cont…’) #1 /home/vagrant/repos/toto/vendor/laravel/framework/src/Illuminate/Container/Container.php(608): Illuminate\Container\Container->build(‘Illuminate\Cont…’) #2 /home/vagrant/repos/toto/vendor/laravel/framework/src/Illuminate/Container/Container.php(575): Illuminate\Container\Container->resolve(‘Illuminate\Cont…’) #3 /home/vagrant/repos/toto/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(728): Illuminate\Container\Container->make(‘Illuminate\Cont…’) #4 /home/vagrant/repos/toto/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(159): Illumin in /home/vagrant/repos/toto/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 895 PHP Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /home/vagrant/repos/toto/vendor/laravel/framework/src/Illuminate/Container/Container.php:895 Stack trace: #0 /home/vagrant/repos/toto/vendor/laravel/framework/src/Illuminate/Container/Container.php(735): Illuminate\Container\Container->notInstantiable(‘Illuminate\Cont…’) #1 /home/vagrant/repos/toto/vendor/laravel/framework/src/Illuminate/Container/Container.php(608): Illuminate\Container\Container->build(‘Illuminate\Cont…’) #2 /home/vagrant/repos/toto/vendor/laravel/framework/src/Illuminate/Container/Container.php(575): Illuminate\Container\Container->resolve(‘Illuminate\Cont…’) #3 /home/vagrant/repos/toto/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(728): Illuminate\Container\Container->make(‘Illuminate\Cont…’) #4 /home/vagrant/repos/toto/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(159): Illumin in /home/vagrant/repos/toto/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 895
@casperbakker oh the joys of development. Ironically for me changing
processIsolationfromtruetofalsefixed it. Honestly.Love beautiful code? Yea. I have nowhere near the skill, experience or access to internal documentation/procedures/architecture to even begin to start to address this or even explain what’s going on. What exactly in a container?? What’s a BindingResolution and why does it have a special exception. I dunno. I’m not asking for a major enhancement to be delivered tomorrow. I’m asking that a CLEARLY well documented (multiple times), two year old bug to be addressed within the next year (yea, I’d be happy with that). I’m just a poor sap that picked Laravel thinking that this type of bug would be addressed by the Laravel eco-system.
Changing
processIsolation="false"toprocessIsolation="true"fixed this issue for me as well. Now I see the real error of the test.PHPUnit 5.7.22 PHP 7.1.10 Laravel 5.4.36
No need for confirmations please. We know it’s broken. 😉
@jschlies I second what @iget-master said. None of the contributors to Laravel or to other open-source projects are being paid for their efforts. Nor do they owe you anything. It’s one thing to ask for help, but another to demand that they fix something for you, especially with the tone you used.
Tell your boss there’s a problem with a thing on the internet and the only way to fix it is to do some stuff. And if he doesn’t that, tell them they’re free to get the Oracle solution for $1 billion plus a lifetime support contract.
This is still a bug. Think it might help people out to at least reopen it so they know it’s still an unresolved problem. That exclude filter doesn’t fix.
mine wasn’t a syntax error, i install phpunit v5.* globally on my linux machine, so when i run phpunit it uses the default instead of the one with the project so, fixed my by running phpunit like this; vendor/bin/phpunit
@GrahamCampbell @taylorotwell can we re-open this? I’m also still seeing this issue. PHPUnit 6.0.13 by Sebastian Bergmann and contributors.
Runtime: PHP 7.1.3 with Xdebug 2.5.0 Configuration: /home/rof/src/bitbucket.org/waypointbuilding_team/toto/phpunit.ci.xml
…E
Time: 10.05 seconds, Memory: 14.00MB
There was 1 error:
ERRORS! Tests: 12, Assertions: 237, Errors: 1.
i started getting this when i am using a new vps for gitlab runner running
php artisan duskhope someone will find fix for it.
and as some more people facing issue, isn’t time to make issue “open” ?
thanks.
Hi, I’m running:
and it throws an exception when creating code coverage report
any suggestions?
I’m on php7.2 and laravel 5.7 now and it’s still happening.
possibly related, chrome driver has this output:
Same issue, phpunit errors not showing, changing the processIsolation doesn’t change anything either.
Vagrant environment: PHPUnit 6.4.2 PHP 7.1 Laravel 5.5.16
Just to add my fix in case it helps anyone:
Laravel 5.1.45 PHPUnit 4.8.35 PHP 5.5.9 Xdebug 2.2.3
I stepped through PHP_CodeCoverage to find that an exception was being thrown in getData() on the call to addUncoveredFilesFromWhitelist(). A twitter exchange from @s_bergmann suggests:
@user1: In @phpunit, what’s the difference between addUncoveredFilesFromWhitelist="true" and processUncoveredFilesFromWhitelist="true" ?@s_bergmann: You want to use processUncoveredFilesFromWhitelist. If it does not work (legacy code) then use addUncoveredFilesFromWhitelist(from http://stackoverflow.com/questions/29041254/phpunit-coverage-what-is-the-difference-between-adduncoveredfilesfromwhitelist)
So changing phpunit.xml from:
<whitelist processUncoveredFilesFromWhitelist="true">to:
<whitelist addUncoveredFilesFromWhitelist="true">And I’ve got code coverage back with no exception. Not totally sure what I’ve lost, but the end result looks complete to me.
Mine was different phpunit in the system and the application. Removed one from system and updated
composer.jsonto"phpunit/phpunit": "5.*",Now it runs fine. 😃
Hi, I have tried
and
./vendor/bin/phpunitworksLaravel Framework version 5.2.44 PHP 7.0.8-0ubuntu0.16.04.2 PHPUnit 4.8.27
See https://github.com/laravel/laravel/pull/3725.
Thanks everyone. Debugging this with @bretterer, we can see that phpunit is requiring the routes file, which has consequences.
This was happening for me, and it ended up being a permissions problem.
I got the same issue.
I try to catch exception when TestRunner is generating coverage
and got error message:
After change coverage directory permission to 755 from 555, It’s work.
Hope helpful.
@jschlies
Get with the flow of things or don’t use the free software at all. Why are you feeling so entitled that a bug needs to be addressed in the next year or even the next 10 years when you’re using what they develop for free?
There’s documentation for the api, framework and you can just read the source code itself to see how everything works. Not everyone who contributes back to the framework knows how every single part of the framework works.
Does the bug affect you? yes? Is the bug a major breaking problem? yes? no? Make a report, wait for it to be fixed. Can’t wait for it? Fix it yourself or use a different framework. Your tone in your posts are really way off, expecting people to fix things for you.
@jschlies you are free to fix the problem and submit a pull request, also you can contribute with the laravel framework before come here with ironies…
As a followup. I found that adding
to
DuskTestCaseworks as well, but has WAY better performance than enabling processIsolation.If changing
processIsolation=falsedon’t work, you can try with this solution:Another problem can be a library for PHPUnit, on my case, was
codedungeon/phpunit-result-printer 0.25.*I got the problem when an exception was thrown in
tearDownAfterClass.Windows 10 x64 PHP 7.0.15-nts-x64 PHPUnit 4.8.16 Laravel 5.1.23
I have the same issue with: PHPUnit 6.4.1 PHP 7.1.3 Laravel 5.5.14 Homestead 2.1.0
In my case, I want to test for SoapFault errors. I have an instance of a SoapClient with an invalid WSDL URI:
However, the SoapClient raises a
E_ERROReven with the'exceptions' => trueoption. This is probably a bug in PHP, but the issue here is how that error is handled by Laravel.Upon inspection, here are the steps in chronological order:
SoapFaultexception, which is being caught and reported as intended.E_ERROR), which is displayed on the console output, with the same message as the exception.tearDownmethod ofIlluminate\Foundation\Testing\TestCaseis being invoked.App@flush()is called, which also callsContainer@flush.bindingsandinstancesof the container are emptied. As a result, the application’s exception handler and the binding for theIlluminate\Contracts\Debug\ExceptionHandler::classare gone. This is important.register_shutdown_functionis called, and it invokesIlluminate\Foundation\Bootstrap\HandleExceptions@handleShutdown.error_get_last(), and will handle any fatal error.E_ERROR, it will be now converted to aFatalErrorExceptionand passed toHandleExceptions@handleException.getExceptionHandler, which resolves the exception handler contract from the container. But since step 7, there is no exception handler, so the container throws aBindingResolutionException.renderForConsole, which again tries to get the exception handler from the container. There is no try/catch there, so this is why everyone is seeing aBindingResolutionExceptionerror.BindingResolutionExceptionis being handled in thehandleExceptionmethod because of theset_exception_handler, which makes the steps 11-12 to recur. That’s why the exception is shown twice on the console.IMO, Laravel maybe Laravel should try to handle unhandled errors (
get_last_error), before the application is flushed. We havebeforeApplicationDestroyedCallbacksbeing called just before flushing, so maybe somewhere in thesetUpwe should register a callback to handle those errors before shutdown.