1Email::Send::Test(3)  User Contributed Perl Documentation Email::Send::Test(3)
2
3
4

NAME

6       Email::Send::Test - Captures emails sent via Email::Send for testing
7

SYNOPSIS

9         # Load as normal
10         use Email::Send;
11         use Email::Send::Test;
12
13         # Always clear the email trap before each test to prevent unexpected
14         # results, and thus spurious test results.
15         Email::Send::Test->clear;
16
17         ### BEGIN YOUR CODE TO BE TESTED (example follows)
18         my $sender = Email::Send->new({ mailer => 'Test' });
19         $sender->send( $message );
20         ### END YOUR CODE TO BE TESTED
21
22         # Check that the number and type (and content) of mails
23         # matched what you expect.
24         my @emails = Email::Send::Test->emails;
25         is( scalar(@emails), 1, 'Sent 1 email' );
26         isa_ok( $emails[0], 'Email::MIME' );
27

DESCRIPTION

29       Email::Send::Test is a driver for use in testing applications that use
30       Email::Send to send email.
31
32       To be able to use it in testing, you will need some sort of configura‐
33       tion mechanism to specify the delivery method to be used, or some other
34       way that in your testing scripts you can convince your code to use
35       "Test" as the mailer, rather than "Sendmail" or another real mailer.
36
37       How does it Work
38
39       Email::Send::Test is a trap for emails. When an email is sent, it adds
40       the emails to an internal array without doing anything at all to them,
41       and returns success to the caller.
42
43       If your application sends one email, there will be one in the trap. If
44       you send 20, there will be 20, and so on.
45
46       A typical test will involve doing running some code that should result
47       in an email being sent, and then checking in the trap to see if the
48       code did actually send out the email.
49
50       If you want you can get the emails out the trap and examine them. If
51       you only care that something got sent you can simply clear the trap and
52       move on to your next test.
53
54       The Email Trap
55
56       The email trap is a simple array fills with whatever is sent.
57
58       When you send an email, it is pushed onto the end of the array. You can
59       access the array directly if you wish, or use the methods provided.
60

METHODS

62       send $message
63
64       As for every other Email::Send mailer, "send" takes the message to be
65       sent.
66
67       However, in our case there are no arguments of any value to us, and so
68       they are ignored.
69
70       It is worth nothing that we do NOTHING to check or alter the email. For
71       example, if we are passed "undef" it ends up as is in the trap. In this
72       manner, you can see exactly what was sent without any possible tamper‐
73       ing on the part of the testing mailer.
74
75       Of course, this doesn't prevent any tampering by Email::Send itself :)
76
77       Always returns true.
78
79       emails
80
81       The "emails" method is the prefered and recommended method of getting
82       access to the email trap.
83
84       In list context, returns the content of the trap array as a list.
85
86       In scalar context, returns the number of items in the trap.
87
88       clear
89
90       The "clear" method resets the trap, emptying it.
91
92       It is recommended you always clear the trap before each test to ensure
93       any existing emails are removed and don't create a spurious test
94       result.
95
96       Always returns true.
97

SUPPORT

99       All bugs should be filed via the CPAN bug tracker at
100
101       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Email-Send-Test>
102
103       For other issues, or commercial enhancement or support, contact the
104       author.
105

AUTHORS

107       Current maintainer: Ricardo SIGNES, <rjbs@cpan.org>.
108
109       Original author: Adam Kennedy <cpan@ali.as>, <http://ali.as/>
110
112       Copyright (c) 2004 - 2005 Adam Kennedy. All rights reserved.  This pro‐
113       gram is free software; you can redistribute it and/or modify it under
114       the same terms as Perl itself.
115
116       The full text of the license can be found in the LICENSE file included
117       with this module.
118
119
120
121perl v5.8.8                       2006-12-07              Email::Send::Test(3)
Impressum