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'); |
|
|
|
|
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'); |
|
|
|
|
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() |
|
|
|
|
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
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.