MailerTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. // Copyright 2019 Hackware SpA <human@hackware.cl>
  3. // "Hackware Web Services Core" is released under the MIT License terms.
  4. namespace Hawese\Tests;
  5. use Hawese\Core\Mailer;
  6. class MailerTest extends TestCase
  7. {
  8. public function setUp(): void
  9. {
  10. parent::setUp();
  11. $this->mailer = new Mailer(true); // True enables exceptions
  12. $this->mailer->CharSet = Mailer::CHARSET_UTF8;
  13. $this->mailer->setFrom('from@example.com', 'Example From');
  14. $this->mailer->addAddress('to_mail@example.com', 'Example To');
  15. $this->mailer->Subject = 'Example subject';
  16. $this->mailer->Body = '<p>Example body</p>';
  17. $this->mailer->AltBody = 'Example body';
  18. $this->mailer->isMail();
  19. }
  20. public function testSend()
  21. {
  22. $this->assertTrue($this->mailer->send());
  23. $this->assertStringContainsString(
  24. 'Example body',
  25. $this->mailer->getSentMIMEMessage()
  26. );
  27. }
  28. public function testJsonSerialize()
  29. {
  30. $this->assertJsonStringEqualsJsonString(
  31. json_encode([
  32. 'From' => $this->mailer->From,
  33. 'FromName' => $this->mailer->FromName,
  34. 'Subject' => $this->mailer->Subject,
  35. 'To' => [['t*****l@example.com', 'Example To']]
  36. ]),
  37. json_encode($this->mailer)
  38. );
  39. }
  40. }