Completed
Push — master ( 61d54e...4a5166 )
by Sam
03:19
created

PagesControllerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 5
c 1
b 1
f 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Tests\AppBundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
use Symfony\Component\DependencyInjection\Container;
7
8
class PagesControllerTest extends WebTestCase
9
{
10
    /** @var Container */
11
    protected $container;
12
13
    public function setUp()
14
    {
15
        $client = static::createClient();
16
        $this->container = $client->getContainer();
0 ignored issues
show
Documentation Bug introduced by
It seems like $client->getContainer() can also be of type object<Symfony\Component...ion\ContainerInterface>. However, the property $container is declared as type object<Symfony\Component...ncyInjection\Container>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
17
    }
18
19
    public function testIndex()
20
    {
21
        $client = static::createClient();
22
23
        $crawler = $client->request('GET', '/pages');
0 ignored issues
show
Unused Code introduced by
$crawler is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
24
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
25
26
        if ($this->container->getParameter('app.is_labs') && !$this->container->getParameter('app.single_wiki')) {
27
            $crawler = $client->request('GET', '/pages/de.wikipedia.org');
28
            $this->assertEquals(200, $client->getResponse()->getStatusCode());
29
30
            // should populate project input field
31
            $this->assertEquals('de.wikipedia.org', $crawler->filter('#project_input')->attr('value'));
32
33
            // assert that the namespaces were correctly loaded from API
34
            $namespaceOptions = $crawler->filter('#namespace_select option');
35
            $this->assertEquals('Diskussion', trim($namespaceOptions->eq(2)->text())); // Talk in German
36
        }
37
    }
38
}
39