我有一个我想模拟的界面。我知道我可以模拟该接口的实现,但有没有办法只模拟该接口?
<?php
require __DIR__ . '/../vendor/autoload.php';
use My\Http\IClient as IHttpClient; // The interface
use My\SomethingElse\Client as SomethingElseClient;
class SomethingElseClientTest extends PHPUnit_Framework_TestCase {
public function testPost() {
$url = 'some_url';
$http_client = $this->getMockBuilder('Cpm\Http\IClient');
$something_else = new SomethingElseClient($http_client, $url);
}
}
我在这里得到的是:
1) SomethingElseTest::testPost
Argument 1 passed to Cpm\SomethingElse\Client::__construct() must be an instance of
My\Http\IClient, instance of PHPUnit_Framework_MockObject_MockBuilder given, called in
$PATH_TO_PHP_TEST_FILE on line $NUMBER and defined
有趣的是,PHPUnit、模拟接口和 instanceof表明这可能会起作用。