/** * @test */ public function it_can_subscribe_someone_to_a_list() { $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $subscriber = new Subscriber($this->faker->name, $this->faker->email, $this->faker->phoneNumber); $subscriber->setTags('a,b'); $data = ['fields' => ['Name' => $subscriber->getName(), 'email' => $subscriber->getEmail(), 'phone' => $subscriber->getPhone()], 'tags' => 'a,b', 'request_ip' => '127.0.0.1', 'request_time' => date('Y-m-d'), 'list_ids' => '1111,2222', 'double_optin' => 3, 'overwrite' => 0]; $expectation = ['result' => ['person_id' => 2500767342]]; $this->api->shouldReceive('subscribe')->with(\Mockery::subset($data))->andReturn($expectation); $response = $this->model->subscribe($subscriber, [1111, 2222]); self::assertEquals($expectation, $response->getApiResponse()); }
/** * Subscribe user to a lists * @param Subscriber $subscriber * @param array $listIds * @return Response */ public function subscribe(Subscriber $subscriber, array $listIds) { $data = ['list_ids' => implode(',', $listIds), 'fields' => ['Name' => $subscriber->getName(), 'email' => $subscriber->getEmail(), 'phone' => $subscriber->getPhone()], 'double_optin' => $subscriber->getDoubleOptin(), 'overwrite' => $subscriber->getOverwrite()]; if ($subscriber->getTags()) { $data['tags'] = $subscriber->getTags(); } if ($subscriber->getRequestIp()) { $data['request_ip'] = $subscriber->getRequestIp(); } if ($subscriber->getRequestTime()) { $data['request_time'] = $subscriber->getRequestTime(); } if (($tags = $subscriber->getTags()) && is_array($tags)) { $data['tags'] = implode(',', $tags); } $apiResponse = $this->getApi()->subscribe($data); return new Response($apiResponse); }