mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-03-10 09:36:10 +03:00
Move logic to extract data in the Extractor Remove logic in the AbstractFormatter Use ApiDoc class as data container Update tests Add test to prove the bug with FOSRestBundle annotations (\\d+ instead of \d+)
207 lines
2.8 KiB
PHP
207 lines
2.8 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the NelmioApiDocBundle.
|
|
*
|
|
* (c) Nelmio <hello@nelm.io>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Nelmio\ApiDocBundle\Tests\Formatter;
|
|
|
|
use Nelmio\ApiDocBundle\Tests\WebTestCase;
|
|
|
|
class MarkdownFormatterTest extends WebTestCase
|
|
{
|
|
public function testFormat()
|
|
{
|
|
$container = $this->getContainer();
|
|
|
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
|
$data = $extractor->all();
|
|
$result = $container->get('nelmio_api_doc.formatter.markdown_formatter')->format($data);
|
|
|
|
$expected = <<<MARKDOWN
|
|
# /tests #
|
|
|
|
### `GET` /tests ###
|
|
|
|
_index action_
|
|
|
|
#### Filters ####
|
|
|
|
a:
|
|
|
|
* dataType: integer
|
|
|
|
b:
|
|
|
|
* dataType: string
|
|
* arbitrary: ["arg1","arg2"]
|
|
|
|
|
|
### `GET` /tests ###
|
|
|
|
_index action_
|
|
|
|
#### Filters ####
|
|
|
|
a:
|
|
|
|
* dataType: integer
|
|
|
|
b:
|
|
|
|
* dataType: string
|
|
* arbitrary: ["arg1","arg2"]
|
|
|
|
|
|
### `POST` /tests ###
|
|
|
|
_create test_
|
|
|
|
#### Parameters ####
|
|
|
|
a:
|
|
|
|
* type: string
|
|
* required: true
|
|
* description: A nice description
|
|
|
|
b:
|
|
|
|
* type: string
|
|
* required: false
|
|
|
|
c:
|
|
|
|
* type: boolean
|
|
* required: true
|
|
|
|
|
|
### `POST` /tests ###
|
|
|
|
_create test_
|
|
|
|
#### Parameters ####
|
|
|
|
a:
|
|
|
|
* type: string
|
|
* required: true
|
|
* description: A nice description
|
|
|
|
b:
|
|
|
|
* type: string
|
|
* required: false
|
|
|
|
c:
|
|
|
|
* type: boolean
|
|
* required: true
|
|
|
|
|
|
|
|
# others #
|
|
|
|
### `POST` /another-post ###
|
|
|
|
_create another test_
|
|
|
|
#### Parameters ####
|
|
|
|
a:
|
|
|
|
* type: string
|
|
* required: true
|
|
* description: A nice description
|
|
|
|
|
|
### `ANY` /any ###
|
|
|
|
_Action without HTTP verb_
|
|
|
|
|
|
### `ANY` /any/{foo} ###
|
|
|
|
_Action without HTTP verb_
|
|
|
|
#### Requirements ####
|
|
|
|
**foo**
|
|
|
|
|
|
|
|
### `ANY` /my-commented/{id}/{page} ###
|
|
|
|
_This method is useful to test if the getDocComment works._
|
|
|
|
#### Requirements ####
|
|
|
|
**id**
|
|
|
|
- Type: int
|
|
- Description: A nice comment
|
|
**page**
|
|
|
|
- Type: int
|
|
|
|
|
|
### `ANY` /yet-another/{id} ###
|
|
|
|
|
|
#### Requirements ####
|
|
|
|
**id**
|
|
|
|
- Requirement: \d+
|
|
|
|
|
|
### `GET` /z-action-with-query-param ###
|
|
|
|
|
|
#### Filters ####
|
|
|
|
page:
|
|
|
|
* requirement: \d+
|
|
* description: Page of the overview.
|
|
MARKDOWN;
|
|
|
|
$this->assertEquals($expected, $result);
|
|
}
|
|
|
|
public function testFormatOne()
|
|
{
|
|
$container = $this->getContainer();
|
|
|
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
|
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::indexAction', 'test_route_1');
|
|
$result = $container->get('nelmio_api_doc.formatter.markdown_formatter')->formatOne($annotation);
|
|
|
|
$expected = <<<MARKDOWN
|
|
### `GET` /tests ###
|
|
|
|
_index action_
|
|
|
|
#### Filters ####
|
|
|
|
a:
|
|
|
|
* dataType: integer
|
|
|
|
b:
|
|
|
|
* dataType: string
|
|
* arbitrary: ["arg1","arg2"]
|
|
|
|
|
|
MARKDOWN;
|
|
|
|
$this->assertEquals($expected, $result);
|
|
}
|
|
}
|