W3Cschool
恭喜您成為首批注冊(cè)用戶(hù)
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
PHPUnit 支持對(duì)測(cè)試方法之間的顯式依賴(lài)關(guān)系進(jìn)行聲明。這種依賴(lài)關(guān)系并不是定義在測(cè)試方法的執(zhí)行順序中,而是允許生產(chǎn)者(?producer
?)返回一個(gè)測(cè)試基境(?fixture
?)的實(shí)例,并將此實(shí)例傳遞給依賴(lài)于它的消費(fèi)者(?consumer
?)們。用 ?@depends
? 標(biāo)注來(lái)表示依賴(lài)關(guān)系,展示了如何用 ?@depends
? 標(biāo)注來(lái)表達(dá)測(cè)試方法之間的依賴(lài)關(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號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話(huà):173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: