3 // +----------------------------------------------------------------------+
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997-2003 The PHP Group |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to version 2.02 of the PHP license, |
9 // | that is bundled with this package in the file LICENSE, and is |
10 // | available at through the world-wide-web at |
11 // | http://www.php.net/license/2_02.txt. |
12 // | If you did not receive a copy of the PHP license and are unable to |
13 // | obtain it through the world-wide-web, please send a note to |
14 // | license@php.net so we can mail you a copy immediately. |
15 // +----------------------------------------------------------------------+
16 // | Author: Chuck Hagenbuch <chuck@horde.org> |
17 // +----------------------------------------------------------------------+
19 // $Id: mock.php,v 1.1 2007/12/08 17:57:54 chagenbu Exp $
23 * Mock implementation of the PEAR Mail:: interface for testing.
26 * @version $Revision: 1.1 $
28 class Mail_mock extends Mail {
31 * Array of messages that have been sent with the mock.
36 var $sentMessages = array();
39 * Callback before sending mail.
43 var $_preSendCallback;
46 * Callback after sending mai.
50 var $_postSendCallback;
55 * Instantiates a new Mail_mock:: object based on the parameters
56 * passed in. It looks for the following parameters, both optional:
57 * preSendCallback Called before an email would be sent.
58 * postSendCallback Called after an email would have been sent.
60 * @param array Hash containing any parameters.
63 function Mail_mock($params)
65 if (isset($params['preSendCallback']) &&
66 is_callable($params['preSendCallback'])) {
67 $this->_preSendCallback = $params['preSendCallback'];
70 if (isset($params['postSendCallback']) &&
71 is_callable($params['postSendCallback'])) {
72 $this->_postSendCallback = $params['postSendCallback'];
77 * Implements Mail_mock::send() function. Silently discards all
80 * @param mixed $recipients Either a comma-seperated list of recipients
81 * (RFC822 compliant), or an array of recipients,
82 * each RFC822 valid. This may contain recipients not
83 * specified in the headers, for Bcc:, resending
86 * @param array $headers The array of headers to send with the mail, in an
87 * associative array, where the array key is the
88 * header name (ie, 'Subject'), and the array value
89 * is the header value (ie, 'test'). The header
90 * produced from those values would be 'Subject:
93 * @param string $body The full text of the message body, including any
96 * @return mixed Returns true on success, or a PEAR_Error
97 * containing a descriptive error message on
101 function send($recipients, $headers, $body)
103 if ($this->_preSendCallback) {
104 call_user_func_array($this->_preSendCallback,
105 array(&$this, $recipients, $headers, $body));
108 $entry = array('recipients' => $recipients, 'headers' => $headers, 'body' => $body);
109 $this->sentMessages[] = $entry;
111 if ($this->_postSendCallback) {
112 call_user_func_array($this->_postSendCallback,
113 array(&$this, $recipients, $headers, $body));