Skip to content

Set recreateApplicationBetweenRequests to true by default #4

@Slamdunk

Description

@Slamdunk

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions