Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update constructor to signify which parameters are required for sending all email #408

Merged
merged 5 commits into from
Jul 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 8 additions & 10 deletions lib/helpers/mail/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -946,16 +946,14 @@ class Mail implements \JsonSerializable
public $tracking_settings;
public $reply_to;

public function __construct($from = null, $subject = null, $to = null, $content = null)
{
if (!empty($from) && !empty($subject) && !empty($to) && !empty($content)) {
$this->setFrom($from);
$personalization = new Personalization();
$personalization->addTo($to);
$this->addPersonalization($personalization);
$this->setSubject($subject);
$this->addContent($content);
}
public function __construct($from, $subject, $to, $content)
{
$this->setFrom($from);
$this->setSubject($subject);
$personalization = new Personalization();
$personalization->addTo($to);
$this->addPersonalization($personalization);
$this->addContent($content);
}

public function setFrom($email)
Expand Down
2 changes: 1 addition & 1 deletion test/unit/SendGridTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static function setUpBeforeClass()
exec($command, $op);
self::$pid = (int)$op[0];
sleep(15);
print("\nPrism Started");
print("\nPrism Started\n\n");
}

public function testHelloWorld()
Expand Down
97 changes: 41 additions & 56 deletions test/unit/helpers/mail/MailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,12 @@ class MailTest_Mail extends \PHPUnit_Framework_TestCase
{
public function testBaseLineExample()
{
$mail = new Mail();

$email = new Email(null, "test@example.com");
$mail->setFrom($email);

$personalization = new Personalization();
$email = new Email(null, "test@example.com");
$personalization->addTo($email);
$mail->addPersonalization($personalization);

$mail->setSubject("Hello World from the SendGrid PHP Library");

$from = new Email(null, "test@example.com");
$to = new Email(null, "test@example.com");
$subject = "Hello World from the SendGrid PHP Library";
$content = new Content("text/plain", "some text here");
$mail->addContent($content);
$mail = new Mail($from, $subject, $to, $content);

$content = new Content("text/html", "<html><body>some text here</body></html>");
$mail->addContent($content);

Expand All @@ -29,61 +21,54 @@ public function testBaseLineExample()

public function testKitchenSinkExample()
{
$mail = new Mail();

$email = new Email("DX", "test@example.com");
$mail->setFrom($email);

$mail->setSubject("Hello World from the SendGrid PHP Library");

$personalization = new Personalization();
$email = new Email("Example User", "test@example.com");
$personalization->addTo($email);
$from = new Email("DX", "test@example.com");
$subject = "Hello World from the SendGrid PHP Library";
$to = new Email("Example User", "test@example.com");
$content = new Content("text/plain", "some text here");
$mail = new Mail($from, $subject, $to, $content);

$email = new Email("Example User", "test@example.com");
$personalization->addTo($email);
$mail->personalization[0]->addTo($email);
$email = new Email("Example User", "test@example.com");
$personalization->addCc($email);
$mail->personalization[0]->addCc($email);
$email = new Email("Example User", "test@example.com");
$personalization->addCc($email);
$mail->personalization[0]->addCc($email);
$email = new Email("Example User", "test@example.com");
$personalization->addBcc($email);
$mail->personalization[0]->addBcc($email);
$email = new Email("Example User", "test@example.com");
$personalization->addBcc($email);
$personalization->setSubject("Hello World from the SendGrid PHP Library");
$personalization->addHeader("X-Test", "test");
$personalization->addHeader("X-Mock", "true");
$personalization->addSubstitution("%name%", "Example User");
$personalization->addSubstitution("%city%", "Denver");
$personalization->addCustomArg("user_id", "343");
$personalization->addCustomArg("type", "marketing");
$personalization->setSendAt(1443636843);
$mail->addPersonalization($personalization);

$personalization2 = new Personalization();
$mail->personalization[0]->addBcc($email);
$mail->personalization[0]->setSubject("Hello World from the SendGrid PHP Library");
$mail->personalization[0]->addHeader("X-Test", "test");
$mail->personalization[0]->addHeader("X-Mock", "true");
$mail->personalization[0]->addSubstitution("%name%", "Example User");
$mail->personalization[0]->addSubstitution("%city%", "Denver");
$mail->personalization[0]->addCustomArg("user_id", "343");
$mail->personalization[0]->addCustomArg("type", "marketing");
$mail->personalization[0]->setSendAt(1443636843);

$personalization1 = new Personalization();
$email = new Email("Example User", "test@example.com");
$personalization2->addTo($email);
$personalization1->addTo($email);
$email = new Email("Example User", "test@example.com");
$personalization2->addTo($email);
$personalization1->addTo($email);
$email = new Email("Example User", "test@example.com");
$personalization2->addCc($email);
$personalization1->addCc($email);
$email = new Email("Example User", "test@example.com");
$personalization2->addCc($email);
$personalization1->addCc($email);
$email = new Email("Example User", "test@example.com");
$personalization2->addBcc($email);
$personalization1->addBcc($email);
$email = new Email("Example User", "test@example.com");
$personalization2->addBcc($email);
$personalization2->setSubject("Hello World from the SendGrid PHP Library");
$personalization2->addHeader("X-Test", "test");
$personalization2->addHeader("X-Mock", "true");
$personalization2->addSubstitution("%name%", "Example User");
$personalization2->addSubstitution("%city%", "Denver");
$personalization2->addCustomArg("user_id", "343");
$personalization2->addCustomArg("type", "marketing");
$personalization2->setSendAt(1443636843);
$mail->addPersonalization($personalization2);
$personalization1->addBcc($email);
$personalization1->setSubject("Hello World from the SendGrid PHP Library");
$personalization1->addHeader("X-Test", "test");
$personalization1->addHeader("X-Mock", "true");
$personalization1->addSubstitution("%name%", "Example User");
$personalization1->addSubstitution("%city%", "Denver");
$personalization1->addCustomArg("user_id", "343");
$personalization1->addCustomArg("type", "marketing");
$personalization1->setSendAt(1443636843);
$mail->addPersonalization($personalization1);

$content = new Content("text/plain", "some text here");
$mail->addContent($content);
$content = new Content("text/html", "<html><body>some text here</body></html>");
$mail->addContent($content);

Expand Down