Skip to content
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

Laravel: disableExceptionHandling and enableExceptionHandling make no effect #4902

Closed
dakipro opened this issue Mar 31, 2018 · 6 comments
Closed

Comments

@dakipro
Copy link

dakipro commented Mar 31, 2018

What are you trying to achieve?

I want to grammatically disable and enable Laravel exception handling, like described in the docs here
https://codeception.com/docs/modules/Laravel5#disableExceptionHandling

What do you get instead?

no difference whether I use it or no

Provide console output if related. Use -vvv mode for more details.

# paste output here

Provide test source code if related

// Default api test with simple test that calls API resource 
    public function exception_test(ApiTester $I)
    {
        $I->disableExceptionHandling();  
        $I->sendGET('items/-25');
        $I->seeResponseCodeIs(202);
    }

// Controller 

    public function show($id)
    {
        return new Item::findOrFail($id);
    }
/*
In list of executed steps it says that 
I disable exception handling
I send get "items/-25" 
I see response code is 202 <-- in red, as test fails here 


Result in the console is the same with both disableExceptionHandling and enableExceptionHandling 
So neither of these commands throw/handle exception. 

Expected HTTP Status Code: 202 (Accepted). Actual Status Code: 404 (Not Found)
Failed asserting that 404 matches expected 202.
Expected :202
Actual   :404


If I throw exception manually in the render() method of the HAndler class, I then get
No query results for model [App\Models\Item\Item] -25
....  (full stack trace bellow)
*/

Details

  • Codeception version: 2.4.0
  • PHP Version: 7.1.9
  • Operating System: Windows 10
  • Installation type: Composer
  • List of installed packages (composer show)

arcanedev/log-viewer 4.5.1
arcanedev/support 4.3.0
asm89/stack-cors 1.2.0
barryvdh/laravel-cors v0.11.0
barryvdh/laravel-debugbar v3.1.3
barryvdh/laravel-ide-helper v2.4.3
barryvdh/reflection-docblock v2.0.4
behat/gherkin v4.5.1
codeception/codeception 2.4.0
codeception/phpunit-wrapper 7.0.5
codeception/stub 1.0.2
creativeorange/gravatar 1.0.10
darkaonline/l5-swagger 5.6.2
davejamesmiller/laravel-breadcrumbs 5.0.0
defuse/php-encryption v2.1.0
dnoegel/php-xdg-base-dir 0.1
doctrine/annotations v1.6.0
doctrine/cache v1.7.1
doctrine/collections v1.5.0
doctrine/common v2.8.1
doctrine/dbal v2.6.3
doctrine/inflector v1.3.0
doctrine/instantiator 1.1.0
doctrine/lexer v1.0.1
dragonmantank/cron-expression v2.0.0
egulias/email-validator 2.1.3
erusev/parsedown 1.7.0
facebook/webdriver 1.5.0
fideloper/proxy 4.0.0
filp/whoops 2.1.14
firebase/php-jwt v5.0.0
flow/jsonpath 0.4.0
fzaninotto/faker v1.7.1
guzzlehttp/guzzle 6.3.0
guzzlehttp/promises v1.3.1
guzzlehttp/psr7 1.4.2
hamcrest/hamcrest-php v1.2.2
hieu-le/active 3.5.1
jakub-onderka/php-console-color 0.1
jakub-onderka/php-console-highlighter v0.3.2
laravel/browser-kit-testing dev-master 3ea22c4
laravel/framework v5.6.7
laravel/passport v5.0.3
laravel/tinker v1.0.3
laravelcollective/html v5.6.3
lcobucci/jwt 3.2.2
league/event 2.1.2
league/flysystem 1.0.42
league/oauth2-server 6.1.1
maximebf/debugbar v1.15.0
mockery/mockery 0.9.9
monolog/monolog 1.23.0
myclabs/deep-copy 1.7.0
nesbot/carbon 1.23.0
nikic/php-parser v3.1.4
paragonie/random_compat v2.0.11
phar-io/manifest 1.0.1
phar-io/version 1.0.1
phpdocumentor/reflection-common 1.0.1
phpdocumentor/reflection-docblock 4.3.0
phpdocumentor/type-resolver 0.4.0
phpseclib/phpseclib 2.0.10
phpspec/prophecy 1.7.5
phpunit/php-code-coverage 6.0.1
phpunit/php-file-iterator 1.4.5
phpunit/php-text-template 1.2.1
phpunit/php-timer 2.0.0
phpunit/php-token-stream 3.0.0
phpunit/phpunit 7.0.2
phpunit/phpunit-mock-objects 6.0.1
psr/container 1.0.0
psr/http-message 1.0.1
psr/log 1.0.2
psr/simple-cache 1.0.0
psy/psysh v0.8.17
ramsey/uuid 3.7.3
sebastian/code-unit-reverse-lookup 1.0.1
sebastian/comparator 2.1.3
sebastian/diff 3.0.0
sebastian/environment 3.1.0
sebastian/exporter 3.1.0
sebastian/global-state 2.0.0
sebastian/object-enumerator 3.0.3
sebastian/object-reflector 1.1.1
sebastian/recursion-context 3.0.0
sebastian/resource-operations 1.0.0
sebastian/version 2.0.1
swagger-api/swagger-ui v3.11.0
swiftmailer/swiftmailer v6.0.2
symfony/browser-kit v4.0.6
symfony/class-loader v3.4.4
symfony/console v4.0.4
symfony/css-selector v4.0.4
symfony/debug v4.0.4
symfony/dom-crawler v4.0.4
symfony/event-dispatcher v4.0.4
symfony/finder v4.0.4
symfony/http-foundation v4.0.4
symfony/http-kernel v4.0.4
symfony/polyfill-mbstring v1.7.0
symfony/polyfill-php72 v1.7.0
symfony/process v4.0.4
symfony/psr-http-message-bridge v1.0.2
symfony/routing v4.0.4
symfony/translation v4.0.4
symfony/var-dumper v4.0.4
symfony/yaml v4.0.6
theseer/tokenizer 1.1.0
tijsverkoyen/css-to-inline-styles 2.2.1
vlucas/phpdotenv v2.4.0
webmozart/assert 1.3.0
yajra/laravel-datatables-oracle v8.4.1
zendframework/zend-diactoros 1.7.1
zircote/swagger-php 2.0.13

  • Suite configuration:
# actor: ApiTester
modules:
    enabled:
        - REST:
            url: http://api.mytotalcollection-laravel.dloc/api/v1/
            depends: Laravel5
        - \Helper\Api
        - Laravel5:
            environment_file: .env.functional.testing
@dakipro
Copy link
Author

dakipro commented Mar 31, 2018

related to this enhancement #2763

@dakipro
Copy link
Author

dakipro commented Mar 31, 2018

And after more then 6 hours of googling and checking the code I found solution that works fine in my case, implemented outside of codeception package (as a custom method)
https://gist.github.com/adamwathan/c9752f61102dc056d157
As it says on the paged

Update 2016-11-09:

At some point since I originally shared this snippet and the accompanying screencast, Laravel started binding App\Exceptions\Handler under the Illuminate\Contracts\Debug\ExceptionHandler interface instead of the concrete class, so I've updated the files below to account for that.

I see that codeception already implements the correct Illuminate\Contracts\Debug\ExceptionHandler so I am not sure what the case is (or if I am using it wrong) but at least there is a workaround...

@DavertMik
Copy link
Member

DavertMik commented Mar 31, 2018

I use enableExceptionHandling in my Laravel tests for checking page with errors:

        $I->enableExceptionHandling();
        $I->sendPOST('/api/tests', ['bad_data' => []]);
        $I->seeResponseCodeIs('400');

So in most general case it works. Not sure what is specific for your case and I'm not Laravel expect to do any assumptions :(

@dakipro
Copy link
Author

dakipro commented Apr 1, 2018

Thanks for checking. I am also not laravel expert, but is exception handling disabled for you by default?
It looks like it is enabled for me

@FatBoyXPC
Copy link
Contributor

@Naktibalda
Copy link
Member

This issue was moved to Codeception/module-laravel#2

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

4 participants