public function testAddPersonToList() { $container = $responses = []; $responses[] = new Response(200, [], json_encode($this->responseAddListPerson)); $list_manager = $this->getListService($container, $responses); $list = new ListModel($this->responseListZero); $person = PersonModel::create(['$first_name' => 'George', 'Birthday' => '02/22/1732', '$email' => '*****@*****.**']); $person_list = $list_manager->addPersonToList($list, $person); $this->assertTrue($person_list instanceof PersonListModel, 'The returned object should be an instance of PersonListModel.'); $person_reference = PersonReferenceModel::create($this->responseAddListPerson['person']); $this->assertEquals($person_reference, $person_list->person); $list_reference = ListReferenceModel::create($this->responseAddListPerson['list']); $this->assertEquals($list_reference, $person_list->list); $this->assertTrue($person_list->alreadyMember); $request = $container[0]['request']; $this->assertSame('POST', $request->getMethod()); $fields = []; parse_str(urldecode((string) $request->getBody()), $fields); $this->assertSame('*****@*****.**', $fields['email']); $this->assertEquals($person, PersonModel::createFromJson($fields['properties'])); $this->assertTrue((bool) $fields['confirm_optin']); }
/** * Retrieve a person from the Klaviyo API. * * @param string $id * The id of the person that should be retrieved. * * @return PersonModel * The person model object if it exists in Klaviyo. */ public function getPerson($id) { $response = $this->api->request('GET', $this->getResourcePath("person/{$id}")); return PersonModel::createFromJson($response->getBody()); }