Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Services/SwaggerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ public function getConcreteRequest()
$explodedController = explode('@', $controller);

$class = $explodedController[0];
$method = $explodedController[1];
$method = $explodedController[1] ?? '__invoke';

if (!method_exists($class, $method)) {
return null;
Expand Down
19 changes: 19 additions & 0 deletions tests/SwaggerServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -868,4 +868,23 @@ public function testAddDataDescriptionForRouteConditionals()

app(SwaggerService::class)->addData($request, $response);
}

public function testAddDataWhenInvokableClass()
{
$this->mockDriverGetEmptyAndSaveTmpData($this->getJsonFixture('tmp_data_get_user_request_invoke'));

$service = app(SwaggerService::class);

$request = $this->generateRequest(
type: 'get',
uri: 'users',
isInvokeController: true,
);

$response = $this->generateResponse('example_success_user_response.json', 200, [
'Content-type' => 'application/json',
]);

$service->addData($request, $response);
}
}
21 changes: 17 additions & 4 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Orchestra\Testbench\TestCase as BaseTest;
use RonasIT\AutoDoc\AutoDocServiceProvider;
use RonasIT\AutoDoc\Tests\Support\Mock\TestController;
use RonasIT\AutoDoc\Tests\Support\Mock\TestInvokableController;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
use Symfony\Component\HttpFoundation\Response;

Expand Down Expand Up @@ -114,13 +115,25 @@ protected function clearDirectory($dirPath, $exceptPaths = []): void
}
}

protected function generateRequest($type, $uri, $data = [], $pathParams = [], $headers = [], $routeConditions = [], $controllerMethod = 'test'): Request
{
protected function generateRequest(
$type,
$uri,
$data = [],
$pathParams = [],
$headers = [],
$routeConditions = [],
$controllerMethod = 'test',
$isInvokeController = false,
): Request {
$request = $this->getBaseRequest($type, $uri, $data, $pathParams, $headers);

return $request->setRouteResolver(function () use ($uri, $request, $controllerMethod, $routeConditions) {
return $request->setRouteResolver(function () use ($isInvokeController, $uri, $request, $controllerMethod, $routeConditions) {
$action = $isInvokeController
? TestInvokableController::class . '@__invoke'
: TestController::class . '@' . $controllerMethod;

$route = Route::get($uri)
->setAction(['controller' => TestController::class . '@' . $controllerMethod])
->setAction(['controller' => $action])
->bind($request);

foreach ($routeConditions as $condition) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"openapi": "3.1.0",
"servers": [
{
"url": "http:\/\/localhost"
}
],
"paths": {
"/users": {
"get": {
"tags": [
"users"
],
"consumes": [],
"produces": [
"application/json"
],
"parameters": [],
"responses": {
"200": {
"description": "Operation successfully done",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/getUsers200ResponseObject",
"type": "object"
},
"example": {
"id": 2,
"name": "first_client",
"likes_count": 23,
"role": {
"id": 2,
"name": "client"
},
"type": "reader"
}
}
}
}
},
"security": [],
"description": "",
"summary": "test empty",
"deprecated": false
}
}
},
"components": {
"schemas": {
"getUsers200ResponseObject": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"likes_count": {
"type": "integer"
},
"role": {
"type": "array"
},
"type": {
"type": "string"
}
}
}
}
},
"info": {
"description": "This is automatically collected documentation",
"version": "0.0.0",
"title": "Name of Your Application",
"termsOfService": "",
"contact": {
"email": "[email protected]"
}
}
}
9 changes: 9 additions & 0 deletions tests/support/Mock/TestEmptyRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace RonasIT\AutoDoc\Tests\Support\Mock;

use Illuminate\Foundation\Http\FormRequest;

class TestEmptyRequest extends FormRequest
{
}
10 changes: 10 additions & 0 deletions tests/support/Mock/TestInvokableController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace RonasIT\AutoDoc\Tests\Support\Mock;

class TestInvokableController
{
public function __invoke(TestEmptyRequest $request)
{
}
}
Loading