繁体   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