Set recreateApplicationBetweenRequests to true by default

Open
#4 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
php
Domain
testing

Research direction

Review the referenced commits and trace where recreateApplicationBetweenTests and recreateApplicationBetweenRequests are defined and their defaults are applied. Confirm the request-level state-reset behavior described in the IdentityHelperMiddleware example, then verify that the default is true and that existing module tests cover the changed behavior.

Written by the indexing model from the issue text.

Description

Hi, commit https://github.com/Codeception/module-zendexpressive/commit/7d405fd406bd55e1eea671ddf4faa449b3be8229 introduced the flags to recreate the application instance between tests and between requests, both set to false by default.

Commit https://github.com/Codeception/module-zendexpressive/commit/8233e766f39effd52a9d8abbe18b06bc58b759fa 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?

Dominant language
PHP
Stars
1
Forks
4
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Codeception/module-mezzio

All issues in Codeception/module-mezzio

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.