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
cf41e30a
Commit
cf41e30a
authored
Nov 15, 2018
by
Okhin
Browse files
Add a DonationCreate command
parent
84a543f6
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/LQDN/Command/DonationCreateCommand.php
0 → 100644
View file @
cf41e30a
<?php
namespace
LQDN\Command
;
class
DonationCreateCommand
{
private
$status
;
private
$datec
;
private
$somme
;
private
$userId
;
private
$public
;
private
$cumul
;
public
function
__construct
(
$userId
,
$status
,
$datec
,
$somme
,
$public
,
$cumul
)
{
$this
->
status
=
$status
;
$this
->
userId
=
$userId
;
$this
->
datec
=
$datec
;
$this
->
somme
=
$somme
;
$this
->
public
=
$public
;
$this
->
cumul
=
$cumul
;
}
public
function
getUserId
()
{
return
$this
->
userId
;
}
public
function
getStatus
()
{
return
$this
->
status
;
}
public
function
getDateC
()
{
return
$this
->
datec
;
}
public
function
getSomme
()
{
return
$this
->
somme
;
}
public
function
getPublic
()
{
return
$this
->
public
;
}
public
function
getCumul
()
{
return
$this
->
cumul
;
}
}
src/LQDN/Handler/DonationHandler.php
View file @
cf41e30a
...
...
@@ -3,6 +3,7 @@
namespace
LQDN\Handler
;
use
Doctrine\DBAL\Connection
;
use
LQDN\Command\DonationCreateCommand
;
use
LQDN\Command\DonationInvalidateCommand
;
use
LQDN\Command\DonationResetPdfCommand
;
use
LQDN\Command\DonationValidateCommand
;
...
...
@@ -16,6 +17,27 @@ class DonationHandler
$this
->
connection
=
$connection
;
}
/**
* Create a donation
*
* @param DonationCreateCommand $command
*/
public
function
handleDonationCreateCommand
(
DonationCreateCommand
$command
)
{
$query
=
<<<EOF
INSERT INTO dons(status, datec, somme, user_id, public, cumul)
VALUES(:status, :datec, :somme, :user_id, :public, :cumul)
EOF;
$stmt
=
$this
->
connection
->
prepare
(
$query
);
$stmt
->
bindvalue
(
'status'
,
$command
->
getStatus
());
$stmt
->
bindvalue
(
'datec'
,
$command
->
getDateC
());
$stmt
->
bindvalue
(
'somme'
,
$command
->
getSomme
());
$stmt
->
bindvalue
(
'user_id'
,
$command
->
getUserId
());
$stmt
->
bindvalue
(
'public'
,
$command
->
getPublic
());
$stmt
->
bindvalue
(
'cumul'
,
$command
->
getCumul
());
$stmt
->
execute
();
}
/**
* Validate a donation.
*
...
...
tests/functional/Handler/CounterpartHandlerTest.php
View file @
cf41e30a
...
...
@@ -21,7 +21,7 @@ class CounterpartHandlerTest extends FunctionalTest
{
$this
->
assertFalse
(
$this
->
counterpartExists
(
3
));
$this
->
container
[
'command_handler'
]
->
handle
(
new
CounterpartCreateCommand
(
1
,
1
,
'pishirt'
,
4
,
1
,
date
(
"Y-m-d H:i:s"
)));
$this
->
container
[
'command_handler'
]
->
handle
(
new
CounterpartCreateCommand
(
1
,
1
,
'pishirt'
,
4
,
1
,
date
(
"Y-m-d H:i:s"
)
,
''
));
}
public
function
testCounterpartChangeState
()
...
...
tests/functional/Handler/DonationHandlerTest.php
View file @
cf41e30a
...
...
@@ -5,6 +5,7 @@ namespace LQDN\Tests\Functional\Handler;
use
LQDN\Command\DonationInvalidateCommand
;
use
LQDN\Command\DonationResetPdfCommand
;
use
LQDN\Command\DonationValidateCommand
;
use
LQDN\Command\DonationCreateCommand
;
use
LQDN\Tests\Functional\FunctionalTest
;
class
DonationHandlerTest
extends
FunctionalTest
...
...
@@ -32,6 +33,13 @@ class DonationHandlerTest extends FunctionalTest
$this
->
assertEquals
(
2
,
$this
->
getDonationByUser
(
2
)[
0
][
'user_id'
]);
}
public
function
testDonationCreateCommand
()
{
$this
->
container
[
'command_handler'
]
->
handle
(
new
DonationCreateCommand
(
1
,
1
,
date
(
"Y-m-d H:M:s"
),
50
,
0
,
0
));
}
/**
* Retrieve a donation
*
...
...
tests/functional/Handler/UserHandlerTest.php
View file @
cf41e30a
...
...
@@ -3,6 +3,8 @@
namespace
LQDN\Tests\Functional\Handler
;
use
LQDN\Command\UserUpdateByAdminCommand
;
use
LQDN\Command\UserUpdateTotalCommand
;
use
LQDN\Command\UserUpdateCumulCommand
;
use
LQDN\Tests\Functional\FunctionalTest
;
class
UserHandlerTest
extends
FunctionalTest
...
...
@@ -22,6 +24,22 @@ class UserHandlerTest extends FunctionalTest
$this
->
assertSame
(
'This is foobar avé dé accênts !'
,
$user
[
'commentaire'
]);
}
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'
]);
}
/**
* Retrieve a given user.
*
...
...
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