Completed
Push — master ( 6366df...fbe022 )
by Kirill
23s queued 19s
created

RenderTest::tearDown()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\SendIt;
13
14
use PHPUnit\Framework\TestCase;
15
use Spiral\Tests\SendIt\App\App;
16
use Spiral\Mailer\Exception\MailerException;
17
use Spiral\Mailer\Message;
18
19
/**
20
 * @requires function \Spiral\Framework\Kernel::init
21
 */
22
class RenderTest extends TestCase
23
{
24
    private $app;
25
26
    public function setUp(): void
27
    {
28
        $this->app = App::init([
29
            'root' => __DIR__ . '/App',
30
            'app'  => __DIR__ . '/App'
31
        ]);
32
    }
33
34
    public function tearDown(): void
35
    {
36
        foreach (glob(__DIR__ . '/App/runtime/cache/views/*.php') as $file) {
37
            @unlink($file);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

37
            /** @scrutinizer ignore-unhandled */ @unlink($file);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
38
        }
39
    }
40
41
    public function testRenderError(): void
42
    {
43
        $this->expectException(MailerException::class);
44
        $this->app->send(new Message('test', ['[email protected]'], ['name' => 'Antony']));
45
    }
46
47
    public function testRender(): void
48
    {
49
        $email = $this->app->send(new Message('email', ['[email protected]'], ['name' => 'Antony']));
50
51
        $this->assertSame('Demo Email', $email->getSubject());
52
53
        $body = $email->getBody()->toString();
54
        $this->assertStringContainsString('bootstrap.txt', $body);
55
        $this->assertStringContainsString('<p>Hello, Antony!</p>', $body);
56
    }
57
}
58