在 PHPUnit 中测试表单输入,您可以使用以下方法:
getMockBuilder
和 setMethods
方法模拟表单输入。$formInput = $this->getMockBuilder(FormInput::class)
->setMethods(['getValue'])
->getMock();
$formInput->expects($this->once())
->method('getValue')
->willReturn('testValue');
$this->assertEquals('testValue', $formInput->getValue());
createMock
方法模拟表单输入。$formInput = $this->createMock(FormInput::class);
$formInput->method('getValue')
->willReturn('testValue');
$this->assertEquals('testValue', $formInput->getValue());
createPartialMock
方法模拟表单输入。$formInput = $this->createPartialMock(FormInput::class, ['getValue']);
$formInput->method('getValue')
->willReturn('testValue');
$this->assertEquals('testValue', $formInput->getValue());
createStub
方法模拟表单输入。$formInput = $this->createStub(FormInput::class);
$formInput->method('getValue')
->willReturn('testValue');
$this->assertEquals('testValue', $formInput->getValue());
这些方法都可以用来模拟表单输入,并在 PHPUnit 中进行测试。您可以根据您的需求选择合适的方法。
云+社区沙龙online第5期[架构演进]
云+社区沙龙online [技术应变力]
腾讯技术开放日
算法大赛
云+社区沙龙online [技术应变力]
云+社区技术沙龙[第3期]
领取专属 10元无门槛券
手把手带您无忧上云