Skip to content
Permalink
Browse files

Fix misleading exceptions for invalid transport configs

The exception that is thrown in case the `className` option is not
being set is a little misleading, as it's not the transport config
that is missing.
  • Loading branch information...
ndm2
ndm2 committed Aug 8, 2015
1 parent 4c4c577 commit 7f55762557c35c33787ae95b2895dfa14253d32b
Showing with 21 additions and 1 deletion.
  1. +7 −1 src/Network/Email/Email.php
  2. +14 −0 tests/TestCase/Network/Email/EmailTest.php
@@ -1013,10 +1013,16 @@ public function transport($name = null)
*/
protected function _constructTransport($name)
{
if (!isset(static::$_transportConfig[$name]['className'])) {
if (!isset(static::$_transportConfig[$name])) {
throw new InvalidArgumentException(sprintf('Transport config "%s" is missing.', $name));
}
if (!isset(static::$_transportConfig[$name]['className'])) {
throw new InvalidArgumentException(
sprintf('Transport config "%s" is invalid, the required `className` option is missing', $name)
);
}
$config = static::$_transportConfig[$name];
if (is_object($config['className'])) {
@@ -813,6 +813,20 @@ public function testTransportTypeInvalid()
$this->CakeEmail->transport(123);
}
/**
* Test that using misconfigured transports fails.
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Transport config "debug" is invalid, the required `className` option is missing
*/
public function testTransportMissingClassName()
{
Email::dropTransport('debug');
Email::configTransport('debug', []);
$this->CakeEmail->transport('debug');
}
/**
* Test configuring a transport.
*

0 comments on commit 7f55762

Please sign in to comment.
You can’t perform that action at this time.