Fully automate the module without requiring changes to tests
まだ誰も着手していません。
評価
調査の方向性
モジュールの _before(TestInterface $test) エントリーポイントと、issue に示されている Codeception Di::injectDependencies の呼び出しから始めます。Cest やその他のテストタイプがどのように実行されるかを追跡し、テストを変更せずに Mockery のクリーンアップを実行するために必要なライフサイクルフックを定義します。完了条件は、サポート対象のテストタイプ全体でモジュールが動作し、クリーンアップと失敗処理のカバレッジがあることです。
索引モデルが issue の本文から書いたものです。
説明
Currently using this module requires changes in each test.
I have found an ugly way to alleviate that problem.
The code below was tested for Cest type tests only. It should not break for any other test type but might simply not work.
use Codeception\Lib\Di;
use Codeception\Module;
use Codeception\TestInterface;
class Mockery extends Module
{
public function _before(TestInterface $test)
{
$meta = $test->getMetadata();
$rc = new \ReflectionClass($meta);
$prop = $rc->getProperty('services');
$prop->setAccessible(true);
$services = $prop->getValue($meta);
/** @var Di $di */
$di = $services['di'];
$services['di'] = new class($di, $test) extends Di {
public function __construct(Di $fallback, private readonly TestInterface $test)
{
parent::__construct($fallback);
}
public function injectDependencies(object $object, string $injectMethodName = self::DEFAULT_INJECT_METHOD_NAME, array $defaults = []): void
{
if ($object === $this->test) {
parent::injectDependencies(...func_get_args());
return;
}
// We check if the object is our test, if so we close mockery after.
codecept_debug(['CALLING',
get_class($object),
$injectMethodName
]);
try {
parent::injectDependencies(...func_get_args());
\Mockery::close();
} catch (\Throwable $t) {
\Mockery::resetContainer();
throw $t;
}
\Mockery::close();
}
};
$prop->setValue($meta, $services);
}
}
Essentially we hijack the Di container and replace it with a custom implementation. Based on the fact that for Cest files the actual test is ran like this:
$this->getMetadata()->getService('di')->injectDependencies($this->testInstance, $methodName, $context);
We abuse this to insert a mockery closure after calling the test method.
While I'm happy to make a PR for this, I'm not sure it should be in an "official" repository. I probably don't have time to implement a proper fix where we add an event to allow modules to fail a test before it is finished.
- 主要言語
- PHP
- スター
- 34
- フォーク
- 12
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Codeception/MockeryModule のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
Codeception/MockeryModule#14 · リアクション 1 件 ·
Codeception/MockeryModule の issue をすべて見る
似ている issue
-
Solved site promotion gate fails on runner PHP patch drift (expects 8.2.33, runner installs 8.2.34) オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
Automattic/blocks-engine#2161 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
Automattic/static-site-importer#1824 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
0. Needs triage bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
0. Needs triage 35-feedback bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100