您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit返回值列表onConsecutiveCalls
发布时间:2021-09-22 16:41:46编辑:雪饮阅读()
返回值列表的配置可以使得一个上桩方法每次执行结果都是按照返回值列表中的顺序进行返回值的。
DatabaseTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class DatabaseTest extends TestCase
{
public function testOnConsecutiveCallsStub(): void
{
// 为类创建桩件。
$stub = $this->createStub(Database::class);
// 配置桩件。
$stub->method('doSomething')
->will($this->onConsecutiveCalls(2, 3, 5, 7));
// $stub->doSomething() 每次都会返回不同的值
$this->assertSame(2, $stub->doSomething());
$this->assertSame(3, $stub->doSomething());
$this->assertSame(5, $stub->doSomething());
}
}
use PHPUnit\Framework\TestCase;
final class DatabaseTest extends TestCase
{
public function testOnConsecutiveCallsStub(): void
{
// 为类创建桩件。
$stub = $this->createStub(Database::class);
// 配置桩件。
$stub->method('doSomething')
->will($this->onConsecutiveCalls(2, 3, 5, 7));
// $stub->doSomething() 每次都会返回不同的值
$this->assertSame(2, $stub->doSomething());
$this->assertSame(3, $stub->doSomething());
$this->assertSame(5, $stub->doSomething());
}
}
C:\Users\Administrator\PhpstormProjects\untitled\organizing>D:\phpstudy_pro\Extensions\php\php7.3.4nts\php.exe D:\phpstudy_pro\Extensions\php\php7.3.4nts\phpunit-9.5.8.phar C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\DatabaseTest.php
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
. 1 / 1 (100%)
Time: 00:00.005, Memory: 20.00 MB
OK (1 test, 3 assertions)
目前还不晓得有什么使用场景
关键字词:phpunit,onConsecutiveCalls