Completed
Pull Request — master (#145)
by Thanos
02:22
created

PathHelperTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A testGenerateRoutes() 0 13 1
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\HttpKernel\Kernel;
7
8
class PathHelperTest extends WebTestCase
9
{
10
    public function testGenerateRoutes()
11
    {
12
        $client = static::createClient(array('environment' => 'symfony' . Kernel::MAJOR_VERSION));
13
14
        $container = $client->getContainer();
15
16
        $pathHelper = new PathHelper($container);
0 ignored issues
show
Bug introduced by
It seems like $container defined by $client->getContainer() on line 14 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...
17
18
        // test route is defined in Tests/app/routing.yml
19
        $routes = $pathHelper->generateRoutes(['test_route' => []]);
20
21
        $this->assertEquals(['api.test_route = "/monitor";'], $routes);
22
    }
23
}
24