Skip to content

Commit 3d3063c

Browse files
authored
[10.x] Test Improvements for Mail & Notifications tests (#50690)
* [10.x] Test Improvements for Mail & Notifications tests Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> --------- Signed-off-by: Mior Muhammad Zaki <[email protected]>
1 parent 9f26b84 commit 3d3063c

9 files changed

+33
-41
lines changed

tests/Integration/Mail/RenderingMailWithLocaleTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@
33
namespace Illuminate\Tests\Integration\Mail;
44

55
use Illuminate\Mail\Mailable;
6-
use Illuminate\Support\Facades\View;
76
use Orchestra\Testbench\TestCase;
87

98
class RenderingMailWithLocaleTest extends TestCase
109
{
11-
protected function getEnvironmentSetUp($app)
10+
protected function defineEnvironment($app)
1211
{
1312
$app['config']->set('app.locale', 'en');
1413

15-
View::addLocation(__DIR__.'/Fixtures');
14+
$app['view']->addLocation(__DIR__.'/Fixtures');
1615

17-
app('translator')->setLoaded([
16+
$app['translator']->setLoaded([
1817
'*' => [
1918
'*' => [
2019
'en' => ['nom' => 'name'],

tests/Integration/Mail/SendingMailWithLocaleTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@
99
use Illuminate\Support\Carbon;
1010
use Illuminate\Support\Facades\Event;
1111
use Illuminate\Support\Facades\Mail;
12-
use Illuminate\Support\Facades\View;
1312
use Illuminate\Testing\Assert;
1413
use Orchestra\Testbench\TestCase;
1514

1615
class SendingMailWithLocaleTest extends TestCase
1716
{
18-
protected function getEnvironmentSetUp($app)
17+
protected function defineEnvironment($app)
1918
{
2019
$app['config']->set('mail.driver', 'array');
2120

2221
$app['config']->set('app.locale', 'en');
2322

24-
View::addLocation(__DIR__.'/Fixtures');
23+
$app['view']->addLocation(__DIR__.'/Fixtures');
2524

26-
app('translator')->setLoaded([
25+
$app['translator']->setLoaded([
2726
'*' => [
2827
'*' => [
2928
'en' => ['nom' => 'name'],

tests/Integration/Mail/SendingMarkdownMailTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Illuminate\Mail\Mailables\Envelope;
88
use Illuminate\Mail\Markdown;
99
use Illuminate\Support\Facades\Mail;
10-
use Illuminate\Support\Facades\View;
1110
use Orchestra\Testbench\TestCase;
1211

1312
class SendingMarkdownMailTest extends TestCase
@@ -16,8 +15,8 @@ protected function getEnvironmentSetUp($app)
1615
{
1716
$app['config']->set('mail.driver', 'array');
1817

19-
View::addNamespace('mail', __DIR__.'/Fixtures');
20-
View::addLocation(__DIR__.'/Fixtures');
18+
$app['view']->addNamespace('mail', __DIR__.'/Fixtures')
19+
->addLocation(__DIR__.'/Fixtures');
2120
}
2221

2322
public function testMailIsSent()

tests/Integration/Mail/SendingQueuedMailTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Illuminate\Queue\Middleware\RateLimited;
88
use Illuminate\Support\Facades\Mail;
99
use Illuminate\Support\Facades\Queue;
10-
use Illuminate\Support\Facades\View;
1110
use Orchestra\Testbench\TestCase;
1211

1312
class SendingQueuedMailTest extends TestCase
@@ -16,7 +15,7 @@ protected function getEnvironmentSetUp($app)
1615
{
1716
$app['config']->set('mail.driver', 'array');
1817

19-
View::addLocation(__DIR__.'/Fixtures');
18+
$app['view']->addLocation(__DIR__.'/Fixtures');
2019
}
2120

2221
public function testMailIsSentWithDefaultLocale()

tests/Integration/Mail/SentMessageMailTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Database\Eloquent\Model;
66
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
78
use Illuminate\Notifications\Events\NotificationSent;
89
use Illuminate\Notifications\Messages\MailMessage;
910
use Illuminate\Notifications\Notifiable;
@@ -14,15 +15,20 @@
1415

1516
class SentMessageMailTest extends TestCase
1617
{
17-
protected function setUp(): void
18-
{
19-
parent::setUp();
18+
use LazilyRefreshDatabase;
2019

20+
protected function afterRefreshingDatabase()
21+
{
2122
Schema::create('sent_message_users', function (Blueprint $table) {
2223
$table->increments('id');
2324
});
2425
}
2526

27+
protected function beforeRefreshingDatabase()
28+
{
29+
Schema::dropIfExists('sent_message_users');
30+
}
31+
2632
public function testDispatchesNotificationSent()
2733
{
2834
$notificationWasSent = false;

tests/Integration/Notifications/SendingMailNotificationsTest.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Illuminate\Notifications\Notifiable;
1515
use Illuminate\Notifications\Notification;
1616
use Illuminate\Support\Facades\Schema;
17-
use Illuminate\Support\Facades\View;
1817
use Illuminate\Support\Str;
1918
use Mockery as m;
2019
use Orchestra\Testbench\TestCase;
@@ -25,14 +24,7 @@ class SendingMailNotificationsTest extends TestCase
2524
public $mailer;
2625
public $markdown;
2726

28-
protected function tearDown(): void
29-
{
30-
parent::tearDown();
31-
32-
m::close();
33-
}
34-
35-
protected function getEnvironmentSetUp($app)
27+
protected function defineEnvironment($app)
3628
{
3729
$this->mailFactory = m::mock(MailFactory::class);
3830
$this->mailer = m::mock(Mailer::class);
@@ -51,7 +43,7 @@ protected function getEnvironmentSetUp($app)
5143
return $this->mailFactory;
5244
});
5345

54-
View::addLocation(__DIR__.'/Fixtures');
46+
$app['view']->addLocation(__DIR__.'/Fixtures');
5547
}
5648

5749
protected function setUp(): void

tests/Integration/Notifications/SendingMailableNotificationsTest.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,42 @@
44

55
use Illuminate\Database\Eloquent\Model;
66
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Foundation\Testing\RefreshDatabase;
78
use Illuminate\Notifications\Messages\MailMessage;
89
use Illuminate\Notifications\Notifiable;
910
use Illuminate\Notifications\Notification;
1011
use Illuminate\Support\Facades\Schema;
11-
use Illuminate\Support\Facades\View;
1212
use Orchestra\Testbench\TestCase;
1313

1414
class SendingMailableNotificationsTest extends TestCase
1515
{
16-
public $mailer;
16+
use RefreshDatabase;
1717

18-
protected function getEnvironmentSetUp($app)
18+
protected function defineEnvironment($app)
1919
{
2020
$app['config']->set('mail.driver', 'array');
2121

2222
$app['config']->set('app.locale', 'en');
2323

2424
$app['config']->set('mail.markdown.theme', 'blank');
2525

26-
View::addLocation(__DIR__.'/Fixtures');
26+
$app['view']->addLocation(__DIR__.'/Fixtures');
2727
}
2828

29-
protected function setUp(): void
29+
protected function afterRefreshingDatabase()
3030
{
31-
parent::setUp();
32-
3331
Schema::create('users', function (Blueprint $table) {
3432
$table->increments('id');
3533
$table->string('email');
3634
$table->string('name')->nullable();
3735
});
3836
}
3937

38+
protected function beforeRefreshingDatabase()
39+
{
40+
Schema::dropIfExists('users');
41+
}
42+
4043
public function testMarkdownNotification()
4144
{
4245
$user = MailableNotificationUser::forceCreate([

tests/Integration/Notifications/SendingNotificationsViaAnonymousNotifiableTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
class SendingNotificationsViaAnonymousNotifiableTest extends TestCase
1212
{
13-
public $mailer;
14-
1513
public function testMailIsSent()
1614
{
1715
$notifiable = (new AnonymousNotifiable)

tests/Integration/Notifications/SendingNotificationsWithLocaleTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,20 @@
1515
use Illuminate\Support\Facades\Event;
1616
use Illuminate\Support\Facades\Notification as NotificationFacade;
1717
use Illuminate\Support\Facades\Schema;
18-
use Illuminate\Support\Facades\View;
1918
use Illuminate\Testing\Assert;
2019
use Orchestra\Testbench\TestCase;
2120

2221
class SendingNotificationsWithLocaleTest extends TestCase
2322
{
24-
public $mailer;
25-
26-
protected function getEnvironmentSetUp($app)
23+
protected function defineEnvironment($app)
2724
{
2825
$app['config']->set('mail.driver', 'array');
2926

3027
$app['config']->set('app.locale', 'en');
3128

32-
View::addLocation(__DIR__.'/Fixtures');
29+
$app['view']->addLocation(__DIR__.'/Fixtures');
3330

34-
app('translator')->setLoaded([
31+
$app['translator']->setLoaded([
3532
'*' => [
3633
'*' => [
3734
'en' => ['hi' => 'hello'],

0 commit comments

Comments
 (0)