MailerSendFailsEmailIsReset.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  11. * @since 5.0.0
  12. * @license https://opensource.org/licenses/mit-license.php MIT License
  13. */
  14. namespace Cake\Test\TestCase\Mailer;
  15. use Cake\Mailer\Mailer;
  16. use Cake\TestSuite\TestCase;
  17. use RuntimeException;
  18. class MailerSendFailsEmailIsReset extends TestCase
  19. {
  20. public function testSendAction(): void
  21. {
  22. $mailer = new class extends Mailer {
  23. public bool $restoreIsCalled = false;
  24. public function welcome()
  25. {
  26. }
  27. public function deliver(string $content = ''): array
  28. {
  29. throw new RuntimeException('kaboom');
  30. }
  31. protected function restore()
  32. {
  33. $this->restoreIsCalled = true;
  34. return $this;
  35. }
  36. };
  37. try {
  38. $mailer->send('welcome', ['foo', 'bar']);
  39. $this->fail('Exception should bubble up.');
  40. } catch (RuntimeException) {
  41. $this->assertTrue($mailer->restoreIsCalled, 'Exception was raised');
  42. }
  43. }
  44. }