2012-04-13 14:27:51 +02:00
|
|
|
<?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 #
|
|
|
|
|
2012-08-10 11:38:01 +02:00
|
|
|
### `GET` /tests.{_format} ###
|
2012-04-13 14:27:51 +02:00
|
|
|
|
|
|
|
_index action_
|
|
|
|
|
2012-08-10 11:38:01 +02:00
|
|
|
#### Requirements ####
|
|
|
|
|
|
|
|
**_format**
|
|
|
|
|
|
|
|
|
2012-04-13 14:27:51 +02:00
|
|
|
#### Filters ####
|
|
|
|
|
|
|
|
a:
|
|
|
|
|
2012-07-20 02:02:45 +02:00
|
|
|
* DataType: integer
|
2012-04-13 14:27:51 +02:00
|
|
|
|
|
|
|
b:
|
|
|
|
|
2012-07-20 02:02:45 +02:00
|
|
|
* DataType: string
|
|
|
|
* Arbitrary: ["arg1","arg2"]
|
2012-04-13 14:27:51 +02:00
|
|
|
|
|
|
|
|
2012-08-10 11:38:01 +02:00
|
|
|
### `GET` /tests.{_format} ###
|
2012-04-14 10:11:52 +02:00
|
|
|
|
|
|
|
_index action_
|
|
|
|
|
2012-08-10 11:38:01 +02:00
|
|
|
#### Requirements ####
|
|
|
|
|
|
|
|
**_format**
|
|
|
|
|
|
|
|
|
2012-04-14 10:11:52 +02:00
|
|
|
#### Filters ####
|
|
|
|
|
|
|
|
a:
|
|
|
|
|
2012-07-20 02:02:45 +02:00
|
|
|
* DataType: integer
|
2012-04-14 10:11:52 +02:00
|
|
|
|
|
|
|
b:
|
|
|
|
|
2012-07-20 02:02:45 +02:00
|
|
|
* DataType: string
|
|
|
|
* Arbitrary: ["arg1","arg2"]
|
2012-04-14 10:11:52 +02:00
|
|
|
|
|
|
|
|
2012-08-10 11:38:01 +02:00
|
|
|
### `POST` /tests.{_format} ###
|
2012-04-14 10:11:52 +02:00
|
|
|
|
|
|
|
_create test_
|
|
|
|
|
2012-08-10 11:38:01 +02:00
|
|
|
#### Requirements ####
|
|
|
|
|
|
|
|
**_format**
|
|
|
|
|
|
|
|
|
2012-04-14 10:11:52 +02:00
|
|
|
#### Parameters ####
|
|
|
|
|
|
|
|
a:
|
|
|
|
|
|
|
|
* type: string
|
|
|
|
* required: true
|
|
|
|
* description: A nice description
|
|
|
|
|
|
|
|
b:
|
|
|
|
|
|
|
|
* type: string
|
2012-06-20 23:19:34 +02:00
|
|
|
* required: false
|
2012-05-23 00:20:03 +02:00
|
|
|
|
2012-07-12 12:13:24 +02:00
|
|
|
c:
|
|
|
|
|
|
|
|
* type: boolean
|
|
|
|
* required: true
|
|
|
|
|
2012-04-14 10:11:52 +02:00
|
|
|
|
2012-08-10 11:38:01 +02:00
|
|
|
### `POST` /tests.{_format} ###
|
2012-04-13 14:27:51 +02:00
|
|
|
|
|
|
|
_create test_
|
|
|
|
|
2012-08-10 11:38:01 +02:00
|
|
|
#### Requirements ####
|
|
|
|
|
|
|
|
**_format**
|
|
|
|
|
|
|
|
|
2012-04-13 14:27:51 +02:00
|
|
|
#### Parameters ####
|
|
|
|
|
|
|
|
a:
|
|
|
|
|
|
|
|
* type: string
|
|
|
|
* required: true
|
|
|
|
* description: A nice description
|
|
|
|
|
|
|
|
b:
|
|
|
|
|
|
|
|
* type: string
|
2012-06-20 23:19:34 +02:00
|
|
|
* required: false
|
2012-05-23 00:20:03 +02:00
|
|
|
|
2012-07-12 12:13:24 +02:00
|
|
|
c:
|
|
|
|
|
|
|
|
* type: boolean
|
|
|
|
* required: true
|
|
|
|
|
2012-04-13 15:00:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
# others #
|
|
|
|
|
2012-06-21 00:12:21 +02:00
|
|
|
### `POST` /another-post ###
|
|
|
|
|
|
|
|
_create another test_
|
|
|
|
|
|
|
|
#### Parameters ####
|
|
|
|
|
|
|
|
a:
|
|
|
|
|
|
|
|
* type: string
|
|
|
|
* required: true
|
|
|
|
* description: A nice description
|
|
|
|
|
|
|
|
|
2012-04-14 10:11:52 +02:00
|
|
|
### `ANY` /any ###
|
|
|
|
|
|
|
|
_Action without HTTP verb_
|
|
|
|
|
|
|
|
|
2012-04-19 20:27:27 +02:00
|
|
|
### `ANY` /any/{foo} ###
|
2012-04-13 15:00:46 +02:00
|
|
|
|
|
|
|
_Action without HTTP verb_
|
2012-04-19 17:05:59 +02:00
|
|
|
|
2012-04-19 20:27:27 +02:00
|
|
|
#### Requirements ####
|
|
|
|
|
|
|
|
**foo**
|
|
|
|
|
|
|
|
|
2012-04-19 17:05:59 +02:00
|
|
|
|
2012-08-07 17:50:58 -04:00
|
|
|
### `POST` /jms-input-test ###
|
|
|
|
|
|
|
|
_Testing JMS_
|
|
|
|
|
2012-08-07 21:47:33 -04:00
|
|
|
#### Parameters ####
|
|
|
|
|
|
|
|
foo:
|
|
|
|
|
|
|
|
* type: string
|
|
|
|
* required: false
|
|
|
|
* description: No description.
|
|
|
|
|
|
|
|
number:
|
|
|
|
|
|
|
|
* type: double
|
|
|
|
* required: false
|
|
|
|
* description: No description.
|
|
|
|
|
|
|
|
arr:
|
|
|
|
|
|
|
|
* type: array
|
|
|
|
* required: false
|
|
|
|
* description: No description.
|
|
|
|
|
2012-08-24 11:10:25 -04:00
|
|
|
nested:
|
|
|
|
|
|
|
|
* type: object (JmsNested)
|
|
|
|
* required: false
|
|
|
|
* description: No description.
|
|
|
|
|
2012-08-31 11:56:48 -04:00
|
|
|
nested[bar]:
|
|
|
|
|
|
|
|
* type: string
|
|
|
|
* required: false
|
|
|
|
* description: No description.
|
|
|
|
|
|
|
|
nested[baz][]:
|
|
|
|
|
|
|
|
* type: array of integers
|
|
|
|
* required: false
|
|
|
|
* description: Epic description.
|
|
|
|
|
|
|
|
With multiple lines.
|
|
|
|
|
|
|
|
nestedArray[]:
|
2012-08-24 11:10:25 -04:00
|
|
|
|
|
|
|
* type: array of objects (JmsNested)
|
|
|
|
* required: false
|
|
|
|
* description: No description.
|
|
|
|
|
2012-08-31 11:56:48 -04:00
|
|
|
nestedArray[][bar]:
|
|
|
|
|
|
|
|
* type: string
|
|
|
|
* required: false
|
|
|
|
* description: No description.
|
|
|
|
|
|
|
|
nestedArray[][baz][]:
|
|
|
|
|
|
|
|
* type: array of integers
|
|
|
|
* required: false
|
|
|
|
* description: Epic description.
|
|
|
|
|
|
|
|
With multiple lines.
|
|
|
|
|
2012-08-07 17:50:58 -04:00
|
|
|
|
2012-08-27 13:25:03 -04:00
|
|
|
### `GET` /jms-return-test ###
|
|
|
|
|
|
|
|
_Testing return_
|
|
|
|
|
|
|
|
#### Response ####
|
|
|
|
|
|
|
|
a:
|
|
|
|
|
|
|
|
* type: string
|
|
|
|
* description: A nice description
|
|
|
|
|
|
|
|
|
2012-05-07 12:51:22 +02:00
|
|
|
### `ANY` /my-commented/{id}/{page} ###
|
2012-04-19 17:05:59 +02:00
|
|
|
|
2012-07-13 16:04:29 +02:00
|
|
|
_This method is useful to test if the getDocComment works._
|
2012-04-19 20:27:27 +02:00
|
|
|
|
|
|
|
#### Requirements ####
|
|
|
|
|
|
|
|
**id**
|
|
|
|
|
|
|
|
- Type: int
|
|
|
|
- Description: A nice comment
|
2012-05-07 12:51:22 +02:00
|
|
|
**page**
|
|
|
|
|
|
|
|
- Type: int
|
2012-04-19 20:27:27 +02:00
|
|
|
|
|
|
|
|
2012-12-10 10:21:04 -08:00
|
|
|
### `ANY` /secure-route ###
|
|
|
|
|
|
|
|
|
|
|
|
#### Requirements ####
|
|
|
|
|
|
|
|
**_scheme**
|
|
|
|
|
|
|
|
- Requirement: https
|
|
|
|
|
|
|
|
|
2012-04-19 20:27:27 +02:00
|
|
|
### `ANY` /yet-another/{id} ###
|
|
|
|
|
|
|
|
|
|
|
|
#### Requirements ####
|
|
|
|
|
|
|
|
**id**
|
|
|
|
|
2012-07-18 12:46:22 +02:00
|
|
|
- Requirement: \d+
|
2012-07-20 00:58:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
### `GET` /z-action-with-query-param ###
|
|
|
|
|
|
|
|
|
|
|
|
#### Filters ####
|
|
|
|
|
|
|
|
page:
|
|
|
|
|
2012-07-20 02:02:45 +02:00
|
|
|
* Requirement: \d+
|
|
|
|
* Description: Page of the overview.
|
2012-11-14 23:59:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
### `POST` /z-action-with-request-param ###
|
|
|
|
|
|
|
|
|
|
|
|
#### Parameters ####
|
|
|
|
|
|
|
|
param1:
|
|
|
|
|
|
|
|
* type: string
|
|
|
|
* required: true
|
|
|
|
* description: Param1 description.
|
2012-04-13 15:00:46 +02:00
|
|
|
MARKDOWN;
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFormatOne()
|
|
|
|
{
|
|
|
|
$container = $this->getContainer();
|
|
|
|
|
2012-07-20 00:58:58 +02:00
|
|
|
$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);
|
2012-04-13 15:00:46 +02:00
|
|
|
|
|
|
|
$expected = <<<MARKDOWN
|
2012-08-10 11:38:01 +02:00
|
|
|
### `GET` /tests.{_format} ###
|
2012-04-13 15:00:46 +02:00
|
|
|
|
|
|
|
_index action_
|
|
|
|
|
2012-08-10 11:38:01 +02:00
|
|
|
#### Requirements ####
|
|
|
|
|
|
|
|
**_format**
|
|
|
|
|
|
|
|
|
2012-04-13 15:00:46 +02:00
|
|
|
#### Filters ####
|
|
|
|
|
|
|
|
a:
|
|
|
|
|
2012-07-20 02:02:45 +02:00
|
|
|
* DataType: integer
|
2012-04-13 15:00:46 +02:00
|
|
|
|
|
|
|
b:
|
|
|
|
|
2012-07-20 02:02:45 +02:00
|
|
|
* DataType: string
|
|
|
|
* Arbitrary: ["arg1","arg2"]
|
2012-04-13 15:00:46 +02:00
|
|
|
|
|
|
|
|
2012-04-13 14:27:51 +02:00
|
|
|
MARKDOWN;
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
}
|