-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIM.php
More file actions
337 lines (315 loc) · 8.6 KB
/
Copy pathIM.php
File metadata and controls
337 lines (315 loc) · 8.6 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<?php
namespace Codeception\Module;
use Codeception\Module;
use Codeception\Exception\ModuleConfig;
use Codeception\Lib\Driver\HipChat;
/**
*
* Works with IM services.
*
* Testing with a selection of remote instant messaging services, including HipChat.
*
* Supported and tested queue types are:
*
* * [HipChat](http://hipchat.com/)
*
* The following dependencies are needed for the listed IM services:
*
* * HipChat: "gorkalaucirica/hipchat-v2-api-client": "~1.0"
*
* ## Status
*
* * Maintainer: **nathanmac**
* * Stability:
* - HipChat: **stable**
* * Contact: nathan.macnamara@outlook.com
*
* ## Config
*
* The configuration settings depending on which queueing service is being used, all the options are listed
* here. Refer to the configuration examples below to identify the configuration options required for your chosen
* service.
*
* * service - the messaging service.
* * token - API token and/or Access Token.
* * room - The room/channel id for the messaging service.
*
* N.B. The API key for HipChat must be an users API token in order to provide sufficient access the last messages in
* a given room, however if you are just looking to send a messages to the service a room API token will be
* sufficient to send the message. Consult the HipChat API documentation for clarification on this topic.
*
* ### Example
* #### Example (hipchat)
*
* modules:
* enabled: [IM]
* config:
* IM:
* service: 'hipchat'
* token: API_TOKEN
* room: ROOM_ID
*
*/
class IM extends Module
{
/**
* @var \Codeception\Lib\Interfaces\IM
*/
public $IMDriver;
/**
* Setup connection and open/setup the connection with config settings
*
* @param \Codeception\TestCase $test
*/
public function _before(\Codeception\TestCase $test)
{
$this->IMDriver->setup($this->config);
}
/**
* Provide and override for the config settings and allow custom settings depending on the service being used.
*/
protected function validateConfig()
{
$this->IMDriver = $this->createIMDriver();
$this->requiredFields = $this->IMDriver->getRequiredConfig();
$this->config = array_merge($this->IMDriver->getDefaultConfig(), $this->config);
parent::validateConfig();
}
/**
* @return \Codeception\Lib\Interfaces\IMInterface
* @throws ModuleConfig
*/
protected function createIMDriver()
{
switch (strtolower($this->config['service'])) {
case 'hipchat':
return new HipChat();
default:
throw new ModuleConfig(
__CLASS__, "Unknown IM service {$this->config}; Supported IM services include: HipChat"
);
}
}
// ----------- METHODS BELOW HERE ------------------------//
/**
* Method for sending a messages to an messaging service.
*
* ```php
* <?php
* $I->sendInstantMessage('Testing message to be send to IM service.', array('color' => 'red', 'notify' => true);
* ?>
* ```
*
* @param string $message Message to be sent.
* @param array $options Depends on service, for HipChat these include the color and the notify option.
*/
public function sendInstantMessage($message, $options = array())
{
$this->IMDriver->sendMessage($message, $options);
}
/**
* Grabber method to return the last messages on the service.
*
* ```php
* <?php
* $messages = $I->grabLastInstantMessage();
* ?>
* ```
*
* @return array
*/
public function grabLastInstantMessage(){
$message = $this->IMDriver->grabLastMessage();
$this->debug("Message -->");
$this->debug($message);
return $message;
}
/**
* Grabber method to return the from field of the last message.
*
* ```php
* <?php
* $from = $this->grabLastInstantMessageFrom();
* ?>
* ```
*
* @return string
*/
public function grabLastInstantMessageFrom()
{
$from = $this->IMDriver->grabLastMessageFrom();
$this->debug('From: [' . $from . ']');
return $from;
}
/**
* Checks whether the last messages from address matches.
*
* ```php
* <?php
* $I->seeInLastInstantMessageFrom('Codeception');
* ?>
* ```
*
* @param string $from
*/
public function seeInLastInstantMessageFrom($from)
{
\PHPUnit_Framework_Assert::assertEquals($from, $this->grabLastInstantMessageFrom());
}
/**
* Checks whether the last messages from address does not match.
*
* ```php
* <?php
* $I->dontSeeInLastInstantMessageFrom('Codeception');
* ?>
* ```
*
* @param string $from
*/
public function dontSeeInLastInstantMessageFrom($from)
{
\PHPUnit_Framework_Assert::assertNotEmpty($from, $this->grabLastInstantMessageFrom());
}
/**
* Grabber method to return the content/text of the last message.
*
* ```php
* <?php
* $from = $this->grabLastInstantMessageContent();
* ?>
* ```
*
* @return string
*/
public function grabLastInstantMessageContent()
{
$content = $this->IMDriver->grabLastMessageContent();
$this->debug('Content: [' . $content . ']');
return $content;
}
/**
* Checks whether the last messages content/text matches.
*
* ```php
* <?php
* $I->seeInLastInstantMessageContent('Hello this is the messages I am expecting to see.');
* ?>
* ```
*
* @param string $content
*/
public function seeInLastInstantMessageContent($content)
{
\PHPUnit_Framework_Assert::assertEquals($content, $this->grabLastInstantMessageContent());
}
/**
* Checks whether the last messages content/text does not match.
*
* ```php
* <?php
* $I->dontSeeInLastInstantMessageContent('Hello this is the messages I am not expecting to see.');
* ?>
* ```
*
* @param string $content
*/
public function dontSeeInLastInstantMessageContent($content)
{
\PHPUnit_Framework_Assert::assertNotEmpty($content, $this->grabLastInstantMessageContent());
}
/**
* Grabber method to return the color of the last message.
*
* ```php
* <?php
* $from = $this->grabLastInstantMessageColor();
* ?>
* ```
*
* @return string
*/
public function grabLastInstantMessageColor()
{
$color = $this->IMDriver->grabLastMessageColor();
$this->debug('Color: [' . $color . ']');
return $color;
}
/**
* Checks whether the last messages color matches.
*
* ```php
* <?php
* $I->seeInLastInstantMessageColor('red');
* ?>
* ```
*
* @param string $color
*/
public function seeInLastInstantMessageColor($color)
{
\PHPUnit_Framework_Assert::assertEquals($color, $this->grabLastInstantMessageColor());
}
/**
* Checks whether the last messages color does not match.
*
* ```php
* <?php
* $I->dontSeeInLastInstantMessageColor('red');
* ?>
* ```
*
* @param string $color
*/
public function dontSeeInLastInstantMessageColor($color)
{
\PHPUnit_Framework_Assert::assertNotEmpty($color, $this->grabLastInstantMessageColor());
}
/**
* Grabber method to return the date/time of the last message.
*
* ```php
* <?php
* $from = $this->grabLastInstantMessageDate();
* ?>
* ```
*
* @return string
*/
public function grabLastInstantMessageDate()
{
$date = $this->IMDriver->grabLastMessageDate();
$this->debug('Date/Time: [' . $date . ']');
return $date;
}
/**
* Checks whether the last messages date matches.
*
* ```php
* <?php
* $I->seeInLastInstantMessageDate('2014-10-13T16:30:48.657455+00:00');
* ?>
* ```
*
* @param string $date
*/
public function seeInLastInstantMessageDate($date)
{
\PHPUnit_Framework_Assert::assertEquals($date, $this->grabLastInstantMessageDate());
}
/**
* Checks whether the last messages date does not match.
*
* ```php
* <?php
* $I->dontSeeInLastInstantMessageDate('2015-11-13T16:30:48.657455+00:00');
* ?>
* ```
*
* @param string $date
*/
public function dontSeeInLastInstantMessageDate($date)
{
\PHPUnit_Framework_Assert::assertNotEmpty($date, $this->grabLastInstantMessageDate());
}
}