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

PathHelperTest::testGenerateRoutes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
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