8000 [11.x] Test Improvements (#55549) · laravel/framework@401649c · GitHub
[go: up one dir, main page]

Skip to content

Commit 401649c

Browse files
authored
[11.x] Test Improvements (#55549)
- Split redundant code Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
1 parent 3557d14 commit 401649c

File tree

4 files changed

+77
-139
lines changed

4 files changed

+77
-139
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
"league/flysystem-read-only": "^3.25.1",
112112
"league/flysystem-sftp-v3": "^3.25.1",
113113
"mockery/mockery": "^1.6.10",
114-
"orchestra/testbench-core": "^9.11.2",
114+
"orchestra/testbench-core": "^9.13.2",
115115
"pda/pheanstalk": "^5.0.6",
116116
"php-http/discovery": "^1.15",
117117
"phpstan/phpstan": "^2.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace Illuminate\Tests\Integration\Mail;
4+
5+
use Illuminate\Mail\Mailable;
6+
use Illuminate\Mail\Mailables\Content;
7+
use Illuminate\Mail\Mailables\Envelope;
8+
use Orchestra\Testbench\TestCase;
9+
use PHPUnit\Framework\Attributes\DataProvider;
10+
11+
abstract class MailableTestCase extends TestCase
12+
{
13+
/** {@inheritdoc} */
14+
#[\Override]
15+
protected function defineEnvironment($app)
16+
{
17+
$app['view']->addLocation(__DIR__.'/Fixtures');
18+
}
19+
20+
#[DataProvider('markdownEncodedDataProvider')]
21+
public function testItCanAssertMarkdownEncodedString($given, $expected)
22+
{
23+
$mailable = new class($given) extends Mailable
24+
{
25+
public function __construct(public string $message)
26+
{
27+
//
28+
}
29+
30+
public function envelope()
31+
{
32+
return new Envelope(
33+
subject: 'My basic title',
34+
);
35+
}
36< 8000 span class="diff-text-marker">+
37+
public function content()
38+
{
39+
return new Content(
40+
markdown: 'message',
41+
);
42+
}
43+
};
44+
45+
$mailable->assertSeeInHtml($expected, false);
46+
}
47+
48+
public static function markdownEncodedDataProvider()
49+
{
50+
yield ['[Laravel](https://laravel.com)', 'My message is: [Laravel](https://laravel.com)'];
51+
52+
yield [
53+
'![Welcome to Laravel](https://laravel.com/assets/img/welcome/background.svg)',
54+
'My message is: ![Welcome to Laravel](https://laravel.com/assets/img/welcome/background.svg)',
55+
];
56+
57+
yield [
58+
'Visit https://laravel.com/docs to browse the documentation',
59+
'My message is: Visit https://laravel.com/docs to browse the documentation',
60+
];
61+
62+
yield [
63+
'Visit <https://laravel.com/docs> to browse the documentation',
64+
'My message is: Visit &lt;https://laravel.com/docs&gt; to browse the documentation',
65+
];
66+
67+
yield [
68+
'Visit <span>https://laravel.com/docs</span> to browse the documentation',
69+
'My message is: Visit &lt;span&gt;https://laravel.com/docs&lt;/span&gt; to browse the documentation',
70+
];
71+
}
72+
}

tests/Integration/Mail/MailableWithSecuredEncodingTest.php

+2-69
Original file line numberDiff line numberDiff line change
@@ -5,91 +5,24 @@
55
use Illuminate\Foundation\Auth\User;
66
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
77
use Illuminate\Mail\Mailable;
8-
use Illuminate\Mail\Mailables\Content;
9-
use Illuminate\Mail\Mailables\Envelope;
108
use Illuminate\Mail\Markdown;
11-
use Illuminate\Support\EncodedHtmlString;
129
use Orchestra\Testbench\Attributes\WithMigration;
1310
use Orchestra\Testbench\Factories\UserFactory;
14-
use Orchestra\Testbench\TestCase;
1511
use PHPUnit\Framework\Attributes\DataProvider;
1612

17-
class MailableWithSecuredEncodingTest extends TestCase
13+
class MailableWithSecuredEncodingTest extends MailableTestCase
1814
{
1915
use LazilyRefreshDatabase;
2016

21-
/** {@inheritdoc} */
22-
#[\Override]
23-
protected function tearDown(): void
24-
{
25-
Markdown::flushState();
26-
EncodedHtmlString::flushState();
27-
28-
parent::tearDown();
29-
}
30-
3117
/** {@inheritdoc} */
3218
#[\Override]
3319
protected function defineEnvironment($app)
3420
{
35-
$app['view']->addLocation(__DIR__.'/Fixtures');
21+
parent::defineEnvironment($app);
3622

3723
Markdown::withSecuredEncoding();
3824
}
3925

40-
#[DataProvider('markdownEncodedDataProvider')]
41-
public function testItCanAssertMarkdownEncodedString($given, $expected)
42-
{
43-
$mailable = new class($given) extends Mailable
44-
{
45-
public function __construct(public string $message)
46-
{
47-
//
48-
}
49-
50-
public function envelope()
51-
{
52-
return new Envelope(
53-
subject: 'My basic title',
54-
);
55-
}
56-
57-
public function content()
58-
{
59-
return new Content(
60-
markdown: 'message',
61-
);
62-
}
63-
};
64-
65-
$mailable->assertSeeInHtml($expected, false);
66-
}
67-
68-
public static function markdownEncodedDataProvider()
69-
{
70-
yield ['[Laravel](https://laravel.com)', 'My message is: [Laravel](https://laravel.com)'];
71-
72-
yield [
73-
'![Welcome to Laravel](https://laravel.com/assets/img/welcome/background.svg)',
74-
'My message is: ![Welcome to Laravel](https://laravel.com/assets/img/welcome/background.svg)',
75-
];
76-
77-
yield [
78-
'Visit https://laravel.com/docs to browse the documentation',
79-
'My message is: Visit https://laravel.com/docs to browse the documentation',
80-
];
81-
82-
yield [
83-
'Visit <https://laravel.com/docs> to browse the documentation',
84-
'My message is: Visit &lt;https://laravel.com/docs&gt; to browse the documentation',
85-
];
86-
87-
yield [
88-
'Visit <span>https://laravel.com/docs</span> to browse the documentation',
89-
'My message is: Visit &lt;span&gt;https://laravel.com/docs&lt;/span&gt; to browse the documentation',
90-
];
91-
}
92-
9326
#[WithMigration]
9427
#[DataProvider('markdownEncodedTemplateDataProvider')]
9528
public function testItCanAssertMarkdownEncodedStringUsingTemplate($given, $expected)

tests/Integration/Mail/MailableWithoutSecuredEncodingTest.php

+2-69
Original file line numberDiff line numberDiff line change
@@ -5,91 +5,24 @@
55
use Illuminate\Foundation\Auth\User;
66
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
77
use Illuminate\Mail\Mailable;
8-
use Illuminate\Mail\Mailables\Content;
9-
use Illuminate\Mail\Mailables\Envelope;
108
use Illuminate\Mail\Markdown;
11-
use Illuminate\Support\EncodedHtmlString;
129
use Orchestra\Testbench\Attributes\WithMigration;
1310
use Orchestra\Testbench\Factories\UserFactory;
14-
use Orchestra\Testbench\TestCase;
1511
use PHPUnit\Framework\Attributes\DataProvider;
1612

17-
class MailableWithoutSecuredEncodingTest extends TestCase
13+
class MailableWithoutSecuredEncodingTest extends MailableTestCase
1814
{
1915
use LazilyRefreshDatabase;
2016

21-
/** {@inheritdoc} */
22-
#[\Override]
23-
protected function tearDown(): void
24-
{
25-
Markdown::flushState();
26-
EncodedHtmlString::flushState();
27-
28-
parent::tearDown();
29-
}
30-
3117
/** {@inheritdoc} */
3218
#[\Override]
3319
protected function defineEnvironment($app)
3420
{
35-
$app['view']->addLocation(__DIR__.'/Fixtures');
21+
parent::defineEnvironment($app);
3622

3723
Markdown::withoutSecuredEncoding();
3824
}
3925

40-
#[DataProvider('markdownEncodedDataProvider')]
41-
public function testItCanAssertMarkdownEncodedString($given, $expected)
42-
{
43-
$mailable = new class($given) extends Mailable
44-
{
45-
public function __construct(public string $message)
46-
{
47-
//
48-
}
49-
50-
public function envelope()
51-
{
52-
return new Envelope(
53-
subject: 'My basic title',
54-
);
55-
}
56-
57-
public function content()
58-
{
59-
return new Content(
60-
markdown: 'message',
61-
);
62-
}
63-
};
64-
65-
$mailable->assertSeeInHtml($expected, false);
66-
}
67-
68-
public static function markdownEncodedDataProvider()
69-
{
70-
yield ['[Laravel](https://laravel.com)', 'My message is: [Laravel](https://laravel.com)'];
71-
72-
yield [
73-
'![Welcome to Laravel](https://laravel.com/assets/img/welcome/background.svg)',
74-
'My message is: ![Welcome to Laravel](https://laravel.com/assets/img/welcome/background.svg)',
75-
];
76-
77-
yield [
78-
'Visit https://laravel.com/docs to browse the documentation',
79-
'My message is: Visit https://laravel.com/docs to browse the documentation',
80-
];
81-
82-
yield [
83-
'Visit <https://laravel.com/docs> to browse the documentation',
84-
'My message is: Visit &lt;https://laravel.com/docs&gt; to browse the documentation',
85-
];
86-
87-
yield [
88-
'Visit <span>https://laravel.com/docs</span> to browse the documentation',
89-
'My message is: Visit &lt;span&gt;https://laravel.com/docs&lt;/span&gt; to browse the documentation',
90-
];
91-
}
92-
9326
#[WithMigration]
9427
#[DataProvider('markdownEncodedTemplateDataProvider')]
9528
public function testItCanAssertMarkdownEncodedStringUsingTemplate($given, $expected)

0 commit comments

Comments
 (0)
0