Set recreateApplicationBetweenRequests to true by default

Aberta
#4 1 comentário 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
45/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Estagnada
Stack de tecnologia
php
Domínio
testing

Direção de pesquisa

Revise os commits referenciados e rastreie onde recreateApplicationBetweenTests e recreateApplicationBetweenRequests são definidos e onde seus valores padrão são aplicados. Confirme o comportamento de redefinição do estado no nível da requisição descrito no exemplo de IdentityHelperMiddleware e, em seguida, verifique se o padrão é true e se os testes de módulo existentes cobrem o comportamento alterado.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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?

Linguagem predominante
PHP
Estrelas
1
Forks
4
Métricas de merge de PRs
Nenhum PR com merge em 30d

Preparar o ambiente

Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de Codeception/module-mezzio

Todas as issues de Codeception/module-mezzio

Issues semelhantes

Mais issues de PHP

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.