ExceptionHandlerTest::testReport()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SfCod\QueueBundle\Tests\Handler;
4
5
use Exception;
6
use PHPUnit\Framework\TestCase;
7
use Psr\Log\LoggerInterface;
8
use SfCod\QueueBundle\Handler\ExceptionHandler;
9
10
/**
11
 * Class ExceptionHandlerTest
12
 *
13
 * @author Virchenko Maksim <[email protected]>
14
 *
15
 * @package SfCod\QueueBundle\Tests\Handler
16
 */
17
class ExceptionHandlerTest extends TestCase
18
{
19
    /**
20
     * Test handler report
21
     */
22
    public function testReport()
23
    {
24
        $message = uniqid('message_');
25
26
        $exception = new Exception($message);
27
        $logger = $this->mockLogger($exception);
28
        $handler = $this->mockHandler($logger);
29
30
        $handler->report($exception);
31
    }
32
33
    /**
34
     * Mock logger
35
     *
36
     * @param Exception $exception
37
     *
38
     * @return LoggerInterface
39
     */
40
    private function mockLogger(Exception $exception): LoggerInterface
41
    {
42
        $logger = $this->createMock(LoggerInterface::class);
43
        $logger
44
            ->expects(self::once())
45
            ->method('error')
46
            ->with(self::equalTo($exception->getMessage()), self::equalTo(['exception' => $exception]));
47
48
        return $logger;
49
    }
50
51
    /**
52
     * Mock exception handler
53
     *
54
     * @return ExceptionHandler
55
     */
56
    private function mockHandler(LoggerInterface $logger): ExceptionHandler
57
    {
58
        $handler = $this->getMockBuilder(ExceptionHandler::class)
59
            ->setConstructorArgs([$logger])
60
            ->setMethods(null)
61
            ->getMock();
62
63
        return $handler;
64
    }
65
}
66