MailerAwareTraitTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://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. (http://cakefoundation.org)
  10. * @link http://cakephp.org CakePHP(tm) Project
  11. * @since 3.1.0
  12. * @license http://www.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. }
  25. /**
  26. * MailerAwareTrait test case
  27. */
  28. class MailerAwareTraitTest extends TestCase
  29. {
  30. /**
  31. * Test getMailer
  32. *
  33. * @return void
  34. */
  35. public function testGetMailer()
  36. {
  37. $originalAppNamespace = Configure::read('App.namespace');
  38. Configure::write('App.namespace', 'TestApp');
  39. $stub = new Stub();
  40. $this->assertInstanceOf('TestApp\Mailer\TestMailer', $stub->getMailer('Test'));
  41. Configure::write('App.namespace', $originalAppNamespace);
  42. }
  43. /**
  44. * Test exception thrown by getMailer.
  45. *
  46. * @expectedException Cake\Mailer\Exception\MissingMailerException
  47. * @expectedExceptionMessage Mailer class "Test" could not be found.
  48. */
  49. public function testGetMailerThrowsException()
  50. {
  51. $stub = new Stub();
  52. $stub->getMailer('Test');
  53. }
  54. }