PHPSpec:问题存根PDO::执行
我在使用PHPSpec和prophecy清除PDO::execute时遇到了一个问题,但我一直收到一个错误:PHPSpec:问题存根PDO::执行,php,pdo,bdd,phpspec,Php,Pdo,Bdd,Phpspec,我在使用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
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::prepare stub工作得很好。感谢您提供的任何帮助。如果这只是在幕后调用PDO,那么它没有正确使用PDO 核心PDO对象没有
execute()
方法。这纯粹是为了准备语句,这是->prepare()
返回的结果。有用于立即执行查询的->exec()
,但它不支持准备好的语句
基本顺序是
$stmt = $pdo->prepare('...');
$stmt->execute(...);
您不能执行此操作。
“SELECT:key FROM:collection WHERE:WHERE”
-除此之外,即使可以,您使用的是MySQL保留字being。但是,您可以执行“SELECT$var1 FROM$var2 WHERE$var3”
啊,很可能就是这样。我在错误的对象上调用它。关于“SELECT:key FROM:collection WHERE:WHERE”
,有什么我不知道的吗?我在OP的问题下发表了这样的评论,并且正在使用key
。我认为OP的框架可以处理这个问题。key
可能是保留字,但:key
不是。这只是一个参数select-key-from
会失败,select:key-from
不会,因为:
会有很大的不同。是的,我知道。我只是说,根据“除此之外,即使你可以……”;-)但是,无法绑定表和/或列。