Commit 1f5a8dcd authored by okhin's avatar okhin 🚴

Adding a user create command

parent 54e2dad3
<?php
namespace LQDN\Command;
class UserCreateCommand
{
private $email;
private $hash;
private $pseudo;
public function __construct($email, $hash, $pseudo, $cumul, $total)
{
$this->hash = $hash;
$this->email = $email;
$this->pseudo = $pseudo;
$this->total = $total;
$this->cumul = $cumul;
}
public function getHash()
{
return $this->hash;
}
public function getEmail()
{
return $this->email;
}
public function getPseudo()
{
return $this->pseudo;
}
public function getTotal()
{
return $this->total;
}
public function getCumul()
{
return $this->cumul;
}
}
...@@ -6,6 +6,7 @@ use Doctrine\DBAL\Connection; ...@@ -6,6 +6,7 @@ use Doctrine\DBAL\Connection;
use LQDN\Command\UserUpdateByAdminCommand; use LQDN\Command\UserUpdateByAdminCommand;
use LQDN\Command\UserUpdateTotalCommand; use LQDN\Command\UserUpdateTotalCommand;
use LQDN\Command\UserUpdateCumulCommand; use LQDN\Command\UserUpdateCumulCommand;
use LQDN\Command\UserCreateCommand;
class UserHandler class UserHandler
{ {
...@@ -31,6 +32,22 @@ class UserHandler ...@@ -31,6 +32,22 @@ class UserHandler
]); ]);
} }
/**
* Create a user in database
*
* @param UserCreateCommand $command
*/
public function handleUserCreateCommand(UserCreateCommand $command)
{
$stmt = $this->connection->prepare('INSERT INTO users(email, hash, pseudo, total, cumul) VALUES (:email, :hash, :pseudo, :total, :cumul)');
$stmt->bindValue('email', $command->getEmail());
$stmt->bindValue('hash', $command->getHash());
$stmt->bindValue('pseudo', $command->getPseudo());
$stmt->bindValue('total', $command->getTotal());
$stmt->bindValue('cumul', $command->getCumul());
$stmt->execute();
}
/** /**
* Update the user total * Update the user total
* *
......
...@@ -5,6 +5,7 @@ namespace LQDN\Tests\Functional\Handler; ...@@ -5,6 +5,7 @@ namespace LQDN\Tests\Functional\Handler;
use LQDN\Command\UserUpdateByAdminCommand; use LQDN\Command\UserUpdateByAdminCommand;
use LQDN\Command\UserUpdateTotalCommand; use LQDN\Command\UserUpdateTotalCommand;
use LQDN\Command\UserUpdateCumulCommand; use LQDN\Command\UserUpdateCumulCommand;
use LQDN\Command\UserCreateCommand;
use LQDN\Tests\Functional\FunctionalTest; use LQDN\Tests\Functional\FunctionalTest;
class UserHandlerTest extends FunctionalTest class UserHandlerTest extends FunctionalTest
...@@ -24,6 +25,11 @@ class UserHandlerTest extends FunctionalTest ...@@ -24,6 +25,11 @@ class UserHandlerTest extends FunctionalTest
$this->assertSame('This is foobar avé dé accênts !', $user['commentaire']); $this->assertSame('This is foobar avé dé accênts !', $user['commentaire']);
} }
public function testUserCreateCommand()
{
$this->container['command_handler']->handle(new UserCreateCommand('eve@example.org', 'not a hash', 'Eve', 0, 0));
}
public function testUserUpdateTotal() public function testUserUpdateTotal()
{ {
$this->container['command_handler']->handle(new UserUpdateTotalCommand(1, 600)); $this->container['command_handler']->handle(new UserUpdateTotalCommand(1, 600));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment