Codeception / Codeception/module-lumen
Multiple inititalize in Lumen module
- 主要言語
- 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
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
Codeception/Lib/Connector/Lumen.php から始め、firstRequest と Facade::clearResolvedInstances() 周辺のコンストラクター、doRequest()、initialize() のフローを読みます。モジュールの既存テストまたは焦点を絞った再現で動作を確認し、連続する Facade モックが複数の REST リクエストにわたって適用されたままになれば、問題が解決したと見なします。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- php
- 領域
- testing
- issue の種類
- バグ
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 50/100