PHPUnit9.0 標(biāo)注-@depends

2022-03-24 10:59 更新
PHPUnit9.0 標(biāo)注集合PHPUnit9.0 標(biāo)注集合

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);
    }
}
    


以上內(nèi)容是否對(duì)您有幫助:
在線(xiàn)筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)