W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
PHPUnit 支持對測試方法之間的顯式依賴關(guān)系進行聲明。這種依賴關(guān)系并不是定義在測試方法的執(zhí)行順序中,而是允許生產(chǎn)者(?producer
?)返回一個測試基境(?fixture
?)的實例,并將此實例傳遞給依賴于它的消費者(?consumer
?)們。用 ?@depends
? 標(biāo)注來表示依賴關(guān)系,展示了如何用 ?@depends
? 標(biāo)注來表達測試方法之間的依賴關(guān)系。
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class StackTest extends TestCase
{
public function testEmpty(): array
{
$stack = [];
$this->assertEmpty($stack);
return $stack;
}
/**
* @depends testEmpty
*/
public function testPush(array $stack): array
{
array_push($stack, 'foo');
$this->assertSame('foo', $stack[count($stack)-1]);
$this->assertNotEmpty($stack);
return $stack;
}
/**
* @depends testPush
*/
public function testPop(array $stack): void
{
$this->assertSame('foo', array_pop($stack));
$this->assertEmpty($stack);
}
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: