Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4416096

Browse files
committed
Formatting
1 parent ba95d4b commit 4416096

File tree

3 files changed

+125
-118
lines changed

3 files changed

+125
-118
lines changed

‎src/Mailtrap.php‎

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ public function fetchMessages()
121121

122122
$messages = json_decode($messages, true);
123123

124-
foreach ($messages as $key => $message) {
125-
$messages[$key] = new MailtrapMessage($message, $this->client);
126-
}
124+
foreach ($messages as $key => $message) {
125+
$messages[$key] = new MailtrapMessage($message, $this->client);
126+
}
127127

128128
return $messages;
129129
}
@@ -290,18 +290,18 @@ public function seeInEmailHtmlBody($expected)
290290
$this->assertContains($expected, $email->html_body, 'Email body contains HTML');
291291
}
292292

293-
/**
294-
* Look for a string in the most recent email subject.
295-
*
296-
* @param string $expected
297-
*
298-
* @return mixed
299-
*/
300-
public function seeInEmailSubject($expected)
301-
{
302-
$email = $this->fetchLastMessage();
303-
$this->assertContains($expected, $email->subject, 'Email subject contains text');
304-
}
293+
/**
294+
* Look for a string in the most recent email subject.
295+
*
296+
* @param string $expected
297+
*
298+
* @return mixed
299+
*/
300+
public function seeInEmailSubject($expected)
301+
{
302+
$email = $this->fetchLastMessage();
303+
$this->assertContains($expected, $email->subject, 'Email subject contains text');
304+
}
305305

306306
/**
307307
* Look for an attachment on the most recent email.
@@ -335,7 +335,7 @@ public function seeAnAttachment($bool)
335335
public function getBccEmailOfMessage($messageId)
336336
{
337337
$message = $this->client->get("inboxes/{$this->config['inbox_id']}/messages/$messageId/body.eml")->getBody();
338-
338+
339339
if ($message instanceof Stream) {
340340
$message = $message->getContents();
341341
}
@@ -369,7 +369,7 @@ protected function wait($timeout_in_second = 30, $interval_in_millisecond = 250)
369369
public function waitForEmail($timeout = 5)
370370
{
371371
$condition = function () {
372-
return !empty($this->fetchLastMessage());
372+
return !empty($this->fetchLastMessage());
373373
};
374374

375375
$message = sprintf('Waited for %d secs but no email has arrived', $timeout);
@@ -381,7 +381,7 @@ public function waitForEmail($timeout = 5)
381381
* Wait until an email has been received with specific text in the text body.
382382
*
383383
* @param string $subject
384-
* @param int $timeout
384+
* @param int $timeout
385385
*
386386
* @throws \Exception
387387
*/
@@ -408,7 +408,7 @@ public function waitForEmailWithSubject($subject, $timeout = 5)
408408
* Wait until an email has been received with specific text in the text body.
409409
*
410410
* @param string $text
411-
* @param int $timeout
411+
* @param int $timeout
412412
*
413413
* @throws \Exception
414414
*/
@@ -426,7 +426,8 @@ public function waitForEmailWithTextInTextBody($text, $timeout = 5)
426426
return false;
427427
};
428428

429-
$message = sprintf('Waited for %d secs but no email with the text body containing %s has arrived', $timeout, $text);
429+
$message = sprintf('Waited for %d secs but no email with the text body containing %s has arrived', $timeout,
430+
$text);
430431

431432
$this->wait($timeout)->until($condition, $message);
432433
}
@@ -435,7 +436,7 @@ public function waitForEmailWithTextInTextBody($text, $timeout = 5)
435436
* Wait until an email has been received with specific text in the text body.
436437
*
437438
* @param string $text
438-
* @param int $timeout
439+
* @param int $timeout
439440
*
440441
* @throws \Exception
441442
*/
@@ -453,7 +454,8 @@ public function waitForEmailWithTextInHTMLBody($text, $timeout = 5)
453454
return false;
454455
};
455456

456-
$message = sprintf('Waited for %d secs but no email with the html body containing %s has arrived', $timeout, $text);
457+
$message = sprintf('Waited for %d secs but no email with the html body containing %s has arrived', $timeout,
458+
$text);
457459

458460
$this->wait($timeout)->until($condition, $message);
459461
}

‎src/MailtrapMessage.php‎

Lines changed: 97 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -9,95 +9,100 @@
99
* Represents a message in the MailTrap inbox
1010
*
1111
*/
12-
class MailtrapMessage {
13-
14-
/**
15-
* @var array Message payload
16-
*/
17-
protected $data;
18-
19-
/**
20-
* @var Client
21-
*/
22-
protected $client;
23-
24-
/**
25-
* @var string HTML body of the message
26-
*/
27-
protected $html_body;
28-
29-
/**
30-
* @var string Text body of the message
31-
*/
32-
protected $text_body;
33-
34-
/**
35-
* MailtrapMessage constructor.
36-
*
37-
* @param array $data
38-
* @param Client $client
39-
*/
40-
public function __construct( $data = [], Client $client ) {
41-
$this->data = $data;
42-
$this->client = $client;
43-
}
44-
45-
/**
46-
* @param string $name
47-
*
48-
* @return mixed|null
49-
*/
50-
public function __get( $name ) {
51-
if ( in_array( $name, array( 'html_body', 'text_body' ) ) ) {
52-
return $this->getMessageData( $name );
53-
}
54-
55-
if ( isset( $this->data[ $name ] ) ) {
56-
return $this->data[ $name ];
57-
}
58-
59-
return null;
60-
}
61-
62-
/**
63-
* Get the body data for a message
64-
*
65-
* @param $key
66-
*
67-
* @return bool|mixed|null|string
68-
*/
69-
public function getMessageData( $key ) {
70-
if ( $this->{$key} ) {
71-
return $this->{$key};
72-
}
73-
74-
$data_key = str_replace( 'body', 'path', $key );
75-
76-
$data = $this->retrieveMessageData( $data_key );
77-
78-
if ( ! $data ) {
79-
return '';
80-
}
81-
82-
$this->{$key} = $data;
83-
84-
return $data;
85-
}
86-
87-
/**
88-
* Retrieve the body data from the MailTrap API
89-
*
90-
* @param $key
91-
*
92-
* @return bool|string
93-
*/
94-
protected function retrieveMessageData( $key ) {
95-
$data = $this->client->get( $this->data[ $key ] )->getBody();
96-
97-
if ( $data instanceof Stream ) {
98-
return $data->getContents();
99-
}
100-
101-
return false;
102-
}
103-
}
12+
class MailtrapMessage
13+
{
14+
15+
/**
16+
* @var array Message payload
17+
*/
18+
protected $data;
19+
20+
/**
21+
* @var Client
22+
*/
23+
protected $client;
24+
25+
/**
26+
* @var string HTML body of the message
27+
*/
28+
protected $html_body;
29+
30+
/**
31+
* @var string Text body of the message
32+
*/
33+
protected $text_body;
34+
35+
/**
36+
* MailtrapMessage constructor.
37+
*
38+
* @param array $data
39+
* @param Client $client
40+
*/
41+
public function __construct($data = [], Client $client)
42+
{
43+
$this->data = $data;
44+
$this->client = $client;
45+
}
46+
47+
/**
48+
* @param string $name
49+
*
50+
* @return mixed|null
51+
*/
52+
public function __get($name)
53+
{
54+
if (in_array($name, ['html_body', 'text_body'])) {
55+
return $this->getMessageData($name);
56+
}
57+
58+
if (isset($this->data[$name])) {
59+
return $this->data[$name];
60+
}
61+
62+
return null;
63+
}
64+
65+
/**
66+
* Get the body data for a message
67+
*
68+
* @param $key
69+
*
70+
* @return bool|mixed|null|string
71+
*/
72+
public function getMessageData($key)
73+
{
74+
if ($this->{$key}) {
75+
return $this->{$key};
76+
}
77+
78+
$data_key = str_replace('body', 'path', $key);
79+
80+
$data = $this->retrieveMessageData($data_key);
81+
82+
if (!$data) {
83+
return '';
84+
}
85+
86+
$this->{$key} = $data;
87+
88+
return $data;
89+
}
90+
91+
/**
92+
* Retrieve the body data from the MailTrap API
93+
*
94+
* @param $key
95+
*
96+
* @return bool|string
97+
*/
98+
protected function retrieveMessageData($key)
99+
{
100+
$data = $this->client->get($this->data[$key])->getBody();
101+
102+
if ($data instanceof Stream) {
103+
return $data->getContents();
104+
}
105+
106+
return false;
107+
}
108+
}

‎src/MailtrapWait.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,22 @@ class MailtrapWait
3131
public function __construct(Mailtrap $mailtrap, $timeout_in_second = null, $interval_in_millisecond = null)
3232
{
3333
$this->mailtrap = $mailtrap;
34-
$this->timeout = isset($timeout_in_second) ? $timeout_in_second : 30;
35-
$this->interval = $interval_in_millisecond ?: 250;
34+
$this->timeout = isset($timeout_in_second) ? $timeout_in_second : 30;
35+
$this->interval = $interval_in_millisecond ?: 250;
3636
}
3737

3838
/**
3939
* Calls the function provided with the driver as an argument until the return value is not falsey.
4040
*
4141
* @param callable $function
42-
* @param string $message
42+
* @param string $message
4343
*
4444
* @throws \Exception
4545
* @return mixed The return value of $function
4646
*/
4747
public function until($function, $message = '')
4848
{
49-
$end = microtime(true) + $this->timeout;
49+
$end = microtime(true) + $this->timeout;
5050
$last_exception = null;
5151

5252
while ($end > microtime(true)) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /