MailerAwareTraitTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. 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. Configure::write('App.namespace', 'TestApp');
  41. $stub = new Stub();
  42. $this->assertInstanceOf('TestApp\Mailer\TestMailer', $stub->getMailer('Test'));
  43. Configure::write('App.namespace', $originalAppNamespace);
  44. }
  45. /**
  46. * Test exception thrown by getMailer.
  47. *
  48. * @expectedException \Cake\Mailer\Exception\MissingMailerException
  49. * @expectedExceptionMessage Mailer class "Test" could not be found.
  50. */
  51. public function testGetMailerThrowsException()
  52. {
  53. $stub = new Stub();
  54. $stub->getMailer('Test');
  55. }
  56. }