Another thought about Unit testing emails:
One should not actually test for mails "being actually sent" on
application testing level. Testing that the EmailComponent works
correctly should be part of the core tests. Afaik those do not exist
yet, but if somebody is looking into writing code that could verify that
the EmailComponent does work (or not and needs to be fixed) PhpNut would
probably take a look at it. On application level you probably would want
to create a mock of the EmailComponent to be used in your Controller
action and then only intercept the send() function call and check if it
get's the right email data.
Of the cuff I could think about something like this:
loadComponent('Email');
Mock::generate('EmailComponent');
class MailsControllerTest extends AppController
{
function setUp()
{
$this->Controller =& new MailsController();
$this->Controller->Email =& new MockEmailComponent();
}
function testContact()
{
$this->Controller->Email->expectOnce('send', array(array('text'
=> 'Hello World')));
$this->Controller->Email->setReturnValue('send', true);
$this->Controller->data['Mail']['name'] = 'Jim Johnson';
$this->Controller->data['Mail']['email'] = '[EMAIL PROTECTED]';
$this->Controller->data['Mail']['text'] = 'Hello World';
$this->Controller->contact();
$this->assertIdentical($this->Controller->Email->name, 'Jim Johnson')
$this->assertIdentical($this->Controller->Email->from,
'[EMAIL PROTECTED]')
// ...
}
}
Everything the happens beyond the EmailComponent::send() function call
is not application level unit testing. So if you would do that you'd
actually do acceptance / integration testing which is a different kind
of testing.
Hope that helps,
-- Felix
--------------------------
http://www.thinkingphp.org
http://www.fg-webdesign.de
Langdon Stevenson wrote:
> Hi Zach
>
>
>> Just be aware that if you can't run Fakemail on port 25 then you need
>> to specify the port in PHP to send the email from. The EmailComponent
>> and the PHP mail() function don't let you do that.
>>
>
> Thanks for the warning.
>
> All of my projects are currently running on Cake 1.1.x.x with PHPMailer,
> so there won't be a problem for me. When I move to 1.2 on its final
> release, then I may have to rethink.
>
> My plan at this stage is to set up a dedicated development/testing
> server some time soon, so given that, it won't clash with my mail server
> anyway.
>
> Regards,
> Langdon
>
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---