Completed
Push — master ( 080928...f7c290 )
by
unknown
15:37
created

tests/WebTest/Dashboard/TreeBrowserTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Sonata\DoctrinePHPCRAdminBundle\Tests\WebTest\Dashboard;
4
5
use Symfony\Cmf\Component\Testing\Functional\BaseTestCase;
6
7
/**
8
 * @author Maximilian Berghoff <[email protected]>
9
 */
10
class TreeBrowserTest extends BaseTestCase
11
{
12
    public function setUp()
13
    {
14
        $this->db('PHPCR')->loadFixtures(array('Sonata\DoctrinePHPCRAdminBundle\Tests\Resources\DataFixtures\Phpcr\LoadTreeData'));
15
        $this->client = $this->createClient();
16
    }
17
18
    public function testTreeOnDashboardLoadsWithNoErrors()
19
    {
20
        $crawler = $this->client->request('GET', '/admin/dashboard');
21
        $res = $this->client->getResponse();
22
23
        $this->assertResponseSuccess($res);
0 ignored issues
show
It seems like $res defined by $this->client->getResponse() on line 21 can be null; however, Symfony\Cmf\Component\Te...assertResponseSuccess() 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...
24
25
        $this->assertCount(1, $crawler->filter('div#tree'));
26
    }
27
}
28