浏览代码

add test to not found email transport class error message

Paweł Kukiełka 9 年之前
父节点
当前提交
2f67740804
共有 2 个文件被更改,包括 24 次插入4 次删除
  1. 6 4
      src/Mailer/Email.php
  2. 18 0
      tests/TestCase/Mailer/EmailTest.php

+ 6 - 4
src/Mailer/Email.php

@@ -1003,10 +1003,12 @@ class Email implements JsonSerializable, Serializable
         $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) {

+ 18 - 0
tests/TestCase/Mailer/EmailTest.php

@@ -103,6 +103,9 @@ class EmailTest extends TestCase
         $this->transports = [
             'debug' => [
                 'className' => 'Debug'
+            ],
+            'badClassName' => [
+                'className' => 'TestFalse'
             ]
         ];
         Email::configTransport($this->transports);
@@ -119,6 +122,7 @@ class EmailTest extends TestCase
         Log::drop('email');
         Email::drop('test');
         Email::dropTransport('debug');
+        Email::dropTransport('badClassName');
         Email::dropTransport('test_smtp');
     }
 
@@ -357,6 +361,20 @@ class EmailTest extends TestCase
     }
 
     /**
+     * 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.
      *
      * @return void