add exception management, correct mistakes in error management in Image.php and add function to simplify parameters using in tests
This commit is contained in:
parent
e01936a73e
commit
fe0eb3a9e2
4 changed files with 338 additions and 289 deletions
|
@ -94,6 +94,12 @@ class AppTest{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setPostParam($name, $value){
|
||||||
|
|
||||||
|
$this->postParams[$name] = $value;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function setOutput($key, $out){
|
public function setOutput($key, $out){
|
||||||
|
|
||||||
$this->output[$key] = $out;
|
$this->output[$key] = $out;
|
||||||
|
|
|
@ -14,55 +14,39 @@ $opt['minDisk'] = 1;
|
||||||
$opt['protected'] = false;
|
$opt['protected'] = false;
|
||||||
$opt['minRam'] = 10;
|
$opt['minRam'] = 10;
|
||||||
|
|
||||||
//$new_image = $image->createImage($opt);
|
//$App->setPostParam('id', 'sdfihlus154dfhj');
|
||||||
|
$err = $image->action("createImage");
|
||||||
|
|
||||||
|
|
||||||
//Liste des images
|
//Liste des images
|
||||||
$image->action("listImage");
|
$image->action("listImage");
|
||||||
//$images = $image->listImage();
|
|
||||||
$im = $App->show();
|
$im = $App->show();
|
||||||
$images = json_decode($im, true)["Images"];
|
$images = json_decode($im, true)["Images"];
|
||||||
if(isset($images)){
|
$recup;
|
||||||
|
|
||||||
echo "Images présentes :";
|
echo "Images présentes :";
|
||||||
echo "</br>";
|
echo "</br>";
|
||||||
foreach($images as $i){
|
foreach($images as $i){
|
||||||
echo $i['name'];
|
$recup = $i;
|
||||||
|
echo $recup['name'];
|
||||||
echo "</br>";
|
echo "</br>";
|
||||||
|
//echo $recup['id'];
|
||||||
}
|
}
|
||||||
echo "</br>";
|
echo "</br>";
|
||||||
|
echo "Erreur capturée: ";
|
||||||
if(isset($list)){
|
|
||||||
foreach ($list as $l) {
|
|
||||||
echo $l;
|
|
||||||
echo "</br>";
|
echo "</br>";
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
echo "Aucune image présente\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Détails Image
|
|
||||||
//$details = $image->imageDetails($id_image);
|
|
||||||
|
|
||||||
//$image->deleteImage('123456');
|
|
||||||
|
|
||||||
//$image->desactivateImage($id_image);
|
|
||||||
//$image->reactivateImage($id_image);
|
|
||||||
|
|
||||||
//$file_name = "/home/yogg/Downloads/TinyCore-6.4.1.iso";
|
|
||||||
//$image->uploadImage($id_image, $file_name);
|
|
||||||
|
|
||||||
//$image->downloadImage($id_image);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
$opt_update = Array();
|
//$App->setPostParam('id', $recup['id']);
|
||||||
$opt_update['name'] = "Test";
|
$App->setPostParam('id', 'sdfihlus154dfhj');
|
||||||
$opt_update['tags'] = null;
|
$err = $image->action("detailsImage");
|
||||||
|
$temp = $App->show();
|
||||||
$update = $image->updateImage($id_image, $opt_update);
|
$ret = json_decode($temp, true)["Images"];
|
||||||
echo $update->name;
|
echo $ret['id'];
|
||||||
*/
|
*/
|
||||||
|
//$App->getPostParam("id");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -33,6 +33,10 @@ Class errorManagement{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function OtherException($error){
|
||||||
|
$this->app->setOutput("Error", $error->getMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,6 +131,8 @@ class image implements Core{
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
}catch(NotImplementedError $e){
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
|
}catch(Exception $e){
|
||||||
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
}
|
}
|
||||||
$this->app->setOutput("Images", $image);
|
$this->app->setOutput("Images", $image);
|
||||||
|
|
||||||
|
@ -156,6 +158,8 @@ class image implements Core{
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
}catch(NotImplementedError $e){
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
|
}catch(Exception $e){
|
||||||
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->app->setOutput("Images", $result);
|
$this->app->setOutput("Images", $result);
|
||||||
|
@ -171,17 +175,21 @@ class image implements Core{
|
||||||
*/
|
*/
|
||||||
private function detailsImage(){
|
private function detailsImage(){
|
||||||
$id = $this->app->getPostParam("id");
|
$id = $this->app->getPostParam("id");
|
||||||
|
|
||||||
if(!isset($id)){
|
if(!isset($id)){
|
||||||
$this->app->setOutput("Error", "Incorrect id parameter");
|
$this->app->setOutput("Error", "Incorrect id parameter");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
try{
|
try{
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
$image = $service->getImage($id);
|
$image = $service->getImage($id);
|
||||||
if($image == null){ // if the image don't exists -> error
|
if($image == null){ // if the image don't exists -> error
|
||||||
$this->app->setOutput("Error", "Image doesn't exist");
|
$this->app->setOutput("Error", "Image doesn't exist");
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
echo 'toto';
|
||||||
$this->app->setOutput("Images", $image);
|
$this->app->setOutput("Images", $image);
|
||||||
|
}
|
||||||
}catch(BadResponseError $e){
|
}catch(BadResponseError $e){
|
||||||
$this->app->getErrorInstance()->BadResponseHandler($e);
|
$this->app->getErrorInstance()->BadResponseHandler($e);
|
||||||
}catch(UserInputError $e){
|
}catch(UserInputError $e){
|
||||||
|
@ -190,6 +198,9 @@ class image implements Core{
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
}catch(NotImplementedError $e){
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
|
}catch(Exception $e){
|
||||||
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,10 +220,10 @@ class image implements Core{
|
||||||
if(!isset($id)){
|
if(!isset($id)){
|
||||||
$this->app->setOutput("Error", "Incorrect id parameter");
|
$this->app->setOutput("Error", "Incorrect id parameter");
|
||||||
}
|
}
|
||||||
if(!isset($opt)){
|
else if(!isset($opt)){
|
||||||
$this->app->setOutput("Error", "Incorrect opt parameter");
|
$this->app->setOutput("Error", "Incorrect opt parameter");
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
try{
|
try{
|
||||||
//vérifier existence image
|
//vérifier existence image
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
|
@ -251,9 +262,12 @@ class image implements Core{
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
}catch(NotImplementedError $e){
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
|
}catch(Exception $e){
|
||||||
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
}
|
}
|
||||||
$this->app->setOutput("Images", $image);
|
$this->app->setOutput("Images", $image);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete an image
|
* Delete an image
|
||||||
|
@ -269,7 +283,7 @@ class image implements Core{
|
||||||
if(!isset($id)){
|
if(!isset($id)){
|
||||||
$this->app->setOutput("Error", "Image doesn't exist");
|
$this->app->setOutput("Error", "Image doesn't exist");
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
try{
|
try{
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
$image = $this->libClass->getImage($id);
|
$image = $this->libClass->getImage($id);
|
||||||
|
@ -285,6 +299,9 @@ class image implements Core{
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
}catch(NotImplementedError $e){
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
|
}catch(Exception $e){
|
||||||
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,6 +318,8 @@ class image implements Core{
|
||||||
if(!isset($id)){
|
if(!isset($id)){
|
||||||
$this->app->setOutput("Error", "Incorrect parameter");
|
$this->app->setOutput("Error", "Incorrect parameter");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
try{
|
try{
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
$image = $service->getImage($id);
|
$image = $service->getImage($id);
|
||||||
|
@ -316,6 +335,9 @@ class image implements Core{
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
}catch(NotImplementedError $e){
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
|
}catch(Exception $e){
|
||||||
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,6 +354,8 @@ class image implements Core{
|
||||||
if(!isset($id)){
|
if(!isset($id)){
|
||||||
$this->app->setOutput("Error", "Incorrect parameter");
|
$this->app->setOutput("Error", "Incorrect parameter");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
try{
|
try{
|
||||||
// vérifier existence image
|
// vérifier existence image
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
|
@ -348,6 +372,9 @@ class image implements Core{
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
}catch(NotImplementedError $e){
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
|
}catch(Exception $e){
|
||||||
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,9 +394,10 @@ class image implements Core{
|
||||||
if(!isset($id)){
|
if(!isset($id)){
|
||||||
$this->app->setOutput("Error", "Incorrect id parameter");
|
$this->app->setOutput("Error", "Incorrect id parameter");
|
||||||
}
|
}
|
||||||
if(!isset($file_name)){
|
else if(!isset($file_name)){
|
||||||
$this->app->setOutput("Error", "Incorrect file name parameter");
|
$this->app->setOutput("Error", "Incorrect file name parameter");
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
try{
|
try{
|
||||||
// vérifier existence image
|
// vérifier existence image
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
|
@ -387,6 +415,9 @@ class image implements Core{
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
}catch(NotImplementedError $e){
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
|
}catch(Exception $e){
|
||||||
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,6 +434,7 @@ class image implements Core{
|
||||||
if(!isset($id)){
|
if(!isset($id)){
|
||||||
$this->app->setOutput("Error", "Incorrect id parameter");
|
$this->app->setOutput("Error", "Incorrect id parameter");
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
try{
|
try{
|
||||||
// vérifier existence image
|
// vérifier existence image
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
|
@ -419,9 +451,12 @@ class image implements Core{
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
}catch(NotImplementedError $e){
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
|
}catch(Exception $e){
|
||||||
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
}
|
}
|
||||||
$this->app->setOutput("Images", $stream);
|
$this->app->setOutput("Images", $stream);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a member to image
|
* Add a member to image
|
||||||
|
@ -438,9 +473,10 @@ class image implements Core{
|
||||||
if(!isset($image_id)){
|
if(!isset($image_id)){
|
||||||
$this->app->setOutput("Error", "Incorrect image id parameter");
|
$this->app->setOutput("Error", "Incorrect image id parameter");
|
||||||
}
|
}
|
||||||
if(!isset($member_id)){
|
else if(!isset($member_id)){
|
||||||
$this->app->setOutput("Error", "Incorrect member id parameter");
|
$this->app->setOutput("Error", "Incorrect member id parameter");
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
try{
|
try{
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
|
|
||||||
|
@ -458,6 +494,9 @@ class image implements Core{
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
}catch(NotImplementedError $e){
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
|
}catch(Exception $e){
|
||||||
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -476,9 +515,10 @@ class image implements Core{
|
||||||
if(!isset($image_id)){
|
if(!isset($image_id)){
|
||||||
$this->app->setOutput("Error", "Incorrect image id parameter");
|
$this->app->setOutput("Error", "Incorrect image id parameter");
|
||||||
}
|
}
|
||||||
if(!isset($member_id)){
|
else if(!isset($member_id)){
|
||||||
$this->app->setOutput("Error", "Incorrect member id parameter");
|
$this->app->setOutput("Error", "Incorrect member id parameter");
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
try{
|
try{
|
||||||
// vérifier existence image
|
// vérifier existence image
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
|
@ -498,9 +538,12 @@ class image implements Core{
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
}catch(NotImplementedError $e){
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
|
}catch(Exception $e){
|
||||||
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
}
|
}
|
||||||
$this->app->setOutput("Images", $members);
|
$this->app->setOutput("Images", $members);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show details of a member of an image
|
* Show details of a member of an image
|
||||||
|
@ -517,9 +560,10 @@ class image implements Core{
|
||||||
if(!isset($image_id)){
|
if(!isset($image_id)){
|
||||||
$this->app->setOutput("Error", "Incorrect image id parameter");
|
$this->app->setOutput("Error", "Incorrect image id parameter");
|
||||||
}
|
}
|
||||||
if(!isset($member_id)){
|
else if(!isset($member_id)){
|
||||||
$this->app->setOutput("Error", "Incorrect member id parameter");
|
$this->app->setOutput("Error", "Incorrect member id parameter");
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
try{
|
try{
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
|
|
||||||
|
@ -540,9 +584,12 @@ class image implements Core{
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
}catch(NotImplementedError $e){
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
|
}catch(Exception $e){
|
||||||
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
}
|
}
|
||||||
$this->app->setOutput("Images", $member);
|
$this->app->setOutput("Images", $member);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a member of an image
|
* Remove a member of an image
|
||||||
|
@ -559,9 +606,10 @@ class image implements Core{
|
||||||
if(!isset($image_id)){
|
if(!isset($image_id)){
|
||||||
$this->app->setOutput("Error", "Incorrect image id parameter");
|
$this->app->setOutput("Error", "Incorrect image id parameter");
|
||||||
}
|
}
|
||||||
if(!isset($member_id)){
|
else if(!isset($member_id)){
|
||||||
$this->app->setOutput("Error", "Incorrect member id parameter");
|
$this->app->setOutput("Error", "Incorrect member id parameter");
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
try{
|
try{
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
|
|
||||||
|
@ -582,6 +630,9 @@ class image implements Core{
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
}catch(NotImplementedError $e){
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
|
}catch(Exception $e){
|
||||||
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -602,9 +653,10 @@ class image implements Core{
|
||||||
if(!isset($image_id)){
|
if(!isset($image_id)){
|
||||||
$this->app->setOutput("Error", "Incorrect image id parameter");
|
$this->app->setOutput("Error", "Incorrect image id parameter");
|
||||||
}
|
}
|
||||||
if(!isset($member_id)){
|
else if(!isset($member_id)){
|
||||||
$this->app->setOutput("Error", "Incorrect member id parameter");
|
$this->app->setOutput("Error", "Incorrect member id parameter");
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
try{
|
try{
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
|
|
||||||
|
@ -625,6 +677,9 @@ class image implements Core{
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
}catch(NotImplementedError $e){
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
|
}catch(Exception $e){
|
||||||
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue