From 2f67740804e1fc1d4bfb05e019358042355b5705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kukie=C5=82ka?= Date: Fri, 20 May 2016 20:32:06 +0200 Subject: [PATCH] add test to not found email transport class error message --- src/Mailer/Email.php | 10 ++++++---- tests/TestCase/Mailer/EmailTest.php | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Mailer/Email.php b/src/Mailer/Email.php index aafd660aa4f..209dd85539c 100644 --- a/src/Mailer/Email.php +++ b/src/Mailer/Email.php @@ -1003,10 +1003,12 @@ protected function _constructTransport($name) $className = App::className($config['className'], 'Mailer/Transport', 'Transport'); if (!$className) { $className = App::className($config['className'], 'Network/Email', 'Transport'); - trigger_error( - 'Transports in "Network/Email" are deprecated, use "Mailer/Transport" instead.', - E_USER_DEPRECATED - ); + if ($className) { + trigger_error( + 'Transports in "Network/Email" are deprecated, use "Mailer/Transport" instead.', + E_USER_DEPRECATED + ); + } } if (!$className) { diff --git a/tests/TestCase/Mailer/EmailTest.php b/tests/TestCase/Mailer/EmailTest.php index ff20f3f719a..525825d60e3 100644 --- a/tests/TestCase/Mailer/EmailTest.php +++ b/tests/TestCase/Mailer/EmailTest.php @@ -103,6 +103,9 @@ public function setUp() $this->transports = [ 'debug' => [ 'className' => 'Debug' + ], + 'badClassName' => [ + 'className' => 'TestFalse' ] ]; Email::configTransport($this->transports); @@ -119,6 +122,7 @@ public function tearDown() Log::drop('email'); Email::drop('test'); Email::dropTransport('debug'); + Email::dropTransport('badClassName'); Email::dropTransport('test_smtp'); } @@ -356,6 +360,20 @@ public function testCustomEmailValidation() ], $this->CakeEmail->to()); } + /** + * Tests not found transport class name exception + * + * @return void + * + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Transport class "TestFalse" not found. + */ + public function testClassNameException() + { + $email = new Email(); + $email->transport('badClassName'); + } + /** * Tests that it is possible to unset the email pattern and make use of filter_var() instead. *