Failed Conditions
Push — master ( 5f5e96...daf37e )
by Adrien
03:02
created

MailerHandlerTest::testHandle()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 20
rs 9.8333
c 1
b 0
f 0
cc 2
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EcodevTests\Felix\Log\Handler;
6
7
use DateTimeImmutable;
8
use Ecodev\Felix\Api\ExceptionWithoutMailLogging;
9
use Ecodev\Felix\Log\Handler\MailerHandler;
10
use Exception;
11
use GraphQL\Error\Error;
12
use Monolog\Level;
13
use Monolog\LogRecord;
14
use PHPUnit\Framework\TestCase;
15
use Symfony\Component\Mailer\Transport\TransportInterface;
16
use Symfony\Component\Mime\Email;
17
18
class MailerHandlerTest extends TestCase
19
{
20
    /**
21
     * @dataProvider providerHandle
22
     */
23
    public function testHandle(array $event, bool $expected): void
24
    {
25
        $record = new LogRecord(
26
            new DateTimeImmutable(),
27
            '',
28
            Level::Error,
29
            '',
30
            $event,
31
        );
32
33
        $mockObject = $this->createMock(TransportInterface::class);
34
        $mockObject->expects(self::exactly($expected ? 1 : 0))
35
            ->method('send');
36
37
        $handler = new MailerHandler($mockObject, new Email());
38
        $actual = $handler->isHandling($record);
39
40
        self::assertSame($expected, $actual);
41
42
        $handler->handle($record);
43
    }
44
45
    public static function providerHandle(): array
46
    {
47
        return [
48
            [[], true],
49
            [['exception' => null], true],
50
            [['exception' => []], true],
51
            [['exception' => new Exception()], true],
52
            [['exception' => new Exception('', 0, new Exception())], true],
53
            [['exception' => new Exception('', 0, new ExceptionWithoutMailLogging())], true],
54
            [['exception' => new ExceptionWithoutMailLogging()], false],
55
            [['exception' => new Error()], true],
56
            [['exception' => new Error('', null, null, [], null, new Exception())], true],
57
            [['exception' => new Error('', null, null, [], null, new ExceptionWithoutMailLogging())], false],
58
        ];
59
    }
60
}
61