UserHandlerTest.php 2.3 KB
Newer Older
1
2
3
4
5
<?php

namespace LQDN\Tests\Functional\Handler;

use LQDN\Command\UserUpdateByAdminCommand;
Okhin's avatar
Okhin committed
6
7
use LQDN\Command\UserUpdateTotalCommand;
use LQDN\Command\UserUpdateCumulCommand;
Okhin's avatar
Okhin committed
8
use LQDN\Command\UserCreateCommand;
9
use LQDN\Command\AdminUpdateTotalUsersCommand;
10
11
12
13
use LQDN\Tests\Functional\FunctionalTest;

class UserHandlerTest extends FunctionalTest
{
14
15
16
17
    public function testAdminUpdateTotalUsersCommand()
    {
        $this->container['command_handler']->handle(new AdminUpdateTotalUsersCommand());
        $this->assertSame(1000, (int) $this->getUser(1)['total']);
18
        $this->assertSame(900, (int) $this->getUser(1)['cumul']);
19
20
    }

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    public function testUserUpdateFromAdmin()
    {
        $user = $this->getUser(1);
        $this->assertSame('Alice', $user['pseudo']);
        $this->assertSame('alice@example.org', $user['email']);
        $this->assertSame('RAS', $user['commentaire']);

        $this->container['command_handler']->handle(new UserUpdateByAdminCommand(1, 'Foobar', 'foobar@example.org', 'This is foobar avé dé accênts !'));

        $user = $this->getUser(1);
        $this->assertSame('Foobar', $user['pseudo']);
        $this->assertSame('foobar@example.org', $user['email']);
        $this->assertSame('This is foobar avé dé accênts !', $user['commentaire']);
    }

Okhin's avatar
Okhin committed
36
37
38
    public function testUserCreateCommand()
    {
        $this->container['command_handler']->handle(new UserCreateCommand('eve@example.org', 'not a hash', 'Eve', 0, 0));
39
40
41
42
        $last_id = $this->container['db']->lastInsertId();
        $user = $this->getUser($last_id);

        $this->assertSame('eve@example.org', $user['email']);
Okhin's avatar
Okhin committed
43
44
    }

Okhin's avatar
Okhin committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
    public function testUserUpdateTotal()
    {
        $this->container['command_handler']->handle(new UserUpdateTotalCommand(1, 600));
        $user = $this->getUser(1);

        $this->assertSame(600, (int) $user['total']);
    }

    public function testUserUpdateCumul()
    {
        $this->container['command_handler']->handle(new UserUpdateCumulCommand(1, 600));
        $user = $this->getUser(1);

        $this->assertSame(600, (int) $user['cumul']);
    }

61
62
63
64
65
66
67
68
69
70
71
72
    /**
     * Retrieve a given user.
     *
     * @param int $id
     *
     * @return []
     */
    private function getUser($id)
    {
        return $this->container['db']->fetchAssoc("SELECT * FROM users WHERE id = $id");
    }
}