Codeception / Codeception/module-lumen

Multiple inititalize in Lumen module

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

描述

Hey Guys!

I'm here again with an another issue with the Lumen module. When I'd like to make tests that contains more than one facade mocks, then the second mock won't be applied (it remains the original class).

for example:
```php
// this is a facade mock:
\AnyNamespace\Facades\Classname::shouldReceive('command1')->andReturnTrue();
$I->sendGET('/path');

// this isn't:
\AnyNamespace\Facades\Classname::shouldReceive('command2')->andReturnTrue();
$I->sendGET('/path');
```
...because the Lumen connector initialize the client again after the second REST call (see doRequest method below), and this function will clear the previously resolved instances.

```php
// in Codeception/Lib/Connector/Lumen.php
public function __construct($module)
{
...
// constructor already initialize the module
$this->initialize();
}
...
protected function doRequest($request)
{
// firstRequest is true by default
if (!$this->firstRequest) {
// I really don't know why suppose to re-initialize the whole module,
// it's already initilaized in the constructor method
$this->initialize($request);
}
$this->firstRequest = false;
....
}

private function initialize($request = null)
{
....
if (class_exists(Facade::class)) {
// this will drop all previously resolved facades,
// and won't let my tests run correctly
Facade::clearResolvedInstances();
}
....
```
The whole firstRequest check should be removed in my opinion. I can make a PR for this.

* Codeception version: 2.5.6
* PHP Version: 7.2.13

贡献指南

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

调研方向

Start in Codeception/Lib/Connector/Lumen.php, reading the constructor, doRequest(), and initialize() flow around firstRequest and Facade::clearResolvedInstances(). Verify the behavior with the module's existing tests or a focused reproduction, and consider the issue resolved when consecutive facade mocks remain applied across multiple REST requests.

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

评估

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

把新 issue 发到你的邮箱

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