UserHandlerTest.php 1.97 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 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
use LQDN\Tests\Functional\FunctionalTest;

class UserHandlerTest extends FunctionalTest
{
    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
28 29 30
    public function testUserCreateCommand()
    {
        $this->container['command_handler']->handle(new UserCreateCommand('eve@example.org', 'not a hash', 'Eve', 0, 0));
31 32 33 34
        $last_id = $this->container['db']->lastInsertId();
        $user = $this->getUser($last_id);

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

Okhin's avatar
Okhin committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
    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']);
    }

53 54 55 56 57 58 59 60 61 62 63 64
    /**
     * Retrieve a given user.
     *
     * @param int $id
     *
     * @return []
     */
    private function getUser($id)
    {
        return $this->container['db']->fetchAssoc("SELECT * FROM users WHERE id = $id");
    }
}