- [x] [ModuleAnswer] Gestion des erreurs au niveau interne des Modules

This commit is contained in:
xdrm-brackets 2016-02-13 00:04:00 +01:00
parent 86e726005d
commit d5f0297c3a
15 changed files with 54 additions and 59 deletions

View File

@ -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<Boolean> 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();
?>

View File

@ -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();
});

View File

@ -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;

View File

@ -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;

View File

@ -167,7 +167,7 @@
* @return instance<ModuleRequest> Retourne un objet de type <ModuleRequest>
*
*/
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 <ModuleRequest>

View File

@ -34,23 +34,28 @@
* @return status<Boolean> 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);
}

View File

@ -431,7 +431,7 @@
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 1.2.13</a> using <a href="http://www.php.net/" target="_top">PHP 5.5.9-1ubuntu4.14</a> and <a href="http://phpunit.de/">PHPUnit 3.7.28</a> at Fri Feb 12 23:33:48 CET 2016.</small>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 1.2.13</a> using <a href="http://www.php.net/" target="_top">PHP 5.5.9-1ubuntu4.14</a> and <a href="http://phpunit.de/">PHPUnit 3.7.28</a> at Fri Feb 12 23:40:08 CET 2016.</small>
</p>
</footer>
</div>

View File

@ -203,7 +203,7 @@
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 1.2.13</a> using <a href="http://www.php.net/" target="_top">PHP 5.5.9-1ubuntu4.14</a> and <a href="http://phpunit.de/">PHPUnit 3.7.28</a> at Fri Feb 12 23:33:48 CET 2016.</small>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 1.2.13</a> using <a href="http://www.php.net/" target="_top">PHP 5.5.9-1ubuntu4.14</a> and <a href="http://phpunit.de/">PHPUnit 3.7.28</a> at Fri Feb 12 23:40:08 CET 2016.</small>
</p>
</footer>
</div>

View File

@ -450,7 +450,7 @@
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 1.2.13</a> using <a href="http://www.php.net/" target="_top">PHP 5.5.9-1ubuntu4.14</a> and <a href="http://phpunit.de/">PHPUnit 3.7.28</a> at Fri Feb 12 23:33:48 CET 2016.</small>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 1.2.13</a> using <a href="http://www.php.net/" target="_top">PHP 5.5.9-1ubuntu4.14</a> and <a href="http://phpunit.de/">PHPUnit 3.7.28</a> at Fri Feb 12 23:40:08 CET 2016.</small>
</p>
</footer>
</div>

View File

@ -153,7 +153,7 @@
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 1.2.13</a> using <a href="http://www.php.net/" target="_top">PHP 5.5.9-1ubuntu4.14</a> and <a href="http://phpunit.de/">PHPUnit 3.7.28</a> at Fri Feb 12 23:33:48 CET 2016.</small>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 1.2.13</a> using <a href="http://www.php.net/" target="_top">PHP 5.5.9-1ubuntu4.14</a> and <a href="http://phpunit.de/">PHPUnit 3.7.28</a> at Fri Feb 12 23:40:08 CET 2016.</small>
</p>
</footer>
</div>

View File

@ -65,7 +65,7 @@
</div>
<footer>
<p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 1.2.13</a> using <a href="http://www.php.net/" target="_top">PHP 5.5.9-1ubuntu4.14</a> and <a href="http://phpunit.de/">PHPUnit 3.7.28</a> at Fri Feb 12 23:33:48 CET 2016.</small>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 1.2.13</a> using <a href="http://www.php.net/" target="_top">PHP 5.5.9-1ubuntu4.14</a> and <a href="http://phpunit.de/">PHPUnit 3.7.28</a> at Fri Feb 12 23:40:08 CET 2016.</small>
</p>
</footer>
</div>

View File

@ -177,7 +177,7 @@
<span class="success"><strong>High</strong>: 70% to 100%</span>
</p>
<p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 1.2.13</a> using <a href="http://www.php.net/" target="_top">PHP 5.5.9-1ubuntu4.14</a> and <a href="http://phpunit.de/">PHPUnit 3.7.28</a> at Fri Feb 12 23:33:48 CET 2016.</small>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 1.2.13</a> using <a href="http://www.php.net/" target="_top">PHP 5.5.9-1ubuntu4.14</a> and <a href="http://phpunit.de/">PHPUnit 3.7.28</a> at Fri Feb 12 23:40:08 CET 2016.</small>
</p>
</footer>
</div>

View File

@ -284,7 +284,7 @@
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 1.2.13</a> using <a href="http://www.php.net/" target="_top">PHP 5.5.9-1ubuntu4.14</a> and <a href="http://phpunit.de/">PHPUnit 3.7.28</a> at Fri Feb 12 23:33:48 CET 2016.</small>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 1.2.13</a> using <a href="http://www.php.net/" target="_top">PHP 5.5.9-1ubuntu4.14</a> and <a href="http://phpunit.de/">PHPUnit 3.7.28</a> at Fri Feb 12 23:40:08 CET 2016.</small>
</p>
</footer>
</div>

View File

@ -1,9 +1,11 @@
<phpunit bootstrap="./bootstrap.php">
<testsuites>
<testsuite name="\manager\Database">
<directory suffix=".php">./tests/</directory>
<directory prefix="Database_" suffix=".php">./tests/</directory>
</testsuite>
</testsuites>

View File

@ -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()