目标:使用测试驱动程序来测试与丰库的Hubspot库(https://packagist.org/packages/fungku/hubspot-php)协同工作的代码,以便向Hubspot提交订阅信息。
地点:在Mac上的vagrant VM中运行Laravel 5.1。
事件:在最终的结账页面上,有一个subscribe复选框。如果选中,我们希望将已经输入和验证的客户信息发送到hubspot。我已经设置了一个类,它将成为Fungkus库和我们的代码之间的中间人:
namespace app\Classes;
use App\Models\CountriesQuery;
use Fungku\HubSpot\HubSpotService;
class Hubspot
{
private $hubspotOBJ;
public function __construct() {
$this->hubspotOBJ = HubSpotService::make();
}
public function subscribeCustomer($customerEmail, $customerArray) {
$result = $this->hubspotOBJ->contacts()->createOrUpdate($customerEmail, $customerArray);
if($result->getStatusCode() == 200){
return true;
}
return false;
}
}传递给函数的参数如下所示:
$customerEmail = "test@test.com"
$customerArray = array(
array('property' => 'email', 'value' => $customerEmail),
array('property' => 'firstname', 'value' => "FirstName"),
array('property' => 'lastname', 'value' => "LastName"),
array('property' => 'phone', 'value' => "1234567890"),
array('property' => 'mobilephone', 'value' => "9876543210"),
array('property' => 'fax', 'value' => "1112223456"),
array('property' => 'address', 'value' => "123 Some St."),
array('property' => 'street_address_2', 'value' => "Apt. 4"),
array('property' => 'state', 'value' => "IL"),
array('property' => 'city', 'value' => "City"),
array('property' => 'zip', 'value' => "12345"),
array('property' => 'country', 'value' => "USA"),
array('property' => 'lifecyclestage', 'value' => "customer"),
array('property' => 'hs_persona', 'value' => "persona_3")
);目前,我甚至还没有写好完整的测试。这一点:
use Illuminate\Foundation\Testing\WithoutMiddleware;
class HubspotTest extends TestCase {
use WithoutMiddleware;
public function tearDown() {
Mockery::close();
}
/**
* @test
*/
function it_subscribes_new_customer()
{
$mock = Mockery::mock('Fungku\HubSpot\HubSpotService');
}
}当我运行phpunit时,会给我这样的提示:
1) HubspotTest::it_subscribes_new_customer
ErrorException: Declaration of Mockery_0_Fungku_HubSpot_HubSpotService::__call() should be compatible with Fungku\HubSpot\HubSpotService::__call($name, $arguments = NULL)
/vagrant/REPO/vendor/mockery/mockery/library/Mockery/Loader/EvalLoader.php:34
/vagrant/REPO/vendor/mockery/mockery/library/Mockery/Container.php:231
/vagrant/REPO/vendor/mockery/mockery/library/Mockery.php:80
/vagrant/REPO/tests/HubspotTest.php:17这个错误告诉我什么?
顺便说一句。向hubspot发送信息的代码运行良好。因此,我知道除了测试之外的所有事情都在按预期进行。为什么我会得到上面的错误?
我知道我需要模仿Fungku的库,因为我不想在测试中包含Hubspot API。我想说的是,
$this->hubspotOBJ->contacts()->createOrUpdate()碰巧说,我想返回它是成功的。或者它可能失败了,并测试我的处理它的代码。
我遗漏了什么?如有任何建议或协助,我们将不胜感激!
谢谢
发布于 2016-05-16 16:26:14
这是一个众所周知的问题。你可以参考这个问题:https://github.com/padraic/mockery/issues/263
正如您所看到的,HubSpotService类中的__call()方法接受一个导致问题的可选参数。因此,对于PHP,__call方法的两个参数都是必需的。
https://stackoverflow.com/questions/36990315
复制相似问题