You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm here again with an another issue with the Lumen module. When I'd like to make tests that contains more than one facade mocks, then the second mock won't be applied (it remains the original class).
for example:
// this is a facade mock:
\AnyNamespace\Facades\Classname::shouldReceive('command1')->andReturnTrue();
$I->sendGET('/path');
// this isn't:
\AnyNamespace\Facades\Classname::shouldReceive('command2')->andReturnTrue();
$I->sendGET('/path');
...because the Lumen connector initialize the client again after the second REST call (see doRequest method below), and this function will clear the previously resolved instances.
// in Codeception/Lib/Connector/Lumen.phppublicfunction__construct($module)
{
...// constructor already initialize the module$this->initialize();
}
...
protected functiondoRequest($request)
{
// firstRequest is true by defaultif (!$this->firstRequest) {
// I really don't know why suppose to re-initialize the whole module, // it's already initilaized in the constructor method$this->initialize($request);
}
$this->firstRequest = false;
....
}
privatefunction initialize($request = null)
{
....
if (class_exists(Facade::class)) {
// this will drop all previously resolved facades, // and won't let my tests run correctlyFacade::clearResolvedInstances();
}
....
The whole firstRequest check should be removed in my opinion. I can make a PR for this.
Simply removing the negative logical operator would not work, that breaks the seeAuthentication and amLoggedAs tests while removing it seems to be a better solution (everything still works fine that way).
As long as we don't have better test coverage, it's difficult to merge it because it can break someone else's tests.
So the first step would be to add the missing tests there, and when the coverage is prudently complete, send the PR where it can be verified via CI that everything is still working well.
The Laravel module tests have a greater coverage and can be taken as a reference to make contributions.
Activity
TavoNiievez commentedon Jan 12, 2021
Simply removing the negative logical operator would not work, that breaks the
seeAuthenticationandamLoggedAstests while removing it seems to be a better solution (everything still works fine that way).However, there are some tests that are still pending to be added (
Ctrl + FforTODO).As long as we don't have better test coverage, it's difficult to merge it because it can break someone else's tests.
So the first step would be to add the missing tests there, and when the coverage is prudently complete, send the PR where it can be verified via CI that everything is still working well.
The Laravel module tests have a greater coverage and can be taken as a reference to make contributions.