Completed
Pull Request — master (#203)
by Tobias
34:49
created

ControllerNamingStrategyTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 16
dl 0
loc 36
rs 10
c 0
b 0
f 0
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\TransactionNamingStrategy;
15
16
use PHPUnit\Framework\TestCase;
17
use Symfony\Component\HttpFoundation\Request;
18
19
class ControllerNamingStrategyTest extends TestCase
20
{
21
    public function testControllerAsString()
22
    {
23
        $request = new Request();
24
        $request->attributes->set('_controller', 'SomeBundle:Some:SomeAction');
25
26
        $strategy = new ControllerNamingStrategy();
27
        $this->assertSame('SomeBundle:Some:SomeAction', $strategy->getTransactionName($request));
28
    }
29
30
    public function testControllerAsClosure()
31
    {
32
        $request = new Request();
33
        $request->attributes->set('_controller', function () {
34
        });
35
36
        $strategy = new ControllerNamingStrategy();
37
        $this->assertSame('Closure controller', $strategy->getTransactionName($request));
38
    }
39
40
    public function testControllerAsCallback()
41
    {
42
        $request = new Request();
43
        $request->attributes->set('_controller', [$this, 'testControllerAsString']);
44
45
        $strategy = new ControllerNamingStrategy();
46
        $this->assertSame('Callback contoller: Ekino\NewRelicBundle\TransactionNamingStrategy\ControllerNamingStrategyTest::testControllerAsString()', $strategy->getTransactionName($request));
47
    }
48
49
    public function testControllerUnknown()
50
    {
51
        $request = new Request();
52
53
        $strategy = new ControllerNamingStrategy();
54
        $this->assertSame('Unknown Symfony controller', $strategy->getTransactionName($request));
55
    }
56
}
57