我正在学习如何结合使用PHPUnit和XDebugger在PHP中进行单元测试。我的代码按预期运行,但是,逐步浏览代码时,我遇到了大量异常,所有异常都具有以下相同的错误消息:
“ SebastianBergmann \ Comparator \ ComparisonFailure:无法断言两个字符串相等。”
奇怪的是,我没有在终端上看到任何异常弹出,并且按预期分配了变量。
此外,如果我删除此代码:
$appStub->expects($this->any())
->method('request')
->will($this->returnValue($requestStub));
$testThree = $appStub->request();
然后,错误停止发生。仅当存根具有多个方法被覆盖时,它们才会出现。
我还更新到了最新的PHPUnit版本,但仍然遇到相同的错误。因此,我只能以为我做错了什么,或者这就是phpunit的工作原理?
这是我的代码段
use PHPUnit\Framework\TestCase;
class FormTest extends TestCase
{
public function testMe($parmas)
{
$requestStub = $this->getMockBuilder('\Slim\Http\Request')
->disableOriginalConstructor()
->disableOriginalClone()
->getMock();
$requestStub->expects($this->any())
->method('params')
->will($this->returnValue((array)["1", "2"]));
$appStub = $this->getMockBuilder('\Slim\Slim')
->disableOriginalConstructor()
->disableOriginalClone()
->setMethods(['environment', 'request'])
->getMock();
$appStub->expects($this->any())
->method('environment')
->will($this->returnValue([]));
$appStub->expects($this->any())
->method('request')
->will($this->returnValue($requestStub));
//THIS RUNS FINE
$testOne = $requestStub->params();
//PRODUCES THE ERROR
$testTwo = $appStub->environment();
//PRODUCES THE ERROR
$testThree = $appStub->request();
//I've not yet written an actual test
$this->assertEquals("alertSuccess", "alertSuccess");
}
}
感谢您的见解!