Skip to content

Commit c19d8df

Browse files
committed
test: extract method
1 parent b306fbc commit c19d8df

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

tests/system/Email/EmailTest.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ public function autoClearProvider()
4444
*/
4545
public function testEmailSendWithClearance($autoClear)
4646
{
47-
$config = config('Email');
48-
$config->validate = true;
49-
$email = new MockEmail($config);
47+
$email = $this->createMockEmail();
48+
5049
$email->setTo('[email protected]');
5150

5251
$this->assertTrue($email->send($autoClear));
@@ -58,9 +57,8 @@ public function testEmailSendWithClearance($autoClear)
5857

5958
public function testEmailSendStoresArchive()
6059
{
61-
$config = config('Email');
62-
$config->validate = true;
63-
$email = new MockEmail($config);
60+
$email = $this->createMockEmail();
61+
6462
$email->setTo('[email protected]');
6563
$email->setFrom('[email protected]');
6664
$email->setSubject('Archive Test');
@@ -75,9 +73,8 @@ public function testEmailSendStoresArchive()
7573

7674
public function testAutoClearLeavesArchive()
7775
{
78-
$config = config('Email');
79-
$config->validate = true;
80-
$email = new MockEmail($config);
76+
$email = $this->createMockEmail();
77+
8178
$email->setTo('[email protected]');
8279

8380
$this->assertTrue($email->send(true));
@@ -89,6 +86,7 @@ public function testEmailSendRepeatUpdatesArchive()
8986
{
9087
$config = config('Email');
9188
$email = new MockEmail($config);
89+
9290
$email->setTo('[email protected]');
9391
$email->setFrom('[email protected]');
9492

@@ -104,9 +102,8 @@ public function testEmailSendRepeatUpdatesArchive()
104102

105103
public function testSuccessDoesTriggerEvent()
106104
{
107-
$config = config('Email');
108-
$config->validate = true;
109-
$email = new MockEmail($config);
105+
$email = $this->createMockEmail();
106+
110107
$email->setTo('[email protected]');
111108

112109
$result = null;
@@ -123,9 +120,8 @@ public function testSuccessDoesTriggerEvent()
123120

124121
public function testFailureDoesNotTriggerEvent()
125122
{
126-
$config = config('Email');
127-
$config->validate = true;
128-
$email = new MockEmail($config);
123+
$email = $this->createMockEmail();
124+
129125
$email->setTo('[email protected]');
130126
$email->returnValue = false;
131127

@@ -139,4 +135,12 @@ public function testFailureDoesNotTriggerEvent()
139135

140136
$this->assertNull($result);
141137
}
138+
139+
private function createMockEmail(): MockEmail
140+
{
141+
$config = config('Email');
142+
$config->validate = true;
143+
144+
return new MockEmail($config);
145+
}
142146
}

0 commit comments

Comments
 (0)