Ajout test unitaire non fonctionnel ( Class Connection not found )
continuous-integration/drone/push Build is failing Details

issue_023_User_Gateway
Kevin MONTEIRO 1 year ago
parent c09ce09b26
commit 64c04a97f6

@ -0,0 +1 @@
{"version":1,"defects":{"MaClasseTest::testMethode":5,"ExampleTest::testMethode":5,"toto::testMethode":5,"AthleteGateway::testGateway":5,"Database\\Tests\\AthleteGatewayTest::testGetAthlete":4,"Database\\Tests\\AthleteGatewayTest::testGetAthleteById":4,"Database\\Tests\\AthleteGatewayTest::testAddAthlete":4,"Database\\Tests\\AthleteGatewayTest::testUpdateAthlete":4,"Database\\Tests\\AthleteGatewayTest::testDeleteAthlete":4,"Database\\AthleteGatewayTest::testGetAthlete":4,"Database\\AthleteGatewayTest::testGetAthleteById":4,"Database\\AthleteGatewayTest::testAddAthlete":4,"Database\\AthleteGatewayTest::testUpdateAthlete":4,"Database\\AthleteGatewayTest::testDeleteAthlete":4,"AthleteGatewayTest::testAddAndGetAthlete":4},"times":{"MaClasseTest::testMethode":0.001,"ExampleTest::testMethode":0.001,"toto::testMethode":0.001,"AthleteGateway::testGateway":0.048,"Database\\Tests\\AthleteGatewayTest::testGetAthlete":0.001,"Database\\Tests\\AthleteGatewayTest::testGetAthleteById":0.001,"Database\\Tests\\AthleteGatewayTest::testAddAthlete":0.072,"Database\\Tests\\AthleteGatewayTest::testUpdateAthlete":0.001,"Database\\Tests\\AthleteGatewayTest::testDeleteAthlete":0.001,"Database\\AthleteGatewayTest::testGetAthlete":0.002,"Database\\AthleteGatewayTest::testGetAthleteById":0,"Database\\AthleteGatewayTest::testAddAthlete":0,"Database\\AthleteGatewayTest::testUpdateAthlete":0,"Database\\AthleteGatewayTest::testDeleteAthlete":0,"AthleteGatewayTest::testAddAndGetAthlete":0.002}}

@ -9,6 +9,7 @@
"Repository\\": "src/data/model/repository", "Repository\\": "src/data/model/repository",
"Manager\\": "src/data/model/manager", "Manager\\": "src/data/model/manager",
"Network\\": "src/data/core/network", "Network\\": "src/data/core/network",
"Database\\": "src/data/core/database",
"Console\\": "src/console", "Console\\": "src/console",
"Stub\\": [ "Stub\\": [
"src/data/stub", "src/data/stub",
@ -24,10 +25,11 @@
"vlucas/phpdotenv": "^5.5" "vlucas/phpdotenv": "^5.5"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "*" "phpunit/phpunit": "^9.6"
}, },
"scripts": { "scripts": {
"dev": "php -S localhost:8080 -t public -d display_errors=1 -d error_reporting=E_ALL", "dev": "php -S localhost:8080 -t public -d display_errors=1 -d error_reporting=E_ALL",
"dev:console": "export APP_ENV=console && php public/index.php" "dev:console": "export APP_ENV=console && php public/index.php",
"test" : "./vendor/bin/phpunit tests"
} }
} }

@ -1,7 +1,9 @@
<?php <?php
class ActivityEntity { namespace Database;
private $idActivity;
class ActiviteEntity {
private $idActivite;
private $type; private $type;
private $date; private $date;
private $heureDebut; private $heureDebut;
@ -16,7 +18,7 @@ class ActivityEntity {
private $temperatureMoyenne; private $temperatureMoyenne;
// Getters // Getters
public function getIdActivity() { public function getIdActivite() {
return $this->idActivity; return $this->idActivity;
} }
@ -69,7 +71,7 @@ class ActivityEntity {
} }
// Setters // Setters
public function setIdActivity($idActivity) { public function setIdActivite($idActivite) {
$this->idActivity = $idActivity; $this->idActivity = $idActivity;
} }

@ -1,37 +1,39 @@
<?php <?php
class ActivityGateway { namespace Database;
class ActiviteGateway {
private $connection; private $connection;
public function __construct(Connection $connection) { public function __construct(Connection $connection) {
$this->connection = $connection; $this->connection = $connection;
} }
public function getActivity() { public function getActivite() {
$query = "SELECT * FROM Activity"; $query = "SELECT * FROM Activite";
return $this->connection->executeWithErrorHandling($query); return $this->connection->executeWithErrorHandling($query);
} }
public function getActivityById($activityId) { public function getActiviteById(int $activiteId) {
$query = "SELECT * FROM Activity WHERE idActivity = :id"; $query = "SELECT * FROM Activite WHERE idActivite = :id";
$params = [':id' => [$activityId, PDO::PARAM_INT]]; $params = [':id' => [$activiteId, PDO::PARAM_INT]];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function getActivityByType($type) { public function getActiviteByType(string $type) {
$query = "SELECT * FROM Activity WHERE type = :type"; $query = "SELECT * FROM Activite WHERE type = :type";
$params = [':type' => [$type, PDO::PARAM_STR]]; $params = [':type' => [$type, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function getActivityByDate($date) { public function getActiviteByDate(string $date) {
$query = "SELECT * FROM Activity WHERE date = :date"; $query = "SELECT * FROM Activite WHERE date = :date";
$params = [':date' => [$date, PDO::PARAM_STR]]; $params = [':date' => [$date, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function getActivityByTimeRange($startTime, $endTime) { public function getActiviteByTimeRange(string $startTime, string $endTime) {
$query = "SELECT * FROM Activity WHERE heureDebut >= :startTime AND heureFin <= :endTime"; $query = "SELECT * FROM Activite WHERE heureDebut >= :startTime AND heureFin <= :endTime";
$params = [ $params = [
':startTime' => [$startTime, PDO::PARAM_STR], ':startTime' => [$startTime, PDO::PARAM_STR],
':endTime' => [$endTime, PDO::PARAM_STR] ':endTime' => [$endTime, PDO::PARAM_STR]
@ -39,23 +41,80 @@ class ActivityGateway {
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function getActivityByEffort($effortRessenti) { public function getActiviteByEffort(int $effortRessenti) {
$query = "SELECT * FROM Activity WHERE effortRessenti = :effort"; $query = "SELECT * FROM Activite WHERE effortRessenti = :effort";
$params = [':effort' => [$effortRessenti, PDO::PARAM_INT]]; $params = [':effort' => [$effortRessenti, PDO::PARAM_INT]];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function getActivityByVariability($variabilite) { public function getActiviteByVariability(int $variabilite) {
$query = "SELECT * FROM Activity WHERE variabilite = :variability"; $query = "SELECT * FROM Activite WHERE variabilite = :variability";
$params = [':variability' => [$variabilite, PDO::PARAM_INT]]; $params = [':variability' => [$variabilite, PDO::PARAM_INT]];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function getActivityByTemperature($temperatureMoyenne) { public function getActiviteByTemperature(int $temperatureMoyenne) {
$query = "SELECT * FROM Activity WHERE temperatureMoyenne = :temperature"; $query = "SELECT * FROM Activite WHERE temperatureMoyenne = :temperature";
$params = [':temperature' => [$temperatureMoyenne, PDO::PARAM_INT]]; $params = [':temperature' => [$temperatureMoyenne, PDO::PARAM_INT]];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function addActivite(ActiviteEntity $activite) {
$query = "INSERT INTO Activite (type, date, heureDebut, heureDeFin, effortRessenti, variabilite, variance, ecartType, moyenne, maximum, minimum, temperatureMoyenne)
VALUES (:type, :date, :heureDebut, :heureDeFin, :effortRessenti, :variabilite, :variance, :ecartType, :moyenne, :maximum, :minimum, :temperatureMoyenne)";
$params = [
':type' => $activite->getType(),
':date' => $activite->getDate()->format('Y-m-d'), // Format date pour SQL
':heureDebut' => $activite->getHeureDebut()->format('H:i:s'), // Format heure pour SQL
':heureDeFin' => $activite->getHeureFin()->format('H:i:s'), // Format heure pour SQL
':effortRessenti' => $activite->getEffortRessenti(),
':variabilite' => $activite->getVariabilite(),
':variance' => $activite->getVariance(),
':ecartType' => $activite->getEcartType(),
':moyenne' => $activite->getMoyenne(),
':maximum' => $activite->getMaximum(),
':minimum' => $activite->getMinimum(),
':temperatureMoyenne' => $activite->getTemperatureMoyenne(),
];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function updateActivite(ActiviteEntity $oldActivite, ActiviteEntity $newActivite) {
$query = "UPDATE Activite
SET type = :type, date = :date, heureDebut = :heureDebut, heureDeFin = :heureDeFin,
effortRessenti = :effortRessenti, variabilite = :variabilite, variance = :variance, ecartType = :ecartType, moyenne = :moyenne, maximum = :maximum, minimum = :minimum, temperatureMoyenne = :temperatureMoyenne
WHERE idActivite = :idActivite";
$params = [
':idActivite' => $oldActivite->getIdActivite(),
':type' => $newActivite->getType(),
':date' => $newActivite->getDate()->format('Y-m-d'), // Format date pour SQL
':heureDebut' => $newActivite->getHeureDebut()->format('H:i:s'), // Format heure pour SQL
':heureDeFin' => $newActivite->getHeureFin()->format('H:i:s'), // Format heure pour SQL
':effortRessenti' => $newActivite->getEffortRessenti(),
':variabilite' => $newActivite->getVariabilite(),
':variance' => $newActivite->getVariance(),
':ecartType' => $newActivite->getEcartType(),
':moyenne' => $newActivite->getMoyenne(),
':maximum' => $newActivite->getMaximum(),
':minimum' => $newActivite->getMinimum(),
':temperatureMoyenne' => $newActivite->getTemperatureMoyenne(),
];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function deleteActivite(int $idActivite) {
$query = "DELETE FROM Activite WHERE idActivite = :idActivite";
$params = [
':idActivite' => $idActivite,
];
return $this->connection->executeWithErrorHandling($query, $params);
}
} }
?> ?>

@ -1,7 +1,10 @@
<?php <?php
namespace Database;
use Model\Activite;
class ActiviteMapper { class ActiviteMapper {
public function map(array $data) { public function map(array $data):ActiviteEntity {
$activite = new ActiviteEntity(); $activite = new ActiviteEntity();
$activite->setIdActivite($data['idActivite']); $activite->setIdActivite($data['idActivite']);
$activite->setType($data['type']); $activite->setType($data['type']);
@ -19,6 +22,30 @@ class ActiviteMapper {
return $activite; return $activite;
} }
//public function ActiviteEntityToModel(ActiviteEntity entity): Activite;
public function ActiviteEntityToModel(ActiviteEntity $activiteEntity):Activite{
$act = new Activite(
$activiteEntity->getIdActivite(),
$activiteEntity->getType(),
$activiteEntity->getDate(),
$activiteEntity->getHeureDebut(),
$activiteEntity->getHeureFin(),
$activiteEntity->getEffortRessenti(),
$activiteEntity->getVariabilite(),
$activiteEntity->getVariance(),
$activiteEntity->getEcartType(),
$activiteEntity->getMoyenne(),
$activiteEntity->getMaximum(),
$activiteEntity->getMinimum(),
$activiteEntity->getTemperatureMoyenne()
);
return $act;
}
//public function ActiviteToEntity(Activite model): ActiviteEntity;
} }
?> ?>

@ -1,5 +1,7 @@
<?php <?php
namespace Database;
class AthleteEntity { class AthleteEntity {
private $idAthlete; private $idAthlete;
private $nom; private $nom;

@ -1,4 +1,7 @@
<?php <?php
namespace Database;
class AthleteGateway { class AthleteGateway {
private $connection; private $connection;
@ -11,60 +14,112 @@ class AthleteGateway {
return $this->connection->executeWithErrorHandling($query); return $this->connection->executeWithErrorHandling($query);
} }
public function getAthleteById($userId) { public function getAthleteById(int $userId) {
$query = "SELECT * FROM Athlete WHERE idAthlete = :id"; $query = "SELECT * FROM Athlete WHERE idAthlete = :id";
$params = [':id' => [$userId, PDO::PARAM_INT]]; $params = [':id' => [$userId, PDO::PARAM_INT]];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function getAthleteByName($name) { public function getAthleteByName(string $name) {
$query = "SELECT * FROM Athlete WHERE nom = :name"; $query = "SELECT * FROM Athlete WHERE nom = :name";
$params = [':name' => [$name, PDO::PARAM_STR]]; $params = [':name' => [$name, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function getAthleteByFirstName($firstName) { public function getAthleteByFirstName(string $firstName) {
$query = "SELECT * FROM Athlete WHERE prenom = :firstName"; $query = "SELECT * FROM Athlete WHERE prenom = :firstName";
$params = [':firstName' => [$firstName, PDO::PARAM_STR]]; $params = [':firstName' => [$firstName, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function getAthleteByEmail($email) { public function getAthleteByEmail(string $email) {
$query = "SELECT * FROM Athlete WHERE email = :email"; $query = "SELECT * FROM Athlete WHERE email = :email";
$params = [':email' => [$email, PDO::PARAM_STR]]; $params = [':email' => [$email, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function getAthleteByGender($gender) { public function getAthleteByGender(string $gender) {
$query = "SELECT * FROM Athlete WHERE sexe = :gender"; $query = "SELECT * FROM Athlete WHERE sexe = :gender";
$params = [':gender' => [$gender, PDO::PARAM_STR]]; $params = [':gender' => [$gender, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function getAthleteByHeight($height) { public function getAthleteByHeight(int $height) {
$query = "SELECT * FROM Athlete WHERE taille = :height"; $query = "SELECT * FROM Athlete WHERE taille = :height";
$params = [':height' => [$height, PDO::PARAM_INT]]; $params = [':height' => [$height, PDO::PARAM_INT]];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function getAthleteByWeight($weight) { public function getAthleteByWeight(int $weight) {
$query = "SELECT * FROM Athlete WHERE poids = :weight"; $query = "SELECT * FROM Athlete WHERE poids = :weight";
$params = [':weight' => [$weight, PDO::PARAM_INT]]; $params = [':weight' => [$weight, PDO::PARAM_INT]];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function getAthleteByBirthDate($birthdate) { public function getAthleteByBirthDate(string $birthdate) {
$query = "SELECT * FROM Athlete WHERE dateNaissance = :birthdate"; $query = "SELECT * FROM Athlete WHERE dateNaissance = :birthdate";
$params = [':birthdate' => [$birthdate, PDO::PARAM_STR]]; $params = [':birthdate' => [$birthdate, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function addAthlete(AthleteEntity $athlete) {
$query = "INSERT INTO Athlete (nom, prenom, email, sexe, taille, poids, motDePasse, dateNaissance)
VALUES (:nom, :prenom, :email, :sexe, :taille, :poids, :motDePasse, :dateNaissance)";
$params = [
':nom' => $athlete->getNom(),
':prenom' => $athlete->getPrenom(),
':email' => $athlete->getEmail(),
':sexe' => $athlete->getSexe(),
':taille' => $athlete->getTaille(),
':poids' => $athlete->getPoids(),
':motDePasse' => $athlete->getMotDePasse(),
':dateNaissance' => $athlete->getDateNaissance()->format('Y-m-d'), // Format date pour SQL
];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function updateAthlete(AthleteEntity $oldAthlete, AthleteEntity $newAthlete) {
$query = "UPDATE Athlete
SET nom = :nom, prenom = :prenom, email = :email, sexe = :sexe,
taille = :taille, poids = :poids, motDePasse = :motDePasse, dateNaissance = :dateNaissance
WHERE idAthlete = :idAthlete";
$params = [
':idAthlete' => $oldAthlete->getIdAthlete(),
':nom' => $newAthlete->getNom(),
':prenom' => $newAthlete->getPrenom(),
':email' => $newAthlete->getEmail(),
':sexe' => $newAthlete->getSexe(),
':taille' => $newAthlete->getTaille(),
':poids' => $newAthlete->getPoids(),
':motDePasse' => $newAthlete->getMotDePasse(),
':dateNaissance' => $newAthlete->getDateNaissance()->format('Y-m-d'), // Format date pour SQL
];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function deleteAthlete(int $idAthlete) {
$query = "DELETE FROM Athlete WHERE idAthlete = :idAthlete";
$params = [
':idAthlete' => $idAthlete,
];
return $this->connection->executeWithErrorHandling($query, $params);
}
} }
// Exemple d'utilisation // Exemple d'utilisation
//$dsn = "pgsql:host=localhost;port=5432;dbname=mydatabase;user=myuser;password=mypassword"; //$dsn = "pgsql:host=localhost;port=5432;dbname=mydatabase;user=myuser;password=mypassword";
//$connection = new Connection($dsn); //$connection = new Connection($dsn);
//$gateway = new UserGateway($connection); //$gateway = new AthleteGateway($connection);
//$allAth = $gateway->getAthlete(); //$allAth = $gateway->getAthlete();
//print_r($allAth); //print_r($allAth);

@ -1,7 +1,10 @@
<?php <?php
namespace Database;
use Model\User;
class AthleteMapper { class AthleteMapper {
public function map(array $data) { public function fromSqlToEntity(array $data):AthleteEntity {
$athlete = new AthleteEntity(); $athlete = new AthleteEntity();
$athlete->setIdAthlete($data['idAthlete']); $athlete->setIdAthlete($data['idAthlete']);
$athlete->setNom($data['nom']); $athlete->setNom($data['nom']);
@ -15,6 +18,42 @@ class AthleteMapper {
return $athlete; return $athlete;
} }
public function AthleteEntityToModel(AthleteEntity $athleteEntity):User{
$role = "Athlete";
$user = new User(
$athleteEntity->getIdAthlete(),
$athleteEntity->getNom(),
$athleteEntity->getPrenom(),
$athleteEntity->getEmail(),
$athleteEntity->getMotDePasse(),
$athleteEntity->getSexe(),
$athleteEntity->getTaille(),
$athleteEntity->getPoids(),
$athleteEntity->getDateNaissance(),
$role
);
return $user;
}
public function AthletetoEntity(User $user):AthleteEntity{
$ath = new AthleteEntity();
$ath->setIdAthlete($user->getId());
$ath->setNom($user->getNom());
$ath->setPrenom($user->getPrenom());
$ath->setEmail($user->getEmail());
$ath->setSexe($user->getSexe());
$ath->setTaille($user->getTaille());
$ath->setPoids($user->getPoids());
$ath->setMotDePasse($user->getMotDePasse());
$ath->setDateNaissance($user->getDateNaissance());
return $ath;
}
} }
?> ?>

@ -1,5 +1,7 @@
<?php <?php
namespace Database;
class CoachEntity { class CoachEntity {
private $idCoach; private $idCoach;
private $nom; private $nom;

@ -1,4 +1,7 @@
<?php <?php
namespace Database;
class CoachGateway { class CoachGateway {
private $connection; private $connection;
@ -11,45 +14,95 @@ class CoachGateway {
return $this->connection->executeWithErrorHandling($query); return $this->connection->executeWithErrorHandling($query);
} }
public function getCoachById($userId) { public function getCoachById(int $userId) {
$query = "SELECT * FROM Coach WHERE idCoach = :id"; $query = "SELECT * FROM Coach WHERE idCoach = :id";
$params = [':id' => [$userId, PDO::PARAM_INT]]; $params = [':id' => [$userId, PDO::PARAM_INT]];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function getCoachByName($name) { public function getCoachByName(string $name) {
$query = "SELECT * FROM Coach WHERE nom = :name"; $query = "SELECT * FROM Coach WHERE nom = :name";
$params = [':name' => [$name, PDO::PARAM_STR]]; $params = [':name' => [$name, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function getCoachByFirstName($firstName) { public function getCoachByFirstName(string $firstName) {
$query = "SELECT * FROM Coach WHERE prenom = :firstName"; $query = "SELECT * FROM Coach WHERE prenom = :firstName";
$params = [':firstName' => [$firstName, PDO::PARAM_STR]]; $params = [':firstName' => [$firstName, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function getCoachByEmail($email) { public function getCoachByEmail(string $email) {
$query = "SELECT * FROM Coach WHERE email = :email"; $query = "SELECT * FROM Coach WHERE email = :email";
$params = [':email' => [$email, PDO::PARAM_STR]]; $params = [':email' => [$email, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function getCoachByGender($gender) { public function getCoachByGender(string $gender) {
$query = "SELECT * FROM Coach WHERE sexe = :gender"; $query = "SELECT * FROM Coach WHERE sexe = :gender";
$params = [':gender' => [$gender, PDO::PARAM_STR]]; $params = [':gender' => [$gender, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function getCoachByHeight($height) { public function getCoachByHeight(int $height) {
$query = "SELECT * FROM Coach WHERE taille = :height"; $query = "SELECT * FROM Coach WHERE taille = :height";
$params = [':height' => [$height, PDO::PARAM_INT]]; $params = [':height' => [$height, PDO::PARAM_INT]];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function getAthleteByBirthDate($birthdate) { public function getCoachByBirthDate(string $birthdate) {
$query = "SELECT * FROM Coach WHERE dateNaissance = :birthdate"; $query = "SELECT * FROM Coach WHERE dateNaissance = :birthdate";
$params = [':birthdate' => [$birthdate, PDO::PARAM_STR]]; $params = [':birthdate' => [$birthdate, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function addCoach(CoachEntity $coach) {
$query = "INSERT INTO Coach (nom, prenom, email, sexe, taille, poids, motDePasse, dateNaissance)
VALUES (:nom, :prenom, :email, :sexe, :taille, :poids, :motDePasse, :dateNaissance)";
$params = [
':nom' => $coach->getNom(),
':prenom' => $coach->getPrenom(),
':email' => $coach->getEmail(),
':sexe' => $coach->getSexe(),
':taille' => $coach->getTaille(),
':poids' => $coach->getPoids(),
':motDePasse' => $coach->getMotDePasse(),
':dateNaissance' => $coach->getDateNaissance()->format('Y-m-d'), // Format date pour SQL
];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function updateCoach(CoachEntity $oldCoach, CoachEntity $newCoach) {
$query = "UPDATE Coach
SET nom = :nom, prenom = :prenom, email = :email, sexe = :sexe,
taille = :taille, poids = :poids, motDePasse = :motDePasse, dateNaissance = :dateNaissance
WHERE idCoach = :idCoach";
$params = [
':idCoach' => $oldCoach->getIdCoach(),
':nom' => $newCoach->getNom(),
':prenom' => $newCoach->getPrenom(),
':email' => $newCoach->getEmail(),
':sexe' => $newCoach->getSexe(),
':taille' => $newCoach->getTaille(),
':poids' => $newCoach->getPoids(),
':motDePasse' => $newCoach->getMotDePasse(),
':dateNaissance' => $newCoach->getDateNaissance()->format('Y-m-d'), // Format date pour SQL
];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function deleteCoach(int $idCoach) {
$query = "DELETE FROM Coach WHERE idCoach = :idCoach";
$params = [
':idCoach' => $idCoach,
];
return $this->connection->executeWithErrorHandling($query, $params);
}
} }

@ -1,5 +1,9 @@
<?php <?php
namespace Database;
use Model\User;
class CoachMapper { class CoachMapper {
public function map(array $data) { public function map(array $data) {
$coach = new CoachEntity(); $coach = new CoachEntity();
@ -15,6 +19,41 @@ class CoachMapper {
return $coach; return $coach;
} }
public function CoachEntityToModel(CoachEntity $coachEntity):User{
$role = "Coach";
$user = new User(
$coachEntity->getIdCoach(),
$coachEntity->getNom(),
$coachEntity->getPrenom(),
$coachEntity->getEmail(),
$coachEntity->getMotDePasse(),
$coachEntity->getSexe(),
$coachEntity->getTaille(),
$coachEntity->getPoids(),
$coachEntity->getDateNaissance(),
$role
);
return $user;
}
public function CoachToEntity(User $user):CoachEntity{
$coach = new CoachEntity();
$coach->setIdCoach($user->getId());
$coach->setNom($user->getNom());
$coach->setPrenom($user->getPrenom());
$coach->setEmail($user->getEmail());
$coach->setSexe($user->getSexe());
$coach->setTaille($user->getTaille());
$coach->setPoids($user->getPoids());
$coach->setMotDePasse($user->getMotDePasse());
$coach->setDateNaissance($user->getDateNaissance());
return $coach;
}
} }
?> ?>

@ -1,13 +0,0 @@
<?php
namespace DataManager;
class CoachManager
{
/**
*/
public function __construct()
{
}
}

@ -0,0 +1,55 @@
<?php
use PHPUnit\Framework\TestCase;
use Database\Connection;
class AthleteGatewayTest extends TestCase {
public function testAddAndGetAthlete() {
$dsn = "pgsql:host=londres;port=8888;dbname=dbkemonteiro2;user=kemonteiro2;password=Mdp";
$connection = new Connection($dsn);
$athleteGateway = new AthleteGateway($connection);
$athleteEntity = new AthleteEntity();
$athleteEntity->setNom('John');
$athleteEntity->setPrenom('Doe');
$athleteEntity->setIdAthlete(1234);
$athleteEntity->setEmail('kevin.monteiro@gmail.fr');
$athleteEntity->setSexe('H');
$athleteEntity->setTaille(169);
$athleteEntity->setPoids(69);
$athleteEntity->setMotDePasse('motdepasse');
$athleteEntity->setDateNaissance('26/03/2004');
//$result = $athleteGateway->addAthlete($athleteEntity);
//$this->assertTrue($result);
$athleteId = $athleteEntity->getIdAthlete();
$retrievedAthlete = $athleteGateway->getAthleteById($athleteId);
$this->assertInstanceOf(AthleteEntity::class, $retrievedAthlete);
$this->assertEquals('John', $retrievedAthlete->getNom());
$this->assertEquals('Doe', $retrievedAthlete->getPrenom());
}
}

@ -1,12 +0,0 @@
<?php
use PHPUnit\Framework\TestCase;
class MaClasseTest extends TestCase
{
public function testMethode()
{
echo "TEST MEC";
}
}

@ -0,0 +1 @@
{"version":1,"defects":[],"times":{"ExampleTest::testAddition":0.037}}

@ -24,6 +24,7 @@ return array(
'Dotenv\\' => array($vendorDir . '/vlucas/phpdotenv/src'), 'Dotenv\\' => array($vendorDir . '/vlucas/phpdotenv/src'),
'Doctrine\\Instantiator\\' => array($vendorDir . '/doctrine/instantiator/src/Doctrine/Instantiator'), 'Doctrine\\Instantiator\\' => array($vendorDir . '/doctrine/instantiator/src/Doctrine/Instantiator'),
'DeepCopy\\' => array($vendorDir . '/myclabs/deep-copy/src/DeepCopy'), 'DeepCopy\\' => array($vendorDir . '/myclabs/deep-copy/src/DeepCopy'),
'Database\\' => array($baseDir . '/src/data/core/database'),
'Data\\' => array($baseDir . '/src/data'), 'Data\\' => array($baseDir . '/src/data'),
'Console\\' => array($baseDir . '/src/console'), 'Console\\' => array($baseDir . '/src/console'),
'App\\' => array($baseDir . '/src/app'), 'App\\' => array($baseDir . '/src/app'),

@ -59,6 +59,7 @@ class ComposerStaticInitb084bad56d99d613841073027e5f5e7e
'Dotenv\\' => 7, 'Dotenv\\' => 7,
'Doctrine\\Instantiator\\' => 22, 'Doctrine\\Instantiator\\' => 22,
'DeepCopy\\' => 9, 'DeepCopy\\' => 9,
'Database\\' => 9,
'Data\\' => 5, 'Data\\' => 5,
), ),
'C' => 'C' =>
@ -146,6 +147,10 @@ class ComposerStaticInitb084bad56d99d613841073027e5f5e7e
array ( array (
0 => __DIR__ . '/..' . '/myclabs/deep-copy/src/DeepCopy', 0 => __DIR__ . '/..' . '/myclabs/deep-copy/src/DeepCopy',
), ),
'Database\\' =>
array (
0 => __DIR__ . '/../..' . '/src/data/core/database',
),
'Data\\' => 'Data\\' =>
array ( array (
0 => __DIR__ . '/../..' . '/src/data', 0 => __DIR__ . '/../..' . '/src/data',

@ -3,7 +3,7 @@
'name' => 'hearttrack/package', 'name' => 'hearttrack/package',
'pretty_version' => 'dev-master', 'pretty_version' => 'dev-master',
'version' => 'dev-master', 'version' => 'dev-master',
'reference' => 'd4345678992503b9eb56ef4afd00ff13f5d7531a', 'reference' => 'c09ce09b267f34dee8978397953b90d55d7d3873',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
@ -31,7 +31,7 @@
'hearttrack/package' => array( 'hearttrack/package' => array(
'pretty_version' => 'dev-master', 'pretty_version' => 'dev-master',
'version' => 'dev-master', 'version' => 'dev-master',
'reference' => 'd4345678992503b9eb56ef4afd00ff13f5d7531a', 'reference' => 'c09ce09b267f34dee8978397953b90d55d7d3873',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),

Loading…
Cancel
Save