From 39a56d17ff72dac13fa0d1c320e893902eae873a Mon Sep 17 00:00:00 2001 From: Okhin Date: Sat, 13 Oct 2018 14:57:40 +0200 Subject: [PATCH] Improving tests to recover donations by user --- db/seeds/DonationSeeder.php | 54 ++++++++++++++++++- src/LQDN/CommandHandler.php | 6 +-- .../Handler/DonationHandlerTest.php | 17 ++++++ 3 files changed, 71 insertions(+), 6 deletions(-) diff --git a/db/seeds/DonationSeeder.php b/db/seeds/DonationSeeder.php index c60ba64..8e2969f 100644 --- a/db/seeds/DonationSeeder.php +++ b/db/seeds/DonationSeeder.php @@ -39,7 +39,59 @@ class DonationSeeder extends AbstractSeed 'cumul' => 1000, 'adresse_id' => 1, 'user_id' => 1, - 'identifier' => 'id1', + 'identifier' => 'id1', + ), + array( + 'id' => 2, + 'status' => 1, + 'datec' => '2016-06-10 12:34', + 'somme' => 1000, + 'lang' => 'fr_FR', + 'cadeau' => 1, + 'abo' => 1, + 'taille' => 8, + 'public' => 0, + 'pdf' => 'pdf', + 'decimale' => 2, + 'datee' => '2016-06-10 12:34', + 'mailsent' => 1, + 'color' => 'blue', + 'pi_x' => 3, + 'pi_y' => 3, + 'hash' => 'hash', + 'taille_h' => 8, + 'fdnn_user' => 1234567890, + 'color_2' => 'red', + 'cumul' => 1000, + 'adresse_id' => 1, + 'user_id' => 2, + 'identifier' => 'id2', + ), + array( + 'id' => 3, + 'status' => 1, + 'datec' => '2016-06-10 12:34', + 'somme' => 1000, + 'lang' => 'fr_FR', + 'cadeau' => 1, + 'abo' => 1, + 'taille' => 8, + 'public' => 0, + 'pdf' => 'pdf', + 'decimale' => 2, + 'datee' => '2016-06-10 12:34', + 'mailsent' => 1, + 'color' => 'blue', + 'pi_x' => 3, + 'pi_y' => 3, + 'hash' => 'hash', + 'taille_h' => 8, + 'fdnn_user' => 1234567890, + 'color_2' => 'red', + 'cumul' => 1000, + 'adresse_id' => 1, + 'user_id' => 2, + 'identifier' => 'id3', ) ); diff --git a/src/LQDN/CommandHandler.php b/src/LQDN/CommandHandler.php index 52eabda..11f5184 100644 --- a/src/LQDN/CommandHandler.php +++ b/src/LQDN/CommandHandler.php @@ -19,11 +19,7 @@ class CommandHandler */ public function handle($command) { - try { - $method = $this->getHandleMethod($command); - } catch (Exception $e) { - throw new CommandNotHandledException(); - } + $method = $this->getHandleMethod($command); foreach ($this->handlers as $handler) { if (method_exists($handler, $method)) { diff --git a/tests/functional/Handler/DonationHandlerTest.php b/tests/functional/Handler/DonationHandlerTest.php index be52872..e54a486 100644 --- a/tests/functional/Handler/DonationHandlerTest.php +++ b/tests/functional/Handler/DonationHandlerTest.php @@ -25,6 +25,13 @@ class DonationHandlerTest extends FunctionalTest $this->assertEquals('', $this->getDonation(1)['pdf']); } + + private function testDonationByUser() + { + $this->assertEquals(2, count($this->getDonationByUser(2))); + $this->assertEquals(2, $this->getDonationByUser(2)[0]['user_id']); + } + /** * Retrieve a donation * @@ -34,4 +41,14 @@ class DonationHandlerTest extends FunctionalTest { return $this->container['db']->fetchAssoc("SELECT * FROM dons WHERE id = $id"); } + + /** + * Retrieve donations by userid + * + * @return [] + */ + private function getDonationByUser($uid) + { + return $this->container['db']->fetchAll("SELECT * FROM dons WHERE user_id = $uid"); + } } -- GitLab