使用
PHPUnit,我在嘲笑pdo,但是我试图找到一种准备多个数据库查询语句的方法.
$pdo = $this->getPdoMock(); $stmt = $this->getPdoStatementMock($pdo); $pdo->expects($this->any()) ->method('prepare') ->with($this->equalTo($title_query)) ->will($this->returnValue($stmt)); $title_stmt = $pdo->prepare($title_query); $desc_stmt = $pdo->prepare($desc_query);
我想传递类似于onConsecutiveCalls的“with”方法,所以我可以准备多个语句,如上所示.
你怎么会这样做?
您可以通过使用$this-> at()而不是$this-> any()编写单独的期望来匹配相同方法的连续调用:
原文链接:https://www.f2er.com/php/140053.html$pdo->expects($this->at(0)) ->method('prepare') ->with($this->equalTo($title_query)) ->will($this->returnValue($stmt)); $pdo->expects($this->at(1)) ->method('prepare') ->with($this->equalTo($desc_query)) ->will($this->returnValue($stmt)); $title_stmt = $pdo->prepare($title_query); $desc_stmt = $pdo->prepare($desc_query);