diff --git a/src/LQDN/Command/DonationCreateCommand.php b/src/LQDN/Command/DonationCreateCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..8e713c77d56ce603d58eae0a316160c1627d17e0 --- /dev/null +++ b/src/LQDN/Command/DonationCreateCommand.php @@ -0,0 +1,53 @@ +<?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; + } +} diff --git a/src/LQDN/Handler/DonationHandler.php b/src/LQDN/Handler/DonationHandler.php index 94dad2e9972cf7e68ae46bbea63132fa712a839f..34b17e8e2d725c82622df4045487b0b7feea8843 100644 --- a/src/LQDN/Handler/DonationHandler.php +++ b/src/LQDN/Handler/DonationHandler.php @@ -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. * diff --git a/tests/functional/Handler/CounterpartHandlerTest.php b/tests/functional/Handler/CounterpartHandlerTest.php index 6df472fbd54c01d651fca8493c2f1f571f8254fd..ecce1a68266e9bba61bcb9f6719752f8a9d25324 100644 --- a/tests/functional/Handler/CounterpartHandlerTest.php +++ b/tests/functional/Handler/CounterpartHandlerTest.php @@ -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() diff --git a/tests/functional/Handler/DonationHandlerTest.php b/tests/functional/Handler/DonationHandlerTest.php index e54a4867683a093981a72471e6f6da259ab04392..dec818a9d3ff73107e850673408901a0d0d3712e 100644 --- a/tests/functional/Handler/DonationHandlerTest.php +++ b/tests/functional/Handler/DonationHandlerTest.php @@ -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 * diff --git a/tests/functional/Handler/UserHandlerTest.php b/tests/functional/Handler/UserHandlerTest.php index 3e0f652ffea00b1470016cd19eca9cb0e80a1466..a083917fb9f2d6376d01aaa65b5cbac7ee05a24c 100644 --- a/tests/functional/Handler/UserHandlerTest.php +++ b/tests/functional/Handler/UserHandlerTest.php @@ -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. *