Skip to content
Permalink
Browse files

Fixed all email tests

  • Loading branch information...
lorenzo committed Aug 30, 2014
1 parent 7638125 commit ce8384d94592a3590c2a4097be3c256b7054b4ef
Showing with 17 additions and 54 deletions.
  1. +3 −3 src/Core/StaticConfigTrait.php
  2. +14 −51 tests/TestCase/Network/Email/EmailTest.php
@@ -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
@@ -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.
@@ -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];
@@ -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'));
}
@@ -249,7 +249,7 @@ public static function invalidEmails() {
* testBuildInvalidData
*
* @dataProvider invalidEmails
* @expectedException \Cake\Network\Error\SocketException
* @expectedException InvalidArgumentException
* @return void
*/
public function testInvalidEmail($value) {
@@ -260,7 +260,7 @@ public function testInvalidEmail($value) {
* testBuildInvalidData
*
* @dataProvider invalidEmails
* @expectedException \Cake\Network\Error\SocketException
* @expectedException InvalidArgumentException
* @return void
*/
public function testInvalidEmailAdd($value) {
@@ -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');
@@ -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
*
@@ -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')));
}
@@ -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');
@@ -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());
@@ -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');
@@ -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() {
@@ -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() {
@@ -1019,7 +982,7 @@ public function testSendWithContent() {
/**
* testSendWithoutFrom method
*
* @expectedException Cake\Network\Error\SocketException
* @expectedException BadMethodCallException
* @return void
*/
public function testSendWithoutFrom() {
@@ -1033,7 +996,7 @@ public function testSendWithoutFrom() {
/**
* testSendWithoutTo method
*
* @expectedException Cake\Network\Error\SocketException
* @expectedException BadMethodCallException
* @return void
*/
public function testSendWithoutTo() {
@@ -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
*/
@@ -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');
}

0 comments on commit ce8384d

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