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
|
|
|
|