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

Tests/Listener/RequestListenerTest.php (6 issues)

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);
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Component\HttpKe...\Event\GetResponseEvent has been deprecated: since Symfony 4.3, use RequestEvent instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

37
        $event = /** @scrutinizer ignore-deprecated */ new GetResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST);
Loading history...
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')->willReturn('foobar');
52
53
        $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
54
        $request = new Request();
55
56
        $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Component\HttpKe...\Event\GetResponseEvent has been deprecated: since Symfony 4.3, use RequestEvent instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

56
        $event = /** @scrutinizer ignore-deprecated */ new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
Loading history...
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);
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Component\HttpKe...\Event\GetResponseEvent has been deprecated: since Symfony 4.3, use RequestEvent instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

72
        $event = /** @scrutinizer ignore-deprecated */ new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
Loading history...
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);
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Component\HttpKe...\Event\GetResponseEvent has been deprecated: since Symfony 4.3, use RequestEvent instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

88
        $event = /** @scrutinizer ignore-deprecated */ new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
Loading history...
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);
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Component\HttpKe...\Event\GetResponseEvent has been deprecated: since Symfony 4.3, use RequestEvent instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

104
        $event = /** @scrutinizer ignore-deprecated */ new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
Loading history...
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);
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Component\HttpKe...\Event\GetResponseEvent has been deprecated: since Symfony 4.3, use RequestEvent instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

120
        $event = /** @scrutinizer ignore-deprecated */ new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
Loading history...
121
122
        $listener = new RequestListener(new Config('App name', 'Token'), $interactor, [], [], $namingStrategy, false);
123
        $listener->setApplicationName($event);
124
    }
125
}
126