HTMLを綺麗に、色んなテスト関係関数の修正

This commit is contained in:
2025-11-20 22:39:28 +09:00
parent 8513c530f5
commit 4f70e6d4e4
11 changed files with 145 additions and 71 deletions

View File

@@ -19,6 +19,7 @@ class Tester {
private bool $colorOutput = true;
private bool $verboseOutput = true;
private bool $stopOnFailure = false;
private bool $skipCurrentDescribe = false;
private array $beforeEachCallbacks = [];
private array $afterEachCallbacks = [];
private array $beforeAllCallbacks = [];
@@ -119,6 +120,7 @@ class Tester {
*/
public function describe(string $description, callable $callback): Tester {
$this->currentTestCase = $description;
$this->skipCurrentDescribe = false;
$this->output($this->colorize('bold', "テストケース: {$description}"));
try {
@@ -149,6 +151,11 @@ class Tester {
* @return Tester このインスタンス
*/
public function it(string $description, callable $callback): Tester {
if ($this->skipCurrentDescribe) {
$this->skip($description, 'skipAll() が呼び出されました');
return $this;
}
$this->currentTest = $description;
$this->testCount++;
@@ -435,7 +442,42 @@ class Tester {
}
/**
* Print a summary of the test results
* コレクションが指定された要素数を持つ事
*
* @param int $expoected 期待される要素数
* @param iterable $collection 配列または Traversable
* @param string|null $message 失敗時のカスタムメッセージ
* @return Tester
*
* @throws AssertionFailedException
*/
public function assertCount(int $expected, iterable $collection, ?string $message = null): Tester {
$actual = is_countable($collection) ? count($collection) : iterator_count($collection);
if ($actual !== $expected) {
$message ??= "要素数が {$expected} であることを期待しましたが、{$actual} でした";
throw new AssertionFailedException($message);
}
return $this;
}
/**
* 現在の describe ブロック内の残りすべての it() をスキップ
*
* @param string $reason スキップ理由(出力に表示)
* @return void
*/
public function skipAll(string $reason = 'このテストケースはスキップされました'): void {
$this->skipCurrentDescribe = true;
if ($this->verboseOutput) {
$this->output($this->colorize('cyan', " スキップAll: {$reason}"));
}
}
/**
* テスト結果の詳細を表示する
*
* @return Tester
*/