Browse Source

Make 'default' transport the default when you use array configuration.

Refs #9286
mark_story 9 years ago
parent
commit
03e126ccd4
2 changed files with 10 additions and 0 deletions
  1. 4 0
      src/Mailer/Email.php
  2. 6 0
      tests/TestCase/Mailer/EmailTest.php

+ 4 - 0
src/Mailer/Email.php

@@ -1389,6 +1389,10 @@ class Email implements JsonSerializable, Serializable
     public static function deliver($to = null, $subject = null, $message = null, $transportConfig = 'default', $send = true)
     {
         $class = __CLASS__;
+
+        if (is_array($transportConfig)) {
+            $transportConfig += ['transport' => 'default'];
+        }
         $instance = new $class($transportConfig);
         if ($to !== null) {
             $instance->to($to);

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

@@ -1906,11 +1906,15 @@ class EmailTest extends TestCase
      */
     public function testDeliver()
     {
+        Email::dropTransport('default');
+        Email::configTransport('default', ['className' => 'Debug']);
+
         $instance = Email::deliver('all@cakephp.org', 'About', 'Everything ok', ['from' => 'root@cakephp.org'], false);
         $this->assertInstanceOf('Cake\Mailer\Email', $instance);
         $this->assertSame($instance->to(), ['all@cakephp.org' => 'all@cakephp.org']);
         $this->assertSame($instance->subject(), 'About');
         $this->assertSame($instance->from(), ['root@cakephp.org' => 'root@cakephp.org']);
+        $this->assertInstanceOf('Cake\Mailer\AbstractTransport', $instance->transport());
 
         $config = [
             'from' => 'cake@cakephp.org',
@@ -2668,6 +2672,8 @@ HTML;
      */
     public function testMockTransport()
     {
+        Email::dropTransport('default');
+
         $mock = $this->getMockBuilder('\Cake\Mailer\AbstractTransport')->getMock();
         $config = ['from' => 'tester@example.org', 'transport' => 'default'];