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 5 bindings not initialising on first request, subsequent requests okay. #3728

Closed
behinddesign opened this Issue Nov 12, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@behinddesign

behinddesign commented Nov 12, 2016

Laravel 5 module isn't allowing the IoC bindings introduced in version 2.2.2 to be bound for the first request. I've tracked this down to the logic in the __construct / doRequest of Laravel5.php.

https://github.com/Codeception/Codeception/blob/2.2.6/src/Codeception/Lib/Connector/Laravel5.php#L89

On construct it's initialised, during which the bindings are applied as part of initialise

https://github.com/Codeception/Codeception/blob/2.2.6/src/Codeception/Lib/Connector/Laravel5.php#L221

This means that automatically, on the first request there can never be any bindings set at all due to this piece of code :

https://github.com/Codeception/Codeception/blob/2.2.6/src/Codeception/Lib/Connector/Laravel5.php#L111

So to confirm, here's the flow of a typical test pseudo style

  • start the test
  • construct the l5 connector
  • apply the bindings via initilise (no binding set yet)
  • set singletons / binds etc in the test (binds are set but not applied)
  • run request against laravel (no bindings applied due to the firstRequest check)
  • change page
  • apply the bindings via initilise (bindings now applied)

After dumping some debug around the code :

Test: tests/functional/InitialLoadCest.php:tryToTestBindings
Scenario --
"construct l5 module"
" first request? 1"
"initilize"
"apply bindings"
 I have singleton "SomeInterface#000000006e01e7310000558df9aaf7e0"
"bind singleton" <=== No further apply bindings before request is made
 I am on route "design.index"

So for my work around to this I'll need to make a request to some page which doesn't require the IoC binding and then follow through with the proper requests.

Let me know if you need a test project supplied, however the logic for this issue is fairly straight forward unless I've missed something glaringly obvious.

@janhenkgerritsen

This comment has been minimized.

Show comment
Hide comment
@janhenkgerritsen

janhenkgerritsen Nov 14, 2016

Contributor

There was a problem with the tests for this functionality that resulted in this issue going undetected. I fixed the tests and the issue itself.

Thanks for reporting this issue!

Contributor

janhenkgerritsen commented Nov 14, 2016

There was a problem with the tests for this functionality that resulted in this issue going undetected. I fixed the tests and the issue itself.

Thanks for reporting this issue!

@behinddesign

This comment has been minimized.

Show comment
Hide comment
@behinddesign

behinddesign Nov 14, 2016

Thanks for the fix and keep up the good work! Cheers.

behinddesign commented Nov 14, 2016

Thanks for the fix and keep up the good work! Cheers.

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