Completed
Push — master ( 558007...566e39 )
by Jérémy
23s queued 11s
created

ExceptionListenerTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 19
dl 0
loc 34
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testOnKernelException() 0 15 2
A testOnKernelExceptionWithHttp() 0 15 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Ekino New Relic bundle.
7
 *
8
 * (c) Ekino - Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Ekino\NewRelicBundle\Tests\Listener;
15
16
use Ekino\NewRelicBundle\Listener\ExceptionListener;
17
use Ekino\NewRelicBundle\NewRelic\NewRelicInteractorInterface;
18
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use Symfony\Component\HttpFoundation\Request;
20
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
21
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpKe...sponseForExceptionEvent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
23
use Symfony\Component\HttpKernel\HttpKernelInterface;
24
25
class ExceptionListenerTest extends TestCase
26
{
27
    public function testOnKernelException()
28
    {
29
        $exception = new \Exception('Boom');
30
31
        $interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock();
32
        $interactor->expects($this->once())->method('noticeThrowable')->with($exception);
33
34
        $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
35
        $request = new Request();
36
37
        $eventClass = \class_exists(ExceptionEvent::class) ? ExceptionEvent::class : GetResponseForExceptionEvent::class;
38
        $event = new $eventClass($kernel, $request, HttpKernelInterface::SUB_REQUEST, $exception);
39
40
        $listener = new ExceptionListener($interactor);
41
        $listener->onKernelException($event);
42
    }
43
44
    public function testOnKernelExceptionWithHttp()
45
    {
46
        $exception = new BadRequestHttpException('Boom');
47
48
        $interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock();
49
        $interactor->expects($this->never())->method('noticeThrowable');
50
51
        $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
52
        $request = new Request();
53
54
        $eventClass = \class_exists(ExceptionEvent::class) ? ExceptionEvent::class : GetResponseForExceptionEvent::class;
55
        $event = new $eventClass($kernel, $request, HttpKernelInterface::SUB_REQUEST, $exception);
56
57
        $listener = new ExceptionListener($interactor);
58
        $listener->onKernelException($event);
59
    }
60
}
61