Skip to content

Commit

Permalink
Rename config class used in test cases.
Browse files Browse the repository at this point in the history
Having a separate classname for testing allows the testsuite to not
provide a classname that the application would. This allows composer to
generate the correct classmap when CakePHP is installed with composer.

Fixes #4112
  • Loading branch information
markstory committed Sep 28, 2013
1 parent cd9b325 commit e96fe51
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
11 changes: 9 additions & 2 deletions lib/Cake/Network/Email/CakeEmail.php
Expand Up @@ -325,6 +325,13 @@ class CakeEmail {
*/
protected $_emailPattern = null;

/**
* The classname used for email configuration.
*
* @var string
*/
protected $_configClass = 'EmailConfig';

/**
* Constructor
*
Expand Down Expand Up @@ -1179,10 +1186,10 @@ public static function deliver($to = null, $subject = null, $message = null, $tr
*/
protected function _applyConfig($config) {
if (is_string($config)) {
if (!class_exists('EmailConfig') && !config('email')) {
if (!class_exists($this->_configClass) && !config('email')) {
throw new ConfigureException(__d('cake_dev', '%s not found.', APP . 'Config' . DS . 'email.php'));
}
$configs = new EmailConfig();
$configs = new $this->_configClass();
if (!isset($configs->{$config})) {
throw new ConfigureException(__d('cake_dev', 'Unknown email configuration "%s".', $config));
}
Expand Down
17 changes: 13 additions & 4 deletions lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
Expand Up @@ -26,6 +26,15 @@
*/
class TestCakeEmail extends CakeEmail {

/**
* Config classname.
*
* Use a the testing config class in this file.
*
* @var string
*/
protected $_configClass = 'TestEmailConfig';

/**
* Config
*
Expand Down Expand Up @@ -79,7 +88,7 @@ public function render($content) {
* EmailConfig class
*
*/
class EmailConfig {
class TestEmailConfig {

/**
* test config
Expand Down Expand Up @@ -841,7 +850,7 @@ public function testConfig() {
* @return void
*/
public function testConfigString() {
$configs = new EmailConfig();
$configs = new TestEmailConfig();
$this->CakeEmail->config('test');

$result = $this->CakeEmail->to();
Expand Down Expand Up @@ -1767,8 +1776,8 @@ public function testConstructWithConfigArray() {
* @return void
*/
public function testConstructWithConfigString() {
$configs = new EmailConfig();
$this->CakeEmail = new CakeEmail('test');
$configs = new TestEmailConfig();
$this->CakeEmail = new TestCakeEmail('test');

$result = $this->CakeEmail->to();
$this->assertEquals($configs->test['to'], $result);
Expand Down

0 comments on commit e96fe51

Please sign in to comment.