Completed
Push — master ( d46a90...0d9294 )
by
unknown
43:57 queued 02:43
created

ExceptionHandlerTest::testReport()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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