Browse Source

Merge pull request #6969 from beporter/enumerate-email-transports

Add `Email::configuredTransport()` to enumerate transport key names.
Mark Story 10 years ago
parent
commit
97c3dccd55
2 changed files with 32 additions and 3 deletions
  1. 10 0
      src/Network/Email/Email.php
  2. 22 3
      tests/TestCase/Network/Email/EmailTest.php

+ 10 - 0
src/Network/Email/Email.php

@@ -1241,6 +1241,16 @@ class Email implements JsonSerializable, Serializable
     }
 
     /**
+     * Returns an array containing the named transport configurations
+     *
+     * @return array Array of configurations.
+     */
+    public static function configuredTransport()
+    {
+        return array_keys(static::$_transportConfig);
+    }
+
+    /**
      * Delete transport configuration.
      *
      * @param string $key The transport name to remove.

+ 22 - 3
tests/TestCase/Network/Email/EmailTest.php

@@ -100,9 +100,12 @@ class EmailTest extends TestCase
         parent::setUp();
         $this->CakeEmail = new TestEmail();
 
-        Email::configTransport('debug', [
-            'className' => 'Debug'
-        ]);
+        $this->transports = [
+            'debug' => [
+                'className' => 'Debug'
+            ]
+        ];
+        Email::configTransport($this->transports);
     }
 
     /**
@@ -882,6 +885,22 @@ class EmailTest extends TestCase
     }
 
     /**
+     * Test enumerating all transport configurations
+     *
+     * @return void
+     */
+    public function testConfiguredTransport()
+    {
+        $result = Email::configuredTransport();
+        $this->assertInternalType('array', $result, 'Should have config keys');
+        $this->assertEquals(
+            array_keys($this->transports),
+            $result,
+            'Loaded transports should be present in enumeration.'
+        );
+    }
+
+    /**
      * Test dropping a transport configuration
      *
      * @return void