Goal: Use TDD to test code that works with Fungku's Hubspot Library (http://ift.tt/1wE432c) to submit subscription info to Hubspot.
Where: Running Laravel 5.1 inside vagrant VM on a Mac.
What: On a final checkout page, there is a subscribe checkbox. If that is checked we want the already entered and validated customer information to be sent to hubspot. I have setup a class that will be a middleman between Fungkus library and our code:
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;
}
}
The arguments passed to the function look like:
$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")
);
currently, I don't even have a full test written. This:
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');
}
}
When I run phpunit, gives me this:
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
What is this error telling me?
As a side note. The code that sends information to hubspot is working fine. So I know everything other than the test is working as expected. Why am I getting the above error?
I know I need to mock Fungku's Library as I don't want to actually include the Hubspot API in the test. I'd like to be able to say that the call to
$this->hubspotOBJ->contacts()->createOrUpdate()
happens to say, I want to return that it was successful. Or maybe that it failed, and to test my code that handles that.
What am I missing? Any pointers or assistance would be gratefully appreciated!
Thanks
Aucun commentaire:
Enregistrer un commentaire