Author: Guillaume Badi (gbadi@mailjet.com)
 function it_should_throw_exception_if_list_not_created(ContactListRepository $repository, ObjectManager $objectManager, Client $client, Response $response)
 {
     $repository->findOneByName(Argument::any())->willReturn(null);
     $client->post(Resources::$Contactslist, ['body' => ['Name' => 'ListName']])->willReturn($response);
     $response->success()->willReturn(false);
     $this->shouldThrow(ContactListNotCreated::CLASS)->duringConvert('list_name');
     $objectManager->persist(Argument::any())->shouldNotBeCalled();
     $objectManager->flush(Argument::any())->shouldNotBeCalled();
 }
 /**
  * Trigger a GET request
  *
  * @param array $resource Mailjet Resource/Action pair
  * @param array $args     Request arguments
  *
  * @return Response
  */
 public function delete($resource, $args = [])
 {
     $response = parent::delete($resource, $args);
     $this->calls[] = ['method' => 'DELETE', 'resource' => $resource, 'args' => $args, 'success' => $response->success(), 'response' => $response->getBody()];
     return $response;
 }
Exemple #3
0
 /**
  * sends a mail
  * @param string $to
  * @param string $subject
  * @param string $body
  * @param string $from (otional, if not uses default mail_from)
  */
 public function sendMail($to, $subject, $body, $from = null)
 {
     if ($from === null) {
         $from = $this->mail_from;
     }
     if (null === $this->mailjet_api_private_key || null === $this->mailjet_api_public_key) {
         $mail = Swift_Message::newInstance();
         $mail->setFrom($from)->setTo($to)->setSubject($subject)->setBody($body)->setContentType('text/html');
         $this->mailer->send($mail);
     } else {
         $mailjetClient = new MailjetClient($this->mailjet_api_public_key, $this->mailjet_api_private_key);
         $message = ['FromEmail' => $from, 'FromName' => $from, 'Subject' => $subject, 'Text-part' => $body, 'Html-part' => $body, 'Recipients' => [['Email' => $to]]];
         $response = $mailjetClient->post(Resources::$Email, ['body' => $message]);
     }
 }
 function it_should_add_to_contact_list(Client $client)
 {
     $this->addToList(12, '*****@*****.**');
     $client->post(Resources::$ContactManagecontactslists, ['id' => '*****@*****.**', 'body' => ['ContactsLists' => [['ListID' => 12, 'Action' => "addforce"]]]]);
 }
 function it_should_not_send_mail_if_cancelled(Swift_Mime_Message $message, Client $client, \Swift_Events_EventDispatcher $dispatcher, \Swift_Events_SendEvent $event)
 {
     $dispatcher->createSendEvent(Argument::any(), Argument::any())->willReturn($event);
     $dispatcher->dispatchEvent($event, 'beforeSendPerformed')->shouldBeCalled();
     $event->bubbleCancelled()->willReturn(true);
     $this->send($message)->shouldBeEqualTo(0);
     $client->post(Argument::any())->shouldNotBeCalled();
 }
 function it_should_unsubscribe_user_from_contact_list(ContactListConvertor $convertor, Client $client)
 {
     $convertor->convert(Argument::any())->willReturn(10);
     $this->unsubscribe('list_name', '*****@*****.**');
     $client->post(Resources::$ContactslistManagecontact, ['id' => 10, 'body' => ['Action' => 'unsub', 'Email' => '*****@*****.**']])->shouldBeCalled();
 }