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' ); # Email::Simple subclasses pass through
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
33       configuration mechanism to specify the delivery method to be used, or
34       some other way that in your testing scripts you can convince your code
35       to use "Test" as the mailer, rather than "Sendmail" or another real
36       mailer.
37
38   How does it Work
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       The email trap is a simple array fills with whatever is sent.
56
57       When you send an email, it is pushed onto the end of the array. You can
58       access the array directly if you wish, or use the methods provided.
59

METHODS

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

SUPPORT

105       All bugs should be filed via the CPAN bug tracker at
106
107       http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Email-Send-Test
108       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Email-Send-Test>
109
110       For other issues, or commercial enhancement or support, contact the
111       author.
112

AUTHORS

114       Current maintainer: Ricardo SIGNES, <rjbs@cpan.org>.
115
116       Original author: Adam Kennedy <cpan@ali.as>, <http://ali.as/>
117
119       Copyright (c) 2004 - 2005 Adam Kennedy. All rights reserved.  This
120       program is free software; you can redistribute it and/or modify it
121       under the same terms as Perl itself.
122
123       The full text of the license can be found in the LICENSE file included
124       with this module.
125
126
127
128perl v5.12.1                      2009-07-12              Email::Send::Test(3)
Impressum