Set recreateApplicationBetweenRequests to true by default
還沒有人認領這個 Issue。
評估
研究方向
檢查所參照的提交,並追蹤 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,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
Codeception/module-mezzio 的其他 Issue
-
難度 4/5 3-5 天 新手友好度 25/100
Codeception/module-mezzio#18 · 3 則留言 ·
-
難度 4/5 3-5 天 新手友好度 30/100
Codeception/module-mezzio#7 · 4 則留言 ·
查看 Codeception/module-mezzio 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 83/100
taskforcesh/bullmq#5238 ·
維護者通常 1 天內回覆
-
[Bug] v-change-database-password reports success but doesn't change the password when MySQL validate_password rejects it可能已有人在做 @bfs2021 今天認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
Automattic/jetpack#55517 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 84/100
-
area/import type/enhancement when/later
難度 2/5 1-3 小時 新手友好度 83/100
維護者通常 1 天內回覆