/** * @param string $name * * @return int * @throws ContactListNotCreated */ public function convert($name) { $name = Inflector::classify($name); if (($contactList = $this->repository->findOneByName($name)) instanceof ContactList) { return $contactList->getListId(); } $body = ['Name' => $name]; $response = $this->client->post(Resources::$Contactslist, ['body' => $body]); if (!$response->success()) { throw new ContactListNotCreated(); } $contactList = new ContactList(); $contactList->setName($name); $contactList->setListId($response->getData()[0]['ID']); $this->objectManager->persist($contactList); $this->objectManager->flush($contactList); return $contactList->getListId(); }
function it_should_return_list_id_if_exists(ContactListRepository $repository, ContactList $contactList) { $contactList->getListId()->willReturn(10); $repository->findOneByName(Argument::any())->willReturn($contactList); $this->convert('list_name')->shouldBeEqualTo(10); }