Ensure passing empty array to SmtpTransport::config() does not reset existing config.

Synced args and return value with AbstractTransport::config().

Fixes #3840
This commit is contained in:
ADmad 2013-05-22 11:32:27 +05:30
parent 1357b00843
commit eccdf3bf60
2 changed files with 24 additions and 3 deletions

View file

@ -71,9 +71,12 @@ class SmtpTransport extends AbstractTransport {
* Set the configuration
*
* @param array $config
* @return void
* @return array Returns configs
*/
public function config($config = array()) {
public function config($config = null) {
if ($config === null) {
return $this->_config;
}
$default = array(
'host' => 'localhost',
'port' => 25,
@ -83,7 +86,8 @@ class SmtpTransport extends AbstractTransport {
'client' => null,
'tls' => false
);
$this->_config = $config + $default;
$this->_config = empty($config) ? $this->_config + $default : $config + $default;
return $this->_config;
}
/**

View file

@ -327,4 +327,21 @@ class SmtpTransportTest extends CakeTestCase {
$this->SmtpTransport->disconnect();
}
/**
* testEmptyConfigArray method
*
* @return void
*/
public function testEmptyConfigArray() {
$expected = $this->SmtpTransport->config(array(
'client' => 'myhost.com',
'port' => 666
));
$this->assertEquals(666, $expected['port']);
$result = $this->SmtpTransport->config(array());
$this->assertEquals($expected, $result);
}
}