Skip to content

Commit

Permalink
Fixed all email tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Aug 30, 2014
1 parent 7638125 commit ce8384d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 54 deletions.
6 changes: 3 additions & 3 deletions src/Core/StaticConfigTrait.php
Expand Up @@ -14,7 +14,7 @@
*/
namespace Cake\Core;

use Cake\Core\Exception\Exception;
use BadMethodCallException;

/**
* A trait that provides a set of static methods to manage configuration
Expand Down Expand Up @@ -65,7 +65,7 @@ trait StaticConfigTrait {
* @param string|array $key The name of the configuration, or an array of multiple configs.
* @param array $config An array of name => configuration data for adapter.
* @return mixed null when adding configuration and an array of configuration data when reading.
* @throws \Cake\Core\Exception\Exception When trying to modify an existing config.
* @throws \BadMethodCallException When trying to modify an existing config.
*/
public static function config($key, $config = null) {
// Read config.
Expand All @@ -79,7 +79,7 @@ public static function config($key, $config = null) {
return;
}
if (isset(static::$_config[$key])) {
throw new Exception(sprintf('Cannot reconfigure existing key "%s"', $key));
throw new BadMethodCallException(sprintf('Cannot reconfigure existing key "%s"', $key));
}
if (is_object($config)) {
$config = ['className' => $config];
Expand Down
65 changes: 14 additions & 51 deletions tests/TestCase/Network/Email/EmailTest.php
Expand Up @@ -132,7 +132,7 @@ public function testFrom() {
$this->assertSame($this->CakeEmail->from(), $expected);
$this->assertSame($this->CakeEmail, $result);

$this->setExpectedException('Cake\Network\Error\SocketException');
$this->setExpectedException('InvalidArgumentException');
$result = $this->CakeEmail->from(array('cake@cakephp.org' => 'CakePHP', 'fail@cakephp.org' => 'From can only be one address'));
}

Expand Down Expand Up @@ -249,7 +249,7 @@ public static function invalidEmails() {
* testBuildInvalidData
*
* @dataProvider invalidEmails
* @expectedException \Cake\Network\Error\SocketException
* @expectedException InvalidArgumentException
* @return void
*/
public function testInvalidEmail($value) {
Expand All @@ -260,7 +260,7 @@ public function testInvalidEmail($value) {
* testBuildInvalidData
*
* @dataProvider invalidEmails
* @expectedException \Cake\Network\Error\SocketException
* @expectedException InvalidArgumentException
* @return void
*/
public function testInvalidEmailAdd($value) {
Expand Down Expand Up @@ -454,7 +454,7 @@ public function testMessageId() {
* testMessageIdInvalid method
*
* @return void
* @expectedException \Cake\Network\Error\SocketException
* @expectedException InvalidArgumentException
*/
public function testMessageIdInvalid() {
$this->CakeEmail->messageId('my-email@localhost');
Expand Down Expand Up @@ -616,43 +616,6 @@ public function testHeaders() {
$this->assertInstanceOf('Cake\Network\Email\Email', $result);
}

/**
* Data provider function for testInvalidHeaders
*
* @return array
*/
public static function invalidHeaders() {
return array(
array(10),
array(''),
array('string'),
array(false),
array(null)
);
}

/**
* testInvalidHeaders
*
* @dataProvider invalidHeaders
* @expectedException \Cake\Network\Error\SocketException
* @return void
*/
public function testInvalidHeaders($value) {
$this->CakeEmail->setHeaders($value);
}

/**
* testInvalidAddHeaders
*
* @dataProvider invalidHeaders
* @expectedException \Cake\Network\Error\SocketException
* @return void
*/
public function testInvalidAddHeaders($value) {
$this->CakeEmail->addHeaders($value);
}

/**
* testTemplate method
*
Expand Down Expand Up @@ -742,7 +705,7 @@ public function testAttachments() {
);
$this->assertSame($this->CakeEmail->attachments(), $expected);

$this->setExpectedException('Cake\Network\Error\SocketException');
$this->setExpectedException('InvalidArgumentException');
$this->CakeEmail->attachments(array(array('nofile' => CAKE . 'basics.php', 'mimetype' => 'text/plain')));
}

Expand All @@ -766,7 +729,7 @@ public function testTransport() {
/**
* Test that using unknown transports fails.
*
* @expectedException \Cake\Core\Exception\Exception
* @expectedException InvalidArgumentException
*/
public function testTransportInvalid() {
$this->CakeEmail->transport('Invalid');
Expand All @@ -775,7 +738,7 @@ public function testTransportInvalid() {
/**
* Test that using classes with no send method fails.
*
* @expectedException \Cake\Core\Exception\Exception
* @expectedException LogicException
*/
public function testTransportInstanceInvalid() {
$this->CakeEmail->transport(new \StdClass());
Expand Down Expand Up @@ -824,7 +787,7 @@ public function testConfigTransportMultiple() {
/**
* Test that exceptions are raised when duplicate transports are configured.
*
* @expectedException \Cake\Core\Exception\Exception
* @expectedException BadMethodCallException
*/
public function testConfigTransportErrorOnDuplicate() {
Email::dropTransport('debug');
Expand Down Expand Up @@ -880,7 +843,7 @@ public function testConfig() {
/**
* Test that exceptions are raised on duplicate config set.
*
* @expectedException \Cake\Core\Exception\Exception
* @expectedException BadMethodCallException
* @return void
*/
public function testConfigErrorOnDuplicate() {
Expand Down Expand Up @@ -911,7 +874,7 @@ public function testProfile() {
/**
* Test that using an invalid profile fails.
*
* @expectedException \Cake\Core\Exception\Exception
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Unknown email configuration "derp".
*/
public function testProfileInvalid() {
Expand Down Expand Up @@ -1019,7 +982,7 @@ public function testSendWithContent() {
/**
* testSendWithoutFrom method
*
* @expectedException Cake\Network\Error\SocketException
* @expectedException BadMethodCallException
* @return void
*/
public function testSendWithoutFrom() {
Expand All @@ -1033,7 +996,7 @@ public function testSendWithoutFrom() {
/**
* testSendWithoutTo method
*
* @expectedException Cake\Network\Error\SocketException
* @expectedException BadMethodCallException
* @return void
*/
public function testSendWithoutTo() {
Expand All @@ -1047,7 +1010,7 @@ public function testSendWithoutTo() {
/**
* test send without a transport method
*
* @expectedException Cake\Network\Error\SocketException
* @expectedException BadMethodCallException
* @expectedExceptionMessage Cannot send email, transport was not defined.
* @return void
*/
Expand Down Expand Up @@ -2053,7 +2016,7 @@ public function testEmailFormat() {
$result = $this->CakeEmail->emailFormat();
$this->assertEquals('html', $result);

$this->setExpectedException('Cake\Network\Error\SocketException');
$this->setExpectedException('InvalidArgumentException');
$result = $this->CakeEmail->emailFormat('invalid');
}

Expand Down

0 comments on commit ce8384d

Please sign in to comment.