PHPSpec と予言を使用して 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::prepare スタブは正常に動作します。ご協力いただきありがとうございます。