Completed
Pull Request — master (#145)
by Thanos
04:23
created

PathHelperTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 23
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A testGenerateRoutes() 0 20 3
1
<?php
2
namespace Liip\MonitorBundle\Tests\Helper;
3
4
use Liip\MonitorBundle\Helper\PathHelper;
5
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpKernel\Kernel;
8
9
class PathHelperTest extends WebTestCase
10
{
11
    public function testGenerateRoutes()
12
    {
13
        $client = static::createClient(array('environment' => 'symfony' . Kernel::MAJOR_VERSION));
14
15
        $container = $client->getContainer();
16
17
        // mock a request flow to allow testing without enabling assets
18
        if (Kernel::MAJOR_VERSION === 2 && Kernel::MINOR_VERSION < 8) {
19
            $request = new Request();
20
            $container->enterScope('request');
0 ignored issues
show
Bug introduced by
The method enterScope() does not seem to exist on object<Symfony\Component...ion\ContainerInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
21
            $container->set('request', $request, 'request');
0 ignored issues
show
Unused Code introduced by
The call to ContainerInterface::set() has too many arguments starting with 'request'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
22
        }
23
24
        $pathHelper = new PathHelper($container);
0 ignored issues
show
Bug introduced by
It seems like $container defined by $client->getContainer() on line 15 can be null; however, Liip\MonitorBundle\Helpe...thHelper::__construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
25
26
        // test route is defined in Tests/app/routing.yml
27
        $routes = $pathHelper->generateRoutes(['test_route' => []]);
28
29
        $this->assertEquals(['api.test_route = "/monitor";'], $routes);
30
    }
31
}
32