我遇到了一个问题,坚持使用PHPSpec和prophecy执行PDO::execute,但是我一直收到一个错误:
29 ! it should perform PDO queries
method `Double\PDO\P3::execute()` is not defined.
0 vendor/phpspec/prophecy/src/Prophecy/Prophecy/MethodProphecy.php:48
throw new Prophecy\Exception\Doubler\MethodNotFoundException("Method `Double\PDO\P3::ex"...)
1 vendor/phpspec/prophecy/src/Prophecy/Prophecy/ObjectProphecy.php:242
Prophecy\Prophecy\MethodProphecy->__construct([obj:Prophecy\Prophecy\ObjectProphecy], "execute", [obj:Prophecy\Argument\ArgumentsWildcard])
2 [internal]
Prophecy\Prophecy\ObjectProphecy->__call("execute", [array:1])
3 [internal]
spec\Devtools\MysqlModelSpec->it_should_perform_PDO_queries([obj:PhpSpec\Wrapper\Collaborator])这是我的规格:
class MysqlModelSpec extends ObjectBehavior
{
function let(\PDO $connection)
{
$this->beConstructedWith($connection);
}
function it_should_perform_PDO_queries(\PDO $connection)
{
$connection->prepare(
"SELECT :key FROM :collection WHERE :where"
)->willReturn(true);
$connection->execute(
array(
'key' => 'user_name',
'collection' => 'users',
'where' => 'userid=1'
)
)->willReturn(true);
$this->get('user_name', 'users', 'userid=1')
->shouldReturn(
array('user_name' => 'seagoj')
);
}
}我知道Prophecy不会将不存在的任何方法存根,但是PDO被放入PHP中,PDO::准备存根工作得很好。谢谢你能提供的任何帮助。
发布于 2014-08-20 17:48:09
如果这只是在引擎盖下调用PDO,那么它没有正确地使用PDO。
核心PDO对象没有execute()方法。这完全是准备好的语句,这就是->prepare()返回的内容。是用于立即执行查询的 ->exec(),但这不支持准备好的语句。
基本顺序是
$stmt = $pdo->prepare('...');
$stmt->execute(...);https://stackoverflow.com/questions/25411164
复制相似问题