MailerAwareTraitTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  10. * @link https://cakephp.org CakePHP(tm) Project
  11. * @since 3.1.0
  12. * @license https://opensource.org/licenses/mit-license.php MIT License
  13. */
  14. namespace Cake\Test\TestCase\Mailer;
  15. use Cake\Core\Configure;
  16. use Cake\Mailer\MailerAwareTrait;
  17. use Cake\TestSuite\TestCase;
  18. /**
  19. * Testing stub.
  20. */
  21. class Stub
  22. {
  23. use MailerAwareTrait {
  24. getMailer as public;
  25. }
  26. }
  27. /**
  28. * MailerAwareTrait test case
  29. */
  30. class MailerAwareTraitTest extends TestCase
  31. {
  32. /**
  33. * Test getMailer
  34. *
  35. * @return void
  36. */
  37. public function testGetMailer()
  38. {
  39. $originalAppNamespace = Configure::read('App.namespace');
  40. static::setAppNamespace();
  41. $stub = new Stub();
  42. $this->assertInstanceOf('TestApp\Mailer\TestMailer', $stub->getMailer('Test'));
  43. static::setAppNamespace($originalAppNamespace);
  44. }
  45. /**
  46. * Test exception thrown by getMailer.
  47. */
  48. public function testGetMailerThrowsException()
  49. {
  50. $this->expectException(\Cake\Mailer\Exception\MissingMailerException::class);
  51. $this->expectExceptionMessage('Mailer class "Test" could not be found.');
  52. $stub = new Stub();
  53. $stub->getMailer('Test');
  54. }
  55. }