Completed
Pull Request — master (#145)
by Thanos
10:29
created

PathHelperTest::testGenerateRoutes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 10
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 5
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
7
class PathHelperTest extends WebTestCase
8
{
9
    public function testGenerateRoutes()
10
    {
11
        $client = static::createClient(array('environment' => 'twig'));
12
        $pathHelper = new PathHelper($client->getContainer());
0 ignored issues
show
Bug introduced by
It seems like $client->getContainer() can be null; however, __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...
13
14
        // test route is defined in Tests/app/routing.yml
15
        $routes = $pathHelper->generateRoutes(['test_route' => []]);
16
17
        $this->assertEquals(['api.test_route = "/monitor";'], $routes);
18
    }
19
}
20