Skip to content

Commit

Permalink
Added Dingo tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mpociot committed May 30, 2016
1 parent 097525f commit bf2c3a1
Show file tree
Hide file tree
Showing 7 changed files with 418 additions and 21 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
},
"require-dev": {
"orchestra/testbench": "~3.0",
"phpunit/phpunit": "~4.0 || ~5.0"
"phpunit/phpunit": "~4.0 || ~5.0",
"dingo/api": "1.0.*@dev"
},
"autoload": {
"psr-0": {
Expand Down
14 changes: 7 additions & 7 deletions src/Mpociot/ApiDoc/Generators/AbstractGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
abstract class AbstractGenerator
{
/**
* @param Route $route
* @param $route
*
* @return mixed
*/
abstract protected function getUri(Route $route);
abstract protected function getUri($route);

/**
* @param \Illuminate\Routing\Route $route
* @param array $bindings
*
* @return array
*/
abstract public function processRoute(Route $route, $bindings = []);
abstract public function processRoute($route, $bindings = []);

/**
* @param array $routeData
Expand Down Expand Up @@ -54,11 +54,11 @@ protected function getParameters($routeData, $routeAction)
}

/**
* @param \Illuminate\Routing\Route $route
* @param $route
*
* @return \Illuminate\Http\Response
*/
protected function getRouteResponse(Route $route, $bindings)
protected function getRouteResponse($route, $bindings)
{
$uri = $this->addRouteModelBindings($route, $bindings);

Expand All @@ -68,12 +68,12 @@ protected function getRouteResponse(Route $route, $bindings)
}

/**
* @param Route $route
* @param $route
* @param array $bindings
*
* @return mixed
*/
protected function addRouteModelBindings(Route $route, $bindings)
protected function addRouteModelBindings($route, $bindings)
{
$uri = $this->getUri($route);
foreach ($bindings as $model => $id) {
Expand Down
19 changes: 8 additions & 11 deletions src/Mpociot/ApiDoc/Generators/DingoGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Mpociot\ApiDoc\Generators;

use Illuminate\Support\Facades\App;
use Exception;

class DingoGenerator extends AbstractGenerator
{
Expand All @@ -14,26 +14,23 @@ class DingoGenerator extends AbstractGenerator
*/
public function processRoute($route, $bindings = [])
{
$response = $this->getRouteResponse($route, $bindings);

try {
$response = $this->getRouteResponse($route, $bindings);
} catch( Exception $e){
$response = '';
}
$routeAction = $route->getAction();
$routeGroup = $this->getRouteGroup($routeAction['uses']);
$routeDescription = $this->getRouteDescription($routeAction['uses']);

if ($response->headers->get('Content-Type') === 'application/json') {
$content = json_encode(json_decode($response->getContent()), JSON_PRETTY_PRINT);
} else {
$content = $response->getContent();
}

return $this->getParameters([
'resource' => $routeGroup,
'title' => $routeDescription['short'],
'description' => $routeDescription['long'],
'methods' => $route->getMethods(),
'uri' => $route->getUri(),
'uri' => $route->uri(),
'parameters' => [],
'response' => $content,
'response' => $response,
], $routeAction);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Mpociot/ApiDoc/Generators/LaravelGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class LaravelGenerator extends AbstractGenerator
*
* @return mixed
*/
protected function getUri(Route $route)
protected function getUri($route)
{
return $route->getUri();
}
Expand All @@ -24,7 +24,7 @@ protected function getUri(Route $route)
*
* @return array
*/
public function processRoute(Route $route, $bindings = [])
public function processRoute($route, $bindings = [])
{
$response = $this->getRouteResponse($route, $bindings);

Expand Down
Loading

0 comments on commit bf2c3a1

Please sign in to comment.