public function testPackageWithMultipleSendables()
 {
     $email = $this->createEmailAndAddToPackage();
     $email->addRecipientByEmail("*****@*****.**");
     $email->setSubject("A test email");
     $email->setText("This is the end, my lonely friend, the end.");
     $email = $this->createEmailAndAddToPackage();
     $email->addRecipientByEmail("*****@*****.**");
     $email->setSubject("A second test email");
     $email->setText("This is the end, my lonely friend, the end.");
     $this->package->title = "A test communication";
     $this->package->send();
     $this->assertCount(2, CommunicationItem::find());
 }
 public function testEmailExtractionFromCommunicationEmail()
 {
     $email = new SimpleEmail();
     $email->addRecipientByEmail("John Smith", "*****@*****.**");
     $email->setSender("Jane Smith", "*****@*****.**");
     $email->setSubject("The three billy goats");
     $email->setText("Michael went to mow, went to mow a meadow.");
     $email->setHtml("<p>Michael went to mow, went to mow a meadow.</p>");
     $email->addAttachment("file_location.txt");
     $email->addAttachment("file_location1.txt", "TestFakeFileName");
     $package = new CommunicationPackage();
     $package->addSendable($email);
     $package->title = $email->getSubject();
     $package->send();
     $item = CommunicationItem::findLast();
     $derivedEmail = $item->getSendable();
     $this->assertEquals($email, $derivedEmail, "The derived email isn't exactly the same as the original");
     $this->assertInstanceOf(SimpleEmail::class, $derivedEmail);
     // Next test is that a different sendable generates the correct type when getSendable is called.
     $unitTestingEmail = new UnitTestingTemplateEmail(['Name' => "", 'Age' => "", 'HairColour' => ""]);
     $unitTestingEmail->addRecipientByEmail("*****@*****.**");
     $package = new CommunicationPackage();
     $package->addSendable($unitTestingEmail);
     $package->title = $unitTestingEmail->getSubject();
     $package->send();
     $item = CommunicationItem::findLast();
     $derivedEmail = $item->getSendable();
     $this->assertInstanceOf(UnitTestingTemplateEmail::class, $derivedEmail);
 }
 public function send(Sendable $email)
 {
     /**
      * @var Email $email
      */
     $package = new CommunicationPackage();
     $package->addSendable($email);
     $package->title = $email->getSubject();
     $package->send();
 }
 /**
  * @return Communication
  * @throws \Rhubarb\Stem\Exceptions\RecordNotFoundException
  */
 public function createCommunicationForEmail()
 {
     $email = new SimpleEmail();
     $email->setSubject("The three billy goats");
     $email->addRecipientByEmail("*****@*****.**", "John Smith");
     $email->setSender("*****@*****.**", "Jane Smith");
     $email->setText("Michael went to mow, went to mow a meadow.");
     $email->setHtml("<p>Michael went to mow, went to mow a meadow.</p>");
     $package = new CommunicationPackage();
     $package->addSendable($email);
     $package->title = $email->getSubject();
     $package->send();
     return Communication::findLast();
 }
 private function createCommunicationWithMultipleRecipients($dateToSend, $noOfRecipients)
 {
     $email = new SimpleEmail();
     $email->setText("Test Message Body");
     $email->setSender("*****@*****.**");
     foreach (range(1, $noOfRecipients) as $i) {
         $email->addRecipientByEmail("test@test" . $i . ".com");
     }
     $package = new CommunicationPackage();
     if ($dateToSend) {
         $package->dateToSend = $dateToSend;
     }
     $package->addSendable($email);
     $package->send();
     $communication = Communication::findLast();
     return $communication;
 }