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