Skip to content

Commit

Permalink
Ensure passing empty array to SmtpTransport::config() does not reset …
Browse files Browse the repository at this point in the history
…existing config.

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

Fixes #3840
  • Loading branch information
ADmad committed May 22, 2013
1 parent 1357b00 commit eccdf3b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/Cake/Network/Email/SmtpTransport.php
Expand Up @@ -71,9 +71,12 @@ public function send(CakeEmail $email) {
* 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,
Expand All @@ -83,7 +86,8 @@ public function config($config = array()) {
'client' => null,
'tls' => false
);
$this->_config = $config + $default;
$this->_config = empty($config) ? $this->_config + $default : $config + $default;
return $this->_config;
}

/**
Expand Down
17 changes: 17 additions & 0 deletions lib/Cake/Test/Case/Network/Email/SmtpTransportTest.php
Expand Up @@ -327,4 +327,21 @@ public function testQuit() {
$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);
}

}

0 comments on commit eccdf3b

Please sign in to comment.