From d5f0297c3a9de77e487709021f6ea0e74f27c545 Mon Sep 17 00:00:00 2001
From: xdrm-brackets
Date: Sat, 13 Feb 2016 00:04:00 +0100
Subject: [PATCH] - [x] [ModuleAnswer] Gestion des erreurs au niveau interne
des Modules
---
automate.php | 38 ++------------------
index.php | 3 +-
manager/ManagerError.php | 10 ++++--
manager/ModuleAnswer.php | 11 ++++++
manager/ModuleRequest.php | 11 ++++--
manager/module/userDefault.php | 21 ++++++-----
phpunit/coverage/Database.php.html | 2 +-
phpunit/coverage/ManagerError.php.html | 2 +-
phpunit/coverage/ResourceDispatcher.php.html | 2 +-
phpunit/coverage/autoloader.php.html | 2 +-
phpunit/coverage/index.dashboard.html | 2 +-
phpunit/coverage/index.html | 2 +-
phpunit/coverage/sessionManager.php.html | 2 +-
phpunit/phpunit.xml | 4 ++-
todo.md | 1 +
15 files changed, 54 insertions(+), 59 deletions(-)
diff --git a/automate.php b/automate.php
index 31ced1a..a0c84ef 100755
--- a/automate.php
+++ b/automate.php
@@ -236,7 +236,7 @@
function insertUsersComposite(){
// Creation de la requete
- $request = new \manager\ModuleRequest('userDefault/create', array('92-55-B9-B3', 'b', 'c', 'd', 'e', 'f', 'g') );
+ $request = new \manager\ModuleRequest('userDefault/create', array('92-55-B9-B3', 'b', 'bla', 'bla', 'bla@test.com', 'sadas', '1') );
$answer = $request->dispatch();
// Debug error
var_dump( $answer->error );
@@ -246,41 +246,7 @@
return true;
- }//insertUsersComposite();
-
-
-
-
-
-
- /* TEST DU CHECKER
- *
- *
- * @return status TRUE si aucune erreur, sinon FALSE
- *
- */
- function testDatabaseChecker(){
-
- /* (1) Code RFID */
- var_dump('user.code');
- var_dump( \manager\Database::check('user.code', '01-23-AB-CD' ) );
- var_dump( \manager\Database::check('user.code', '01-23-45-67-89-AB' ) );
- var_dump( \manager\Database::check('user.code', '01-23-AB-CG' ) );
- var_dump( \manager\Database::check('user.code', '01-23-45-67-89-AB-CD' ) );
-
- /* (2) Username / FirstName / Lastname */
- var_dump('user.username ; user.firstname ; user.lastname');
-
- /* (3) Adresse mail */
- var_dump('user.mail');
-
- /* (4) Password sha1 hash */
- var_dump('user.password');
-
-
- return true;
-
- }//testDatabaseChecker();
+ }insertUsersComposite();
?>
\ No newline at end of file
diff --git a/index.php b/index.php
index 26e675b..2138ed7 100755
--- a/index.php
+++ b/index.php
@@ -41,9 +41,8 @@
// Api
$R->post('api/?', function(){
- $request = \manager\ModuleRequest::fromURL($_POST);
+ $request = \manager\ModuleRequest::fromPost($_POST);
$answer = $request->dispatch();
-
echo $answer->serialize();
});
diff --git a/manager/ManagerError.php b/manager/ManagerError.php
index 3f43929..1988718 100755
--- a/manager/ManagerError.php
+++ b/manager/ManagerError.php
@@ -38,18 +38,21 @@
// Methode inamorcable
const UncallableMethod = 8;
+ // Erreur de parametre(s)
+ const ParamError = 9;
+
/* Repo */
// Verification de la coherence du chemin (existe dans la conf)
- const WrongPathRepo = 9;
+ const WrongPathRepo = 10;
// Module non specifie dans la conf
- const UnknownRepo = 10;
+ const UnknownRepo = 11;
/* Database */
// Erreur lors de la creation d'un objet PDO (connection)
- const PDOConnection = 11;
+ const PDOConnection = 12;
/* EXPLICITE UN CODE D'ERREUR
@@ -72,6 +75,7 @@
case self::UnknownRepo: return "Le repo n'existe pas"; break;
case self::UnknownMethod: return "Le methode n'existe pas"; break;
case self::UncallableMethod: return "Le methode n'est pas amorcable"; break;
+ case self::ParamError: return "Un ou plusieurs parametres sont manquants ou incorrects"; break;
case self::PDOConnection: return "La connexion avec la base de donnees a echoue"; break;
default: return "Erreur inconnue..."; break;
diff --git a/manager/ModuleAnswer.php b/manager/ModuleAnswer.php
index 3a5b899..808a4b3 100755
--- a/manager/ModuleAnswer.php
+++ b/manager/ModuleAnswer.php
@@ -67,6 +67,17 @@
*
*/
public function appendAll($dataset){
+ // Si ce n'est pas un tableau, on ne fais rien
+ if( !is_array($dataset) ) return $this;
+
+ // Si une valeur contient une erreur
+ if( array_key_exists('ModuleError', $dataset) ){
+ // On definit cette erreur
+ $this->error = $dataset['ModuleError'];
+ // On enleve cette entree des donnees
+ unset($dataset['ModuleError']);
+ }
+
// Ajoute une entree pour la cle @key et de valeur @value
$this->data = $dataset;
diff --git a/manager/ModuleRequest.php b/manager/ModuleRequest.php
index ed52eec..e7c3bbd 100755
--- a/manager/ModuleRequest.php
+++ b/manager/ModuleRequest.php
@@ -167,7 +167,7 @@
* @return instance Retourne un objet de type
*
*/
- public static function fromURL($post){
+ public static function fromPost($post){
/* [1] On verifie que le @path est renseigne
=========================================================*/
if( !isset($post['path']) )
@@ -175,7 +175,14 @@
/* [2] On verifie que @data est renseigne
=========================================================*/
- $data = (isset($post['data'])) ? $post['data'] : array();
+ // Si variable n'existe pas, on cree un tableau vide
+ $data = (isset($post['data'])) ? $post['data'] : array();
+
+ // Si c'est toujours pas un tableau, on essaie de voir si c'est un json
+ $data = (!is_array($data)) ? json_decode($data, true) : $data;
+
+ // Si toujours pas de tableau, on cree un tableau vide
+ $data = (!is_array($data)) ? array() : $data;
/* [3] On retourne une instance de
diff --git a/manager/module/userDefault.php b/manager/module/userDefault.php
index 8344d54..a59e21a 100755
--- a/manager/module/userDefault.php
+++ b/manager/module/userDefault.php
@@ -34,23 +34,28 @@
* @return status Retourne si oui ou non, tout s'est bien passe
*
*/
- public static function create($code, $username, $firstname, $lastname, $mail, $password, $status){
+ public static function create($code=null, $username=null, $firstname=null, $lastname=null, $mail=null, $password=null, $status=null){
/* [1] Normalisation + verification des donnees
=========================================================*/
$password_hash = \manager\sessionManager::secure_sha1($password);
$correct_param = \manager\Database::check('user.code', $code);
- $correct_param = $correct_param && \manager\Database::check('user.username', $username);
+ $correct_param = $correct_param && \manager\Database::check('user.username', $username);
$correct_param = $correct_param && \manager\Database::check('user.firstname', $firstname);
- $correct_param = $correct_param && \manager\Database::check('user.lastname', $lastname);
- $correct_param = $correct_param && \manager\Database::check('user.mail', $mail);
- $correct_param = $correct_param && \manager\Database::check('user.password', $password_hash);
- $correct_param = $correct_param && \manager\Database::check('user.status', $status);
+ $correct_param = $correct_param && \manager\Database::check('user.lastname', $lastname);
+ $correct_param = $correct_param && \manager\Database::check('user.mail', $mail);
+ $correct_param = $correct_param && \manager\Database::check('user.password', $password_hash);
+ $correct_param = $correct_param && \manager\Database::check('user.status', $status);
+
+ // Si les parametres ne sont pas corrects, on retourne une erreur
+ if( !$correct_param )
+ return array('ModuleError' => \manager\ManagerError::ParamError);
- $request = new \manager\Repo('user/create', array($code, $username, $firstname, $lastname, $mail, $password, $status) );
+ // $request = new \manager\Repo('user/create', array($code, $username, $firstname, $lastname, $mail, $password, $status) );
- return $request->answer();
+ // return $request->answer();
+ return array('ModuleError' => \manager\ManagerError::Success);
}
diff --git a/phpunit/coverage/Database.php.html b/phpunit/coverage/Database.php.html
index 05a6439..7adfff1 100755
--- a/phpunit/coverage/Database.php.html
+++ b/phpunit/coverage/Database.php.html
@@ -431,7 +431,7 @@
Dead Code
- Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 23:33:48 CET 2016.
+ Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 23:40:08 CET 2016.
diff --git a/phpunit/coverage/ManagerError.php.html b/phpunit/coverage/ManagerError.php.html
index 57c1c12..dc2e9fe 100644
--- a/phpunit/coverage/ManagerError.php.html
+++ b/phpunit/coverage/ManagerError.php.html
@@ -203,7 +203,7 @@
Dead Code
- Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 23:33:48 CET 2016.
+ Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 23:40:08 CET 2016.
diff --git a/phpunit/coverage/ResourceDispatcher.php.html b/phpunit/coverage/ResourceDispatcher.php.html
index 1bf9c1d..7367242 100644
--- a/phpunit/coverage/ResourceDispatcher.php.html
+++ b/phpunit/coverage/ResourceDispatcher.php.html
@@ -450,7 +450,7 @@
Dead Code
- Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 23:33:48 CET 2016.
+ Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 23:40:08 CET 2016.
diff --git a/phpunit/coverage/autoloader.php.html b/phpunit/coverage/autoloader.php.html
index 6317d90..1cc001c 100755
--- a/phpunit/coverage/autoloader.php.html
+++ b/phpunit/coverage/autoloader.php.html
@@ -153,7 +153,7 @@
Dead Code
- Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 23:33:48 CET 2016.
+ Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 23:40:08 CET 2016.
diff --git a/phpunit/coverage/index.dashboard.html b/phpunit/coverage/index.dashboard.html
index 8951ca5..4123f08 100755
--- a/phpunit/coverage/index.dashboard.html
+++ b/phpunit/coverage/index.dashboard.html
@@ -65,7 +65,7 @@
diff --git a/phpunit/coverage/index.html b/phpunit/coverage/index.html
index f01aa19..45d9ca9 100755
--- a/phpunit/coverage/index.html
+++ b/phpunit/coverage/index.html
@@ -177,7 +177,7 @@
High: 70% to 100%
- Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 23:33:48 CET 2016.
+ Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 23:40:08 CET 2016.
diff --git a/phpunit/coverage/sessionManager.php.html b/phpunit/coverage/sessionManager.php.html
index 389531d..eef0b6d 100644
--- a/phpunit/coverage/sessionManager.php.html
+++ b/phpunit/coverage/sessionManager.php.html
@@ -284,7 +284,7 @@
Dead Code
- Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 23:33:48 CET 2016.
+ Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 23:40:08 CET 2016.
diff --git a/phpunit/phpunit.xml b/phpunit/phpunit.xml
index b316503..bbe09a6 100755
--- a/phpunit/phpunit.xml
+++ b/phpunit/phpunit.xml
@@ -1,9 +1,11 @@
+
- ./tests/
+ ./tests/
+
diff --git a/todo.md b/todo.md
index 9073064..6961a1f 100755
--- a/todo.md
+++ b/todo.md
@@ -39,6 +39,7 @@
########
# FAIT #
########
+- [x] [ModuleAnswer] Gestion des erreurs au niveau interne des Modules
- [x] [autoloader][phpunit/bootstrap.php] Correction des bugs de $_SERVER avec PHPUnit -> autoloader + bootstrap personnalise
- [x] [sessionManager] Import de sessionManager
- [x] [phpunit/tests/Database_*] Tests unitaire de delNumeric()