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\RequestListener; |
17
|
|
|
use Ekino\NewRelicBundle\NewRelic\Config; |
18
|
|
|
use Ekino\NewRelicBundle\NewRelic\NewRelicInteractorInterface; |
19
|
|
|
use Ekino\NewRelicBundle\TransactionNamingStrategy\TransactionNamingStrategyInterface; |
20
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
21
|
|
|
use Symfony\Component\HttpFoundation\Request; |
22
|
|
|
use Symfony\Component\HttpFoundation\Response; |
23
|
|
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent; |
|
|
|
|
24
|
|
|
use Symfony\Component\HttpKernel\Event\RequestEvent; |
25
|
|
|
use Symfony\Component\HttpKernel\HttpKernelInterface; |
26
|
|
|
|
27
|
|
|
class RequestListenerTest extends TestCase |
28
|
|
|
{ |
29
|
|
|
public function testSubRequest() |
30
|
|
|
{ |
31
|
|
|
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
32
|
|
|
$interactor->expects($this->never())->method('setTransactionName'); |
33
|
|
|
|
34
|
|
|
$namingStrategy = $this->getMockBuilder(TransactionNamingStrategyInterface::class)->getMock(); |
35
|
|
|
|
36
|
|
|
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); |
37
|
|
|
|
38
|
|
|
$eventClass = \class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; |
39
|
|
|
$event = new $eventClass($kernel, new Request(), HttpKernelInterface::SUB_REQUEST, new Response()); |
40
|
|
|
|
41
|
|
|
$listener = new RequestListener(new Config('App name', 'Token'), $interactor, [], [], $namingStrategy); |
42
|
|
|
$listener->setApplicationName($event); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testMasterRequest() |
46
|
|
|
{ |
47
|
|
|
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
48
|
|
|
$interactor->expects($this->once())->method('setTransactionName'); |
49
|
|
|
|
50
|
|
|
$namingStrategy = $this->getMockBuilder(TransactionNamingStrategyInterface::class) |
51
|
|
|
->setMethods(['getTransactionName']) |
52
|
|
|
->getMock(); |
53
|
|
|
$namingStrategy->expects($this->once())->method('getTransactionName')->willReturn('foobar'); |
54
|
|
|
|
55
|
|
|
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); |
56
|
|
|
|
57
|
|
|
$eventClass = \class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; |
58
|
|
|
$event = new $eventClass($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, new Response()); |
59
|
|
|
|
60
|
|
|
$listener = new RequestListener(new Config('App name', 'Token'), $interactor, [], [], $namingStrategy); |
61
|
|
|
$listener->setTransactionName($event); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testPathIsIgnored() |
65
|
|
|
{ |
66
|
|
|
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
67
|
|
|
$interactor->expects($this->once())->method('ignoreTransaction'); |
68
|
|
|
|
69
|
|
|
$namingStrategy = $this->getMockBuilder(TransactionNamingStrategyInterface::class)->getMock(); |
70
|
|
|
|
71
|
|
|
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); |
72
|
|
|
$request = new Request([], [], [], [], [], ['REQUEST_URI' => '/ignored_path']); |
73
|
|
|
|
74
|
|
|
$eventClass = \class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; |
75
|
|
|
$event = new $eventClass($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new Response()); |
76
|
|
|
|
77
|
|
|
$listener = new RequestListener(new Config('App name', 'Token'), $interactor, [], ['/ignored_path'], $namingStrategy); |
78
|
|
|
$listener->setIgnoreTransaction($event); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testRouteIsIgnored() |
82
|
|
|
{ |
83
|
|
|
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
84
|
|
|
$interactor->expects($this->once())->method('ignoreTransaction'); |
85
|
|
|
|
86
|
|
|
$namingStrategy = $this->getMockBuilder(TransactionNamingStrategyInterface::class)->getMock(); |
87
|
|
|
|
88
|
|
|
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); |
89
|
|
|
$request = new Request([], [], ['_route' => 'ignored_route']); |
90
|
|
|
|
91
|
|
|
$eventClass = \class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; |
92
|
|
|
$event = new $eventClass($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new Response()); |
93
|
|
|
|
94
|
|
|
$listener = new RequestListener(new Config('App name', 'Token'), $interactor, ['ignored_route'], [], $namingStrategy); |
95
|
|
|
$listener->setIgnoreTransaction($event); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testSymfonyCacheEnabled() |
99
|
|
|
{ |
100
|
|
|
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
101
|
|
|
$interactor->expects($this->once())->method('startTransaction'); |
102
|
|
|
|
103
|
|
|
$namingStrategy = $this->getMockBuilder(TransactionNamingStrategyInterface::class)->getMock(); |
104
|
|
|
|
105
|
|
|
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); |
106
|
|
|
|
107
|
|
|
$eventClass = \class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; |
108
|
|
|
$event = new $eventClass($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, new Response()); |
109
|
|
|
|
110
|
|
|
$listener = new RequestListener(new Config('App name', 'Token'), $interactor, [], [], $namingStrategy, true); |
111
|
|
|
$listener->setApplicationName($event); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function testSymfonyCacheDisabled() |
115
|
|
|
{ |
116
|
|
|
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
117
|
|
|
$interactor->expects($this->never())->method('startTransaction'); |
118
|
|
|
|
119
|
|
|
$namingStrategy = $this->getMockBuilder(TransactionNamingStrategyInterface::class)->getMock(); |
120
|
|
|
|
121
|
|
|
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); |
122
|
|
|
|
123
|
|
|
$eventClass = \class_exists(RequestEvent::class) ? RequestEvent::class : GetResponseEvent::class; |
124
|
|
|
$event = new $eventClass($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, new Response()); |
125
|
|
|
|
126
|
|
|
$listener = new RequestListener(new Config('App name', 'Token'), $interactor, [], [], $namingStrategy, false); |
127
|
|
|
$listener->setApplicationName($event); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths