FormLoginTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 54
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testLoginWithValidUser() 0 16 1
A testLoginWithInvalidUser() 0 15 1
1
<?php
2
3
namespace OpenOrchestra\FunctionalTests\BackOfficeBundle\Security;
4
5
use OpenOrchestra\BaseBundle\Tests\AbstractTest\AbstractWebTestCase;
6
use Symfony\Bundle\FrameworkBundle\Client;
7
8
/**
9
 * Class FormLoginTest
10
 */
11
class FormLoginTest extends AbstractWebTestCase
12
{
13
    /**
14
     * @var Client
15
     */
16
    protected $client;
17
18
    /**
19
     * Set up the test
20
     */
21
    public function setUp()
22
    {
23
        $this->client = static::createClient();
24
    }
25
26
    /**
27
     * Test form login with valid user
28
     */
29
    public function testLoginWithValidUser()
30
    {
31
        $userName = 'p-admin';
32
        $password = 'p-admin';
33
        $crawler = $this->client->request('GET', '/login');
34
35
        $form = $crawler->selectButton('Log in')->form();
36
        $form['_username'] = $userName;
37
        $form['_password'] = $password;
38
        $this->client->submit($form);
0 ignored issues
show
Documentation introduced by
$form is of type array<string,string,{"_password":"string"}>, but the function expects a object<Symfony\Component\DomCrawler\Form>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
39
40
        $this->assertEquals(302, $this->client->getResponse()->getStatusCode());
41
        $user = $this->client->getContainer()->get('security.token_storage')->getToken()->getUser();
42
        $this->assertInstanceOf('OpenOrchestra\UserBundle\Model\UserInterface', $user);
43
        $this->assertEquals($user->getUserName(), $userName);
44
    }
45
46
    /**
47
     * Test form login with invalid user
48
     */
49
    public function testLoginWithInvalidUser()
50
    {
51
        $userName = 'invalidUserName';
52
        $password = 'invalidUserName';
53
        $crawler = $this->client->request('GET', '/login');
54
55
        $form = $crawler->selectButton('Log in')->form();
56
        $form['_username'] = $userName;
57
        $form['_password'] = $password;
58
        $this->client->submit($form);
0 ignored issues
show
Documentation introduced by
$form is of type array<string,string,{"_password":"string"}>, but the function expects a object<Symfony\Component\DomCrawler\Form>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
59
60
        $this->assertEquals(302, $this->client->getResponse()->getStatusCode());
61
        $token = $this->client->getContainer()->get('security.token_storage')->getToken();
62
        $this->assertNull($token);
63
    }
64
}
65