Ben alay etmek istediğim bir arayüz var. Bu arayüzün bir uygulamasıyla dalga geçebileceğimi biliyorum, ama sadece arayüzle dalga geçmenin bir yolu var mı?PHPUnit ile bir arayüz uygulaması alay edebilir miyim?
<?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);
}
}
Benim burada olsun:
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
İlginç PHPUnit, mocked interfaces, and instanceof bu işe yarayabilecek öneririm. Bunun yerine
http_client = $this->getMock('Cpm\Http\IClient');
veya
http_client = $this->getMockBuilder('Cpm\Http\IClient')->getMock();
Tamamen çalışır
http_client = $this->getMockBuilder('Cpm\Http\IClient');
kullanım
, kullandığı' -() '' değil getMock> ve bu sizin gibidir Sorunun cevabını da buldu. Bununla birlikte, IIRC burada sorunuzun bir kopyası da var ama şu anda bunu bulamıyorum. – hakre
İlginç. Onu aramamda bulamadım. Düzenleme için teşekkürler. –
cevabınızı da sorunuza cevap olarak işaretlenmiş olarak cevaplayabilirsiniz. – hakre