public function store(CampaignEmailFactory $campaignEmailFactory, CampaignEmailRepository $campaignEmailRepository, Queue $queue, HttpRequest $httpRequest)
 {
     $emails = json_decode(Request::input('emails'), true);
     $processed = 0;
     $campaignId = Request::input('campaign_id');
     foreach ($emails as $email) {
         try {
             $campaignEmail = $campaignEmailFactory->create(['campaignId' => $campaignId, 'emailAddress' => new Email($email['email_address']), 'variables' => $email['variables']]);
         } catch (InvalidArgumentException $e) {
             // if the email address is invalid, then
             //    we can just skip it
             continue;
         }
         $campaignEmailRepository->save($campaignEmail);
         $processed++;
     }
     if ($processed > 0) {
         // add this campaign to the queue for sending
         $message = json_encode(['campaignId' => $campaignId, 'emailsToSend' => $processed]);
         $queue->start('AmbitiousMailSenderEmailSend', $httpRequest);
         $queue->produce($message);
     }
     return $this->success(['received' => $processed]);
 }
 /**
  * @test
  */
 function converts_email_string_to_email_object_on_create()
 {
     $campaignEmail = $this->campaignEmailFactory->create(['id' => 1, 'email_address' => '*****@*****.**']);
     $this->assertInstanceOf('App\\AmbitiousMailSender\\CampaignEmails\\CampaignEmail', $campaignEmail);
     $this->assertEquals('*****@*****.**', $campaignEmail->emailAddress());
 }