-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTestMessage.php
102 lines (85 loc) · 2.46 KB
/
TestMessage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
namespace NSWDPC\Messaging\Mailgun\Tests;
use Mailgun\Mailgun;
use Mailgun\Model\Message\SendResponse;
use NSWDPC\Messaging\Mailgun\Connector\Message;
/**
* Extends the default message connector between Mailer and API, captures sending
* parameters and other data for testing purposes, doesn't actually send anything.
*/
class TestMessage extends Message
{
/**
* @var string
*/
const MSG_ID = 'TESTONLY';
/**
* @var string
*/
const MSG_MESSAGE = 'This was handled as a test';
/**
* @var string
*/
protected $sentVia = '';
/**
* @var array
*/
protected $finalParameters = [];
/**
* Send data for the last message send()
*/
protected static $sendData = [];
/**
* Sends a message
* @param array $parameters
*/
protected function sendMessage(array $parameters) {
self::$sendData = [];
// Test API domain
$domain = $this->getApiDomain();
// store what would be sent
$this->finalParameters = $parameters;
$in = $this->getSendIn();
// send options
$send_via_job = $this->sendViaJob();
switch ($send_via_job) {
case 'yes':
$this->sentVia = 'job';
$response = $this->queueAndSend($domain, $parameters, $in);
break;
case 'when-attachments':
if (!empty($parameters['attachment'])) {
$this->sentVia = 'job-as-attachments';
$response = $this->queueAndSend($domain, $parameters, $in);
break;
}
case 'no':
default:
$this->sentVia = 'direct-to-api';
$response = SendResponse::create(['id' => self::MSG_ID, 'message' => self::MSG_MESSAGE]);
break;
}
// Store message info
self::setSendData([
'in' => $in,
'parameters' => $this->finalParameters,
'sentVia' => $this->sentVia,
'client' => $this->getClient(),
'domain' => $this->getApiDomain(),
'response' => $response
]);
return $response;
}
/**
* Set data that would be used
*/
public function setSendData(array $data) {
self::$sendData = $data;
}
/**
* Get data that would be used
*/
public static function getSendData() : array {
return self::$sendData;
}
}