Codeception / Codeception/module-mezzio

Set recreateApplicationBetweenRequests to true by default

未关闭
#4 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
PHP
星标
1
派生
4
PR 合并指标
30 天内没有已合并 PR

描述

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:

```php
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?

贡献指南

这个仓库没有索引到贡献指南

调研方向

检查所引用的提交,并跟踪 recreateApplicationBetweenTests 和 recreateApplicationBetweenRequests 的定义位置以及它们的默认值应用位置。确认 IdentityHelperMiddleware 示例中描述的请求级状态重置行为,然后验证默认值为 true,并确认现有模块测试覆盖了已更改的行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
php
领域
testing
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。