Browse Source

Merge pull request #8863 from Graziel/patch-1

error gives message about config name instead of class name
Mark Story 9 years ago
parent
commit
babc83bac6
2 changed files with 25 additions and 5 deletions
  1. 7 5
      src/Mailer/Email.php
  2. 18 0
      tests/TestCase/Mailer/EmailTest.php

+ 7 - 5
src/Mailer/Email.php

@@ -1003,14 +1003,16 @@ 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) {
-            throw new InvalidArgumentException(sprintf('Transport class "%s" not found.', $name));
+            throw new InvalidArgumentException(sprintf('Transport class "%s" not found.', $config['className']));
         } elseif (!method_exists($className, 'send')) {
             throw new InvalidArgumentException(sprintf('The "%s" does not have a send() method.', $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