Completed
Push — master ( cc9b98...5f169a )
by Louis
14s
created

DepartmentUpdateCommandTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 8
dl 0
loc 50
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A testUpdateDepartment() 0 19 1
A tearDown() 0 7 1
1
<?php
2
3
namespace Tests\KI\UserBundle\Command;
4
5
use KI\UserBundle\Entity\User;
6
use KI\UserBundle\Command\DepartmentUpdateCommand;
7
use Symfony\Bundle\FrameworkBundle\Console\Application;
8
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
9
use Symfony\Component\Console\Tester\CommandTester;
10
11
// This test is not unitary, it has a side effect : it sets Matthias Dreveton's department to 'IMI'
12
13
class DepartmentUpdateCommandTest extends KernelTestCase
14
{
15
     /**
16
     * @var \Doctrine\ORM\EntityManager
17
     */
18
    private $em;
19
20
     /**
21
      * {@inheritDoc}
22
      */
23
    protected function setUp()
24
    {
25
        self::bootKernel();
26
27
        $this->em = static::$kernel->getContainer()
28
            ->get('doctrine')
29
            ->getManager();
30
    }
31
32
    public function testUpdateDepartment()
33
    {
34
        $dreveton = $this->em->getRepository(User::class)->findOneByUsername('matthias.dreveton');
35
36
        $application = new Application(static::$kernel);
37
        $application->add(new DepartmentUpdateCommand());
38
        $command = $application->find('upont:update:department');
39
        $commandTester = new CommandTester($command);
40
        $commandTester->execute(array(
41
            'command'  => $command->getName(),
42
            'department' => 'IMI',
43
            'usernames' => 'archlinux,trezzinl,matthias.dreveton,dsfqsdfefdfq'
44
        ));
45
46
        $output = $commandTester->getDisplay();
47
        $this->assertContains('IMI : 3 élèves sur 4 mis à jour', $output);
48
        $this->assertContains('Username dsfqsdfefdfq n\'existe pas', $output);
49
        $this->assertEquals('IMI', $dreveton->getDepartment());
50
    }
51
52
     /**
53
      * {@inheritDoc}
54
      */
55
    protected function tearDown()
56
    {
57
        parent::tearDown();
58
59
        $this->em->close();
60
        $this->em = null; // avoid memory leaks
61
    }
62
}
63