diff --git a/src/Network/Email/Email.php b/src/Network/Email/Email.php index 1753132b0fc..5ecc4b27ee2 100644 --- a/src/Network/Email/Email.php +++ b/src/Network/Email/Email.php @@ -937,6 +937,7 @@ public function emailFormat($format = null) { * transport, or a transport instance. * @return \Cake\Network\Email\AbstractTransport|$this * @throws \LogicException When the chosen transport lacks a send method. + * @throws \InvalidArgumentException When $name is neither a string nor an object. */ public function transport($name = null) { if ($name === null) { @@ -947,6 +948,10 @@ public function transport($name = null) { $transport = $this->_constructTransport($name); } elseif (is_object($name)) { $transport = $name; + } else { + throw new InvalidArgumentException( + sprintf('The value passed for the "$name" argument must be either a string, or an object, %s given.', gettype($name)) + ); } if (!method_exists($transport, 'send')) { throw new LogicException(sprintf('The "%s" do not have send method.', get_class($transport))); diff --git a/tests/TestCase/Network/Email/EmailTest.php b/tests/TestCase/Network/Email/EmailTest.php index c9d04a05dc3..7608f214230 100644 --- a/tests/TestCase/Network/Email/EmailTest.php +++ b/tests/TestCase/Network/Email/EmailTest.php @@ -732,6 +732,7 @@ public function testTransport() { * Test that using unknown transports fails. * * @expectedException InvalidArgumentException + * @expectedExceptionMessage Transport config "Invalid" is missing. */ public function testTransportInvalid() { $this->CakeEmail->transport('Invalid'); @@ -746,6 +747,16 @@ public function testTransportInstanceInvalid() { $this->CakeEmail->transport(new \StdClass()); } +/** + * Test that using unknown transports fails. + * + * @expectedException InvalidArgumentException + * @expectedExceptionMessage The value passed for the "$name" argument must be either a string, or an object, integer given. + */ + public function testTransportTypeInvalid() { + $this->CakeEmail->transport(123); + } + /** * Test configuring a transport. *