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

Laravel5 module: Laravel 5.3.0-Dev throws TypeError exception for Codeception\Lib\Connector\Laravel5\ExceptionHandlerDecorator #3420

Closed
bonsi opened this Issue Aug 9, 2016 · 7 comments

Comments

Projects
None yet
2 participants
@bonsi

bonsi commented Aug 9, 2016

What are you trying to achieve?

Using the Codeception Laravel5 module together with Laravel Framework version 5.3.0-Dev.

I've already found a solution by letting Codeception\Lib\Connector\Laravel5\ExceptionHandlerDecorator implement the Illuminate\Contracts\Debug\ExceptionHandler contract. Will provide a pullrequest later today.

What do you get instead?

SecureSessionCest: Setup a secure session
Signature: SecureSessionCest:setup_a_secure_session
Test: tests/api/SecureSessionCest.php:setup_a_secure_session
Scenario --

  [Symfony\Component\Debug\Exception\FatalThrowableError]                                                                                                                                     
  Type error: Argument 3 passed to Illuminate\Queue\Worker::__construct() must implement interface Illuminate\Contracts\Debug\ExceptionHandler, instance of Codeception\Lib\Connector\Laravel5\ExceptionHandlerDecorator given, called in /home/vagrant/dispatcher/vendor/laravel/framework/src/Illuminate/Queue/QueueServiceProvider.php on line 80

Provide test source code if related

// paste test

Details

The actual issues here lies in Codeception\Lib\Connector\Laravel5:

$decorator = new ExceptionHandlerDecorator($this->app['Illuminate\Contracts\Debug\ExceptionHandler']);
$decorator->exceptionHandlingDisabled($this->exceptionHandlingDisabled);
$this->app->instance('Illuminate\Contracts\Debug\ExceptionHandler', $decorator);

where the laravel exception handler is replaced in the laravel service container by an instance of Codeception\Lib\Connector\Laravel5\ExceptionHandlerDecorator, which does not implement the Illuminate\Contracts\Debug\ExceptionHandler contract.
Because of a recent rework (see commit) Laravel Queue Workers, the Worker constructor now expects an exception handler which implements Illuminate\Contracts\Debug\ExceptionHandler.

  • Codeception version: 2.2.3
  • PHP Version: PHP 7.0.9-1+deb.sury.org~trusty+1 (cli) ( NTS )
  • Operating System: ubuntu1404-x64
  • Installation type: Composer
  • List of installed packages (composer show)
    barryvdh/laravel-debugbar dev-master ecd1ce5 PHP Debugbar integration for Laravel
    barryvdh/laravel-ide-helper v2.2.1 Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.
    barryvdh/reflection-docblock v2.0.4
    behat/gherkin v4.4.1 Gherkin DSL parser for PHP 5.3
    classpreloader/classpreloader 3.0.0 Helps class loading performance by generating a single PHP file containing all of the autoloaded files for a specific use case
    codeception/codeception 2.2.3 BDD-style testing framework
    dnoegel/php-xdg-base-dir 0.1 implementation of xdg base directory specification for php
    doctrine/inflector v1.1.0 Common String Manipulations with regard to casing and singular/plural rules.
    doctrine/instantiator 1.0.5 A small, lightweight utility to instantiate objects in PHP without invoking their constructors
    facebook/webdriver 1.1.2 A PHP client for WebDriver
    fzaninotto/faker v1.6.0 Faker is a PHP library that generates fake data for you.
    guzzlehttp/guzzle 6.2.1 Guzzle is a PHP HTTP client library
    guzzlehttp/promises 1.2.0 Guzzle promises library
    guzzlehttp/psr7 1.3.1 PSR-7 message implementation
    hamcrest/hamcrest-php v1.2.2 This is the PHP port of Hamcrest Matchers
    jakub-onderka/php-console-color 0.1
    jakub-onderka/php-console-highlighter v0.3.2
    jeremeamia/SuperClosure 2.2.0 Serialize Closure objects, including their context and binding
    laravel/framework 5.3.x-dev 4dc53d7 The Laravel Framework.
    league/flysystem 1.0.26 Filesystem abstraction: Many filesystems, one API.
    maximebf/debugbar v1.12.0 Debug bar in the browser for php application
    mockery/mockery 0.9.5 Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing f...
    monolog/monolog 1.21.0 Sends your logs to files, sockets, inboxes, databases and various web services
    mtdowling/cron-expression v1.1.0 CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due
    myclabs/deep-copy 1.5.1 Create deep copies (clones) of your objects
    nesbot/carbon 1.21.0 A simple API extension for DateTime.
    nikic/php-parser v2.1.0 A PHP parser written in PHP
    paragonie/random_compat v2.0.2 PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
    phpdocumentor/reflection-common 1.0 Common reflection classes used by phpdocumentor to reflect the code structure
    phpdocumentor/reflection-docblock 3.1.0 With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embe...
    phpdocumentor/type-resolver 0.2
    phpseclib/phpseclib 2.0.2 PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.
    phpspec/prophecy v1.6.1 Highly opinionated mocking framework for PHP 5.3+
    phpunit/php-code-coverage 4.0.1 Library that provides collection, processing, and rendering functionality for PHP code coverage information.
    phpunit/php-file-iterator 1.4.1 FilterIterator implementation that filters files based on a list of suffixes.
    phpunit/php-text-template 1.2.1 Simple template engine.
    phpunit/php-timer 1.0.8 Utility class for timing
    phpunit/php-token-stream 1.4.8 Wrapper around PHP's tokenizer extension.
    phpunit/phpunit 5.4.8 The PHP Unit Testing framework.
    phpunit/phpunit-mock-objects 3.2.3 Mock Object library for PHPUnit
    psr/http-message 1.0.1 Common interface for HTTP messages
    psr/log 1.0.0 Common interface for logging libraries
    psy/psysh v0.7.2 An interactive shell for modern PHP.
    sabre/uri 1.1.0 Functions for making sense out of URIs.
    sabre/xml 1.4.2 sabre/xml is an XML library that you may not hate.
    sebastian/code-unit-reverse-lookup 1.0.0 Looks up which function or method a line of code belongs to
    sebastian/comparator 1.2.0 Provides the functionality to compare PHP values for equality
    sebastian/diff 1.4.1 Diff implementation
    sebastian/environment 1.3.7 Provides functionality to handle HHVM/PHP environments
    sebastian/exporter 1.2.2 Provides the functionality to export PHP variables for visualization
    sebastian/global-state 1.1.1 Snapshotting of global state
    sebastian/object-enumerator 1.0.0 Traverses array structures and object graphs to enumerate all referenced objects
    sebastian/recursion-context 1.0.2 Provides functionality to recursively process PHP variables
    sebastian/resource-operations 1.0.0 Provides a list of PHP built-in functions that operate on resources
    sebastian/version 2.0.0 Library that helps with managing the version number of Git-hosted PHP projects
    swiftmailer/swiftmailer v5.4.3 Swiftmailer, free feature-rich PHP mailer
    symfony/browser-kit v3.1.3 Symfony BrowserKit Component
    symfony/class-loader v3.1.3 Symfony ClassLoader Component
    symfony/console v3.1.3 Symfony Console Component
    symfony/css-selector v3.1.3 Symfony CssSelector Component
    symfony/debug v3.1.3 Symfony Debug Component
    symfony/dom-crawler v3.1.3 Symfony DomCrawler Component
    symfony/event-dispatcher v3.1.3 Symfony EventDispatcher Component
    symfony/finder v3.1.3 Symfony Finder Component
    symfony/http-foundation v3.1.3 Symfony HttpFoundation Component
    symfony/http-kernel v3.1.3 Symfony HttpKernel Component
    symfony/polyfill-mbstring v1.2.0 Symfony polyfill for the Mbstring extension
    symfony/polyfill-php56 v1.2.0 Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
    symfony/polyfill-util v1.2.0 Symfony utilities for portability of PHP codes
    symfony/process v3.1.3 Symfony Process Component
    symfony/routing v3.1.3 Symfony Routing Component
    symfony/translation v3.1.3 Symfony Translation Component
    symfony/var-dumper v3.1.3 Symfony mechanism for exploring and dumping PHP variables
    symfony/yaml v3.1.3 Symfony Yaml Component
    vlucas/phpdotenv v2.3.0 Loads environment variables from .env to getenv(), $_ENV and $_SERVER automagically.
    webmozart/assert 1.0.2 Assertions to validate method input/output with nice error messages.
    zf1/zend-auth 1.12.11 Zend Framework 1 Auth package
    zf1/zend-config 1.12.11 Zend Framework 1 Config package
    zf1/zend-db 1.12.11 Zend Framework 1 Db package
    zf1/zend-exception 1.12.11 Zend Framework 1 Exception package
    zf1/zend-loader 1.12.11 Zend Framework 1 Loader package
    zf1/zend-xml 1.12.11 Zend Framework 1 Xml package
  • Suite configuration:
class_name: ApiTester
modules:
    enabled:
        - Helper\Api
        - Asserts
        - REST:
            depends: Laravel5
        - Laravel5:
            environment_file: .env.testing
            run_database_migrations: true
@janhenkgerritsen

This comment has been minimized.

Show comment
Hide comment
@janhenkgerritsen

janhenkgerritsen Aug 10, 2016

Contributor

What does your test and relevant application code look like? I'd like to replicate the problem myself before I merge your PR.

Contributor

janhenkgerritsen commented Aug 10, 2016

What does your test and relevant application code look like? I'd like to replicate the problem myself before I merge your PR.

@bonsi

This comment has been minimized.

Show comment
Hide comment
@bonsi

bonsi Aug 11, 2016

I can not show you the original code since it's proprietary, but for the
test code below, the same exception is thrown:

$I->wantTo('Setup a secure session');

$I->haveHttpHeader('Content-Type', 'text/xml');
$I->sendPOST('api/dispatcher_xml', 'data');

$I->seeResponseCodeIs(200);
$I->seeResponseIsXml();

Result:

  1. SecureSessionCest: Setup a secure session
    Test tests/api/SecureSessionCest.php:setup_a_secure_session

[TypeError] Argument 3 passed to Illuminate\Queue\Worker::__construct()
must implement interface Illuminate\Contracts\Debug\ExceptionHandler,
instance of Codeception\Lib\Connector\Laravel5\ExceptionHandlerDecorator
given, called in
/home/vagrant/dispatcher/vendor/laravel/framework/src/Illuminate/Queue/QueueServiceProvider.php
on line 80


I was in doubt whether our definition of functional and acceptence tests
were one and the same, and therefore I maybe had to use the snippet to
setup Laravel as shown in the codeception docks:

require 'bootstrap/autoload.php';
$app = require 'bootstrap/app.php';
$app->loadEnvironmentFrom('.env.testing');
$app->instance('request', new \Illuminate\Http\Request);
$app->make('Illuminate\Contracts\Http\Kernel')->bootstrap();

but that made no difference at all.

I also made sure the webserver was not used for the test above.

Regards,
Ivo

On Wed, Aug 10, 2016 at 1:00 PM, Jan-Henk Gerritsen <
notifications@github.com> wrote:

What does your test and relevant application code look like? I'd like to
replicate the problem myself before I merge your PR.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#3420 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABFb-DIbdSdfeM-Rz-fo7hTBrDM4xH46ks5qea81gaJpZM4JgDbX
.

bonsi commented Aug 11, 2016

I can not show you the original code since it's proprietary, but for the
test code below, the same exception is thrown:

$I->wantTo('Setup a secure session');

$I->haveHttpHeader('Content-Type', 'text/xml');
$I->sendPOST('api/dispatcher_xml', 'data');

$I->seeResponseCodeIs(200);
$I->seeResponseIsXml();

Result:

  1. SecureSessionCest: Setup a secure session
    Test tests/api/SecureSessionCest.php:setup_a_secure_session

[TypeError] Argument 3 passed to Illuminate\Queue\Worker::__construct()
must implement interface Illuminate\Contracts\Debug\ExceptionHandler,
instance of Codeception\Lib\Connector\Laravel5\ExceptionHandlerDecorator
given, called in
/home/vagrant/dispatcher/vendor/laravel/framework/src/Illuminate/Queue/QueueServiceProvider.php
on line 80


I was in doubt whether our definition of functional and acceptence tests
were one and the same, and therefore I maybe had to use the snippet to
setup Laravel as shown in the codeception docks:

require 'bootstrap/autoload.php';
$app = require 'bootstrap/app.php';
$app->loadEnvironmentFrom('.env.testing');
$app->instance('request', new \Illuminate\Http\Request);
$app->make('Illuminate\Contracts\Http\Kernel')->bootstrap();

but that made no difference at all.

I also made sure the webserver was not used for the test above.

Regards,
Ivo

On Wed, Aug 10, 2016 at 1:00 PM, Jan-Henk Gerritsen <
notifications@github.com> wrote:

What does your test and relevant application code look like? I'd like to
replicate the problem myself before I merge your PR.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#3420 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABFb-DIbdSdfeM-Rz-fo7hTBrDM4xH46ks5qea81gaJpZM4JgDbX
.

@janhenkgerritsen

This comment has been minimized.

Show comment
Hide comment
@janhenkgerritsen

janhenkgerritsen Aug 11, 2016

Contributor

And can you give me an idea of the application code that leads to a queue worker being constructed? Just some pseudo code is fine.

Contributor

janhenkgerritsen commented Aug 11, 2016

And can you give me an idea of the application code that leads to a queue worker being constructed? Just some pseudo code is fine.

@bonsi

This comment has been minimized.

Show comment
Hide comment
@bonsi

bonsi Aug 11, 2016

I'm currently rebuilding/integrating a legacy PHP appl which reads XML
commands (kinda like soap) and responds accordingly. I'm using Laravel for
all the goodies like migrations, and so far I only created
one route (POST /api/xml_dispatcher) in Laravel, and one controller which
responds to this uri. In the controller method, the XML message in the POST
params is extracted and passed on
to the entry point class of the legacy code.
As far as I can tell, the queue worker is instantiated by default in a
laravel 5.3 bootstrap, but the big difference with 5.2 is that the queue
worker now has the exception handler as a dependency.
My code does not explicitly construct the laravel queue worker, it's done
so by default by laravel itself.

On Thu, Aug 11, 2016 at 12:51 PM, Jan-Henk Gerritsen <
notifications@github.com> wrote:

And can you give me an idea of the application code that leads to a queue
worker being constructed? Just some pseudo code is fine.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#3420 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABFb-MGWfRfx4FUlajVxq09bHdz64AFbks5qev6VgaJpZM4JgDbX
.

bonsi commented Aug 11, 2016

I'm currently rebuilding/integrating a legacy PHP appl which reads XML
commands (kinda like soap) and responds accordingly. I'm using Laravel for
all the goodies like migrations, and so far I only created
one route (POST /api/xml_dispatcher) in Laravel, and one controller which
responds to this uri. In the controller method, the XML message in the POST
params is extracted and passed on
to the entry point class of the legacy code.
As far as I can tell, the queue worker is instantiated by default in a
laravel 5.3 bootstrap, but the big difference with 5.2 is that the queue
worker now has the exception handler as a dependency.
My code does not explicitly construct the laravel queue worker, it's done
so by default by laravel itself.

On Thu, Aug 11, 2016 at 12:51 PM, Jan-Henk Gerritsen <
notifications@github.com> wrote:

And can you give me an idea of the application code that leads to a queue
worker being constructed? Just some pseudo code is fine.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#3420 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABFb-MGWfRfx4FUlajVxq09bHdz64AFbks5qev6VgaJpZM4JgDbX
.

@bonsi

This comment has been minimized.

Show comment
Hide comment
@bonsi

bonsi Aug 11, 2016

Just tested with a new route + test:

route/api.php:

Route::get('lara53', function() {
    return '5.3 works';
});

tests/api/SecureSessionCest.php:

public function test_laravel_53( ApiTester $I )
{
    $I->wantTo('Make sure the codeception laravel5 module works with 5.3');
    $I->visit('api/lara53')
       ->see('5.3 works');
}

result:

Time: 152 ms, Memory: 18.00MB

There was 1 error:

---------
1) SecureSessionCest: Make sure the codeception laravel5 module works with 5.3
 Test  tests/api/SecureSessionCest.php:test_laravel_53

  [TypeError] Argument 3 passed to Illuminate\Queue\Worker::__construct() must implement interface Illuminate\Contracts\Debug\ExceptionHandler, instance of Codeception\Lib\Connector\Laravel5\ExceptionHandlerDecorator given, called in /home/vagrant/dispatcher/vendor/laravel/framework/src/Illuminate/Queue/QueueServiceProvider.php on line 80

bonsi commented Aug 11, 2016

Just tested with a new route + test:

route/api.php:

Route::get('lara53', function() {
    return '5.3 works';
});

tests/api/SecureSessionCest.php:

public function test_laravel_53( ApiTester $I )
{
    $I->wantTo('Make sure the codeception laravel5 module works with 5.3');
    $I->visit('api/lara53')
       ->see('5.3 works');
}

result:

Time: 152 ms, Memory: 18.00MB

There was 1 error:

---------
1) SecureSessionCest: Make sure the codeception laravel5 module works with 5.3
 Test  tests/api/SecureSessionCest.php:test_laravel_53

  [TypeError] Argument 3 passed to Illuminate\Queue\Worker::__construct() must implement interface Illuminate\Contracts\Debug\ExceptionHandler, instance of Codeception\Lib\Connector\Laravel5\ExceptionHandlerDecorator given, called in /home/vagrant/dispatcher/vendor/laravel/framework/src/Illuminate/Queue/QueueServiceProvider.php on line 80
@janhenkgerritsen

This comment has been minimized.

Show comment
Hide comment
@janhenkgerritsen

janhenkgerritsen Aug 11, 2016

Contributor

I am currently running into the same issue while upgrading the Laravel sample application for the 5.3 release, so I can investigate that a bit further. But I will probably just merge your PR, since I don't see any problems with it.

One thing from the code samples you posted, why are you using the visit method in a Codeception Cest class? That is a method from the test class that comes with Laravel, but it should not work with Codeception.

And thanks for your help and reporting the issue.

Contributor

janhenkgerritsen commented Aug 11, 2016

I am currently running into the same issue while upgrading the Laravel sample application for the 5.3 release, so I can investigate that a bit further. But I will probably just merge your PR, since I don't see any problems with it.

One thing from the code samples you posted, why are you using the visit method in a Codeception Cest class? That is a method from the test class that comes with Laravel, but it should not work with Codeception.

And thanks for your help and reporting the issue.

@bonsi

This comment has been minimized.

Show comment
Hide comment
@bonsi

bonsi Aug 11, 2016

Ah, old habits ;) visit should ofcourse be amOnPage.

bonsi commented Aug 11, 2016

Ah, old habits ;) visit should ofcourse be amOnPage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment