Commit cf41e30a authored by okhin's avatar okhin 🚴

Add a DonationCreate command

parent 84a543f6
<?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;
}
}
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace LQDN\Handler; namespace LQDN\Handler;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use LQDN\Command\DonationCreateCommand;
use LQDN\Command\DonationInvalidateCommand; use LQDN\Command\DonationInvalidateCommand;
use LQDN\Command\DonationResetPdfCommand; use LQDN\Command\DonationResetPdfCommand;
use LQDN\Command\DonationValidateCommand; use LQDN\Command\DonationValidateCommand;
...@@ -16,6 +17,27 @@ class DonationHandler ...@@ -16,6 +17,27 @@ class DonationHandler
$this->connection = $connection; $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. * Validate a donation.
* *
......
...@@ -21,7 +21,7 @@ class CounterpartHandlerTest extends FunctionalTest ...@@ -21,7 +21,7 @@ class CounterpartHandlerTest extends FunctionalTest
{ {
$this->assertFalse($this->counterpartExists(3)); $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() public function testCounterpartChangeState()
......
...@@ -5,6 +5,7 @@ namespace LQDN\Tests\Functional\Handler; ...@@ -5,6 +5,7 @@ namespace LQDN\Tests\Functional\Handler;
use LQDN\Command\DonationInvalidateCommand; use LQDN\Command\DonationInvalidateCommand;
use LQDN\Command\DonationResetPdfCommand; use LQDN\Command\DonationResetPdfCommand;
use LQDN\Command\DonationValidateCommand; use LQDN\Command\DonationValidateCommand;
use LQDN\Command\DonationCreateCommand;
use LQDN\Tests\Functional\FunctionalTest; use LQDN\Tests\Functional\FunctionalTest;
class DonationHandlerTest extends FunctionalTest class DonationHandlerTest extends FunctionalTest
...@@ -32,6 +33,13 @@ class DonationHandlerTest extends FunctionalTest ...@@ -32,6 +33,13 @@ class DonationHandlerTest extends FunctionalTest
$this->assertEquals(2, $this->getDonationByUser(2)[0]['user_id']); $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 * Retrieve a donation
* *
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
namespace LQDN\Tests\Functional\Handler; namespace LQDN\Tests\Functional\Handler;
use LQDN\Command\UserUpdateByAdminCommand; use LQDN\Command\UserUpdateByAdminCommand;
use LQDN\Command\UserUpdateTotalCommand;
use LQDN\Command\UserUpdateCumulCommand;
use LQDN\Tests\Functional\FunctionalTest; use LQDN\Tests\Functional\FunctionalTest;
class UserHandlerTest extends FunctionalTest class UserHandlerTest extends FunctionalTest
...@@ -22,6 +24,22 @@ class UserHandlerTest extends FunctionalTest ...@@ -22,6 +24,22 @@ 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 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. * Retrieve a given user.
* *
......
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