UserHandlerTest.php 2.54 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
        $this->assertSame(1000, (int) $this->getUser(2)['total']);
        $this->assertSame(750, (int) $this->getUser(2)['cumul']);
21 22
    }

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

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

        $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']);
36 37
        $this->assertSame(2000, (int) $user['total']);
        $this->assertSame(1000, (int) $user['cumul']);
38 39
    }

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

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

Okhin's avatar
Okhin committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
    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']);
    }

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