Skip to content

Commit

Permalink
Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
n.zeinali committed Jun 28, 2023
1 parent 624d9b7 commit 661ab27
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
12 changes: 12 additions & 0 deletions Mapping/Apis/Users/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,16 @@ public function setFullname(mixed $fullname): static
return $this;
}

/**
* Gives a JSON representation of this user
* @return string
*/
public function toJson() {
return json_encode([
'fullname' => $this->fullname,
'username' => $this->username
]);
}


}
18 changes: 16 additions & 2 deletions app/Http/Controllers/DataMapperController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


use App\Http\Controllers\Controller;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Http\Request;
use JetBrains\PhpStorm\NoReturn;

Expand All @@ -21,6 +22,20 @@ class DataMapperController extends Controller
* @return void
*/
public function mapping(ApiResponses $apiResponses, EntityInterface $entity, Request $request, string $type)
{
$file = 'api.' . $type;
$data = $apiResponses->getData($file, $type);
try {
$result = $this->startMapping($data, $entity, $type);

return response($result->toJson(), 200);

} catch (\Exception $e) {
return response($e->getMessage(), 500);
}
}

public function test(ApiResponses $apiResponses, EntityInterface $entity, Request $request, string $type)
{
$file = 'api.'.$type;
$data = $apiResponses->getData($file, $type);
Expand All @@ -33,10 +48,9 @@ public function mapping(ApiResponses $apiResponses, EntityInterface $entity, Req
dd($result);

} catch (\Exception $e) {
echo "Error : ". $e->getMessage();
echo "Error : ". $e->getMessage();
}


}

}
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
use App\Http\Controllers\DataMapperController;

Route::get("/data-mapping/{type}", [DataMapperController::class, 'mapping']);
Route::get("/data-mapping-show/{type}", [DataMapperController::class, 'test']);


19 changes: 0 additions & 19 deletions tests/Feature/ExampleTest.php

This file was deleted.

0 comments on commit 661ab27

Please sign in to comment.