Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LQDN Adminsys
don
Commits
1f5a8dcd
Commit
1f5a8dcd
authored
Nov 15, 2018
by
Okhin
Browse files
Adding a user create command
parent
54e2dad3
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/LQDN/Command/UserCreateCommand.php
0 → 100644
View file @
1f5a8dcd
<?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
;
}
}
src/LQDN/Handler/UserHandler.php
View file @
1f5a8dcd
...
...
@@ -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
*
...
...
tests/functional/Handler/UserHandlerTest.php
View file @
1f5a8dcd
...
...
@@ -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
));
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment