Completed
Pull Request — dev (#22)
by
unknown
03:40
created

UserControllerTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 1
cbo 4
dl 0
loc 80
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testListAction() 0 10 1
B testAddAction() 0 27 1
A testActivationAction() 0 22 1
1
<?php
2
3
namespace Tests\AppBundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
use Symfony\Component\DependencyInjection\ContainerInterface;
7
use Doctrine\ORM\EntityManager;
8
use AppBundle\Entity\User;
9
10
class UserControllerTest extends WebTestCase
11
{
12
    public function testListAction() {
13
        $client = static::createClient();
14
        $crawler = $client->request('GET', '/users');
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...
15
        $this->assertEquals('302', $client->getResponse()->getStatusCode());
16
        $crawler = $client->request('GET', '/login');
17
        $form = $crawler->selectButton('Login')->form();
18
        $client->submit($form, ['_username' => '[email protected]', '_password' => 'ghjynj']);
19
        $crawler = $client->request('GET', '/users');
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...
20
        $this->assertEquals('200', $client->getResponse()->getStatusCode());
21
    }
22
23
    public function testAddAction()
24
    {
25
        $client = static::createClient();
26
        $crawler = $client->request('GET', '/login');
27
        $form = $crawler->selectButton('Login')->form();
28
        $client->submit($form, ['_username' => '[email protected]', '_password' => 'ghjynj']);
29
30
        $em = static::$kernel->getContainer()
31
            ->get('doctrine')
32
            ->getManager();
33
34
        $usersCount1 = count($em->getRepository('AppBundle:User')->findAll());
35
36
        $crawler = $client->request('GET', '/user/add');
37
        $form = $crawler->selectButton('Register')->form();
38
        //dump($form);
39
        $client->submit($form, [
40
            'registration[lastName]' => 'test',
41
            'registration[firstName]' => 'test',
42
            'registration[email]' => '[email protected]',
43
            'registration[plainPassword][first]' => 'test',
44
            'registration[plainPassword][second]' => 'test',
45
        ]);
46
47
        $usersCount2 = count($em->getRepository('AppBundle:User')->findAll());
48
        $this->assertEquals($usersCount1 + 1, $usersCount2);
49
    }
50
51
    public function testActivationAction()
52
    {
53
        $client = static::createClient();
54
        $crawler = $client->request('GET', '/login');
55
        $form = $crawler->selectButton('Login')->form();
56
        $client->submit($form, ['_username' => '[email protected]', '_password' => 'ghjynj']);
57
58
        $em = static::$kernel->getContainer()
59
            ->get('doctrine')
60
            ->getManager();
61
62
        $crawler = $client->request('GET', '/users');
63
64
        $form = $crawler->filter('table td form')->form();
65
        $url_params = explode('/', $form->getUri());
66
        $userid = $url_params[count($url_params)-1];
67
68
        $client->submit($form, ['activation[enabled]' => false]);
69
        $user = $em->getRepository('AppBundle:User')->findOneBy(array("id" => $userid));
70
71
        $this->assertEquals(false, $user->isEnabled());
72
    }
73
74
//    public function testEditAction()
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
75
//    {
76
//        $user = new User();
77
//        $user -> setEmail('[email protected]');
78
//        $user -> setLastName('Test');
79
//        $user -> setFirstName('Test');
80
//        $user -> setPlainPassword('Test');
81
//
82
//        $user -> setEmail('[email protected]');
83
//        $user -> setLastName('editedTest');
84
//        $user -> setFirstName('editedTest');
85
//        $user -> setPlainPassword('editedTest');
86
//
87
//        $this->assertInstanceOf(User::class, $user);
88
//    }
89
}
90