簡體   English   中英

如何在 codeception yii2 測試中使用 PhpUnit mocking 方法

[英]How to use PhpUnit mocking methods within codeception yii2 tests

我需要使用 PHPUnit mocking 這樣的方法expect($this->once())->returnSelf(); 在 codecept/yii2 測試中。 找不到任何方式給他們打電話。 codeception 的存根庫沒有那么多方法來模擬方法。

盡管 phpunit 被解碼包裝,但我也找不到使用 phpunit 和 yii 2 進行 API 測試的方法,使用sendPost等。

請建議。

Codeception\Test\Unit class 間接擴展了PHPUnit\Framework\TestCase 您應該能夠使用 PHPUnit 創建模擬 object 的方式,然后您可以設置其方法:

public function testMyTestCase()
{
    $mockedObject = $this->createMock(MockedClassOrInterface::class);
    $mockedObject->expects($this->once())
        ->method('methodName')
        ->willReturnSelf();
    // ... rest of the test case code
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM