[英]How to test a second parameter in a PHPUnit mock object
這就是我所擁有的:
$observer = $this->getMock('SomeObserverClass', array('method'));
$observer->expects($this->once())
->method('method')
->with($this->equalTo($arg1));
但該方法應該采用兩個參數。 我只測試第一個參數正確傳遞($ arg1)。
如何測試第二個參數?
我相信這樣做的方法是:
$observer->expects($this->once())
->method('method')
->with($this->equalTo($arg1),$this->equalTo($arg2));
要么
$observer->expects($this->once())
->method('method')
->with($arg1, $arg2);
如果你需要在第二個arg上執行不同類型的斷言,你也可以這樣做:
$observer->expects($this->once())
->method('method')
->with($this->equalTo($arg1),$this->stringContains('some_string'));
如果你需要確保一些參數傳遞多個斷言,請使用logicalAnd()
$observer->expects($this->once())
->method('method')
->with($this->logicalAnd($this->stringContains('a'), $this->stringContains('b')));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.