Hi, commit Codeception/module-zendexpressive@7d405fd introduced the flags to recreate the application instance between tests and between requests, both set to false by default.
Commit Codeception/module-zendexpressive@8233e76 changed the default of recreateApplicationBetweenTests to true, which is sane to me, but without any reason described.
In my humble opinion also recreateApplicationBetweenRequests should be set to true by default, because any stateful service or component with non-deterministic behavior related to the request fails to be reset on subsequent requests.
A trivial example may be the initialization of an Identity helper:
class IdentityHelperMiddleware implements MiddlewareInterface
{
private IdentityHelper $identityHelper;
public function __construct(IdentityHelper $identityHelper)
{
$this->identityHelper = $identityHelper;
}
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$username = $request->getAttribute('username');
if (null !== $username) {
$this->identityHelper->setIdentity($username);
}
return $handler->handle($request);
}
}
In this code snipped IdentityHelper is a service instantiated only once per test with recreateApplicationBetweenRequests = false, so an hypothetical second request in the same test without the username attribute wouldn't clear the previously registered identity, while a real scenario would instead end with an empty identity for the second request.
Is this a user fault? Maybe, but PHP is shared-nothing by default, and almost every developer takes it for granted.
I don't experience any visible performance degradation switching the flag.
@Naktibalda is there any reason recreateApplicationBetweenRequests was set to false by default?
Hi, commit Codeception/module-zendexpressive@7d405fd introduced the flags to recreate the application instance between tests and between requests, both set to false by default.
Commit Codeception/module-zendexpressive@8233e76 changed the default of
recreateApplicationBetweenTeststo true, which is sane to me, but without any reason described.In my humble opinion also
recreateApplicationBetweenRequestsshould be set to true by default, because any stateful service or component with non-deterministic behavior related to the request fails to be reset on subsequent requests.A trivial example may be the initialization of an Identity helper:
In this code snipped
IdentityHelperis a service instantiated only once per test withrecreateApplicationBetweenRequests = false, so an hypothetical second request in the same test without the username attribute wouldn't clear the previously registered identity, while a real scenario would instead end with an empty identity for the second request.Is this a user fault? Maybe, but PHP is shared-nothing by default, and almost every developer takes it for granted.
I don't experience any visible performance degradation switching the flag.
@Naktibalda is there any reason
recreateApplicationBetweenRequestswas set to false by default?