diff --git a/src/LQDN/Command/UserCreateCommand.php b/src/LQDN/Command/UserCreateCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..b7af39467b53b3ad87b0e579a4c22f27d814af4c --- /dev/null +++ b/src/LQDN/Command/UserCreateCommand.php @@ -0,0 +1,44 @@ +<?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; + } +} diff --git a/src/LQDN/Handler/UserHandler.php b/src/LQDN/Handler/UserHandler.php index 4e886eff59d799c456f09898033ea915e5d7643b..e88b958b19bdb564eb2ae6f8f1a09ba0f1203851 100644 --- a/src/LQDN/Handler/UserHandler.php +++ b/src/LQDN/Handler/UserHandler.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Connection; use LQDN\Command\UserUpdateByAdminCommand; use LQDN\Command\UserUpdateTotalCommand; use LQDN\Command\UserUpdateCumulCommand; +use LQDN\Command\UserCreateCommand; 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 * diff --git a/tests/functional/Handler/UserHandlerTest.php b/tests/functional/Handler/UserHandlerTest.php index a083917fb9f2d6376d01aaa65b5cbac7ee05a24c..5162d26af5eb1b8ce3f649875ebb7240cf61499d 100644 --- a/tests/functional/Handler/UserHandlerTest.php +++ b/tests/functional/Handler/UserHandlerTest.php @@ -5,6 +5,7 @@ namespace LQDN\Tests\Functional\Handler; use LQDN\Command\UserUpdateByAdminCommand; use LQDN\Command\UserUpdateTotalCommand; use LQDN\Command\UserUpdateCumulCommand; +use LQDN\Command\UserCreateCommand; use LQDN\Tests\Functional\FunctionalTest; class UserHandlerTest extends FunctionalTest @@ -24,6 +25,11 @@ class UserHandlerTest extends FunctionalTest $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() { $this->container['command_handler']->handle(new UserUpdateTotalCommand(1, 600));