PHPUnit 作为 PHP 开发者进行单元测试的利器,其每一次更新都可能带来一些变化。最近,PHPUnit 移除了一个常用的方法:
withConsecutive
那么,如何解决这个问题呢?
seec/phpunit-consecutive-params
withConsecutive
Composer在线学习地址:学习地址
安装
首先,你需要使用 Composer 安装这个包:
<pre class="brush:php;toolbar:false;">composer require --dev seec/phpunit-consecutive-params
使用
立即学习“PHP免费学习笔记(深入)”;
安装完成后,只需在你的测试类中使用
SEEC\PhpUnit\Helper\ConsecutiveParams
<pre class="brush:php;toolbar:false;"><?php
declare(strict_types=1);
namespace Your\Namespace\For\Tests;
use SEEC\PhpUnit\Helper\ConsecutiveParams;
use PHPUnit\Framework\TestCase; // 确保引入 TestCase
final class TestRunnerContextTest extends TestCase
{
use ConsecutiveParams;
public function test_it_can_use_consecutive_replacement(): void
{
$mock = $this->createMock(\stdClass::class);
$mock->expects($this->exactly(3))
->method('foo')
->with(...$this->withConsecutive(
['a', 'b'],
['c', 'd'],
['e', 'f']
));
}
}优势
withConsecutive
实际应用效果
通过使用
seec/phpunit-consecutive-params
withConsecutive
总而言之,
seec/phpunit-consecutive-params
withConsecutive
以上就是解决PHPUnitwithConsecutive弃用难题:seec/phpunit-consecutive-params助你轻松迁移的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号