Set recreateApplicationBetweenRequests to true by default

未關閉
#4 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
45/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
php
領域
testing

研究方向

檢查所參照的提交,並追蹤 recreateApplicationBetweenTests 和 recreateApplicationBetweenRequests 的定義位置,以及它們的預設值套用位置。確認 IdentityHelperMiddleware 範例中描述的要求層級狀態重設行為,然後驗證預設值為 true,並確認現有的模組測試涵蓋了已變更的行為。

由索引模型根據 Issue 內容生成。

描述

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?

主要語言
PHP
星號
1
分支
4
PR 合併指標
30 天內沒有已合併 PR

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

Codeception/module-mezzio 的其他 Issue

查看 Codeception/module-mezzio 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。