mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
Added more tests
This commit is contained in:
parent
2c1e100094
commit
4ecf03ce8a
@ -22,7 +22,7 @@ class ApiDocExtractorTest extends WebTestCase
|
|||||||
$data = $extractor->all();
|
$data = $extractor->all();
|
||||||
|
|
||||||
$this->assertTrue(is_array($data));
|
$this->assertTrue(is_array($data));
|
||||||
$this->assertCount(2, $data);
|
$this->assertCount(3, $data);
|
||||||
|
|
||||||
foreach ($data as $d) {
|
foreach ($data as $d) {
|
||||||
$this->assertTrue(is_array($d));
|
$this->assertTrue(is_array($d));
|
||||||
|
@ -42,4 +42,11 @@ class TestController
|
|||||||
public function anotherAction()
|
public function anotherAction()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ApiDoc(description="Action without HTTP verb")
|
||||||
|
*/
|
||||||
|
public function anyAction()
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,10 @@ test_route_3:
|
|||||||
pattern: /another
|
pattern: /another
|
||||||
defaults: { _controller: NelmioApiDocTestBundle:Test:another }
|
defaults: { _controller: NelmioApiDocTestBundle:Test:another }
|
||||||
|
|
||||||
|
test_route_4:
|
||||||
|
pattern: /any
|
||||||
|
defaults: { _controller: NelmioApiDocTestBundle:Test:any, _format: json }
|
||||||
|
|
||||||
NelmioApiDocBundle:
|
NelmioApiDocBundle:
|
||||||
resource: "@NelmioApiDocBundle/Resources/config/routing.yml"
|
resource: "@NelmioApiDocBundle/Resources/config/routing.yml"
|
||||||
prefix: /
|
prefix: /
|
||||||
|
@ -58,6 +58,44 @@ b:
|
|||||||
|
|
||||||
* type: string
|
* type: string
|
||||||
* required: true
|
* required: true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# others #
|
||||||
|
|
||||||
|
### `ANY` /any ###
|
||||||
|
|
||||||
|
_Action without HTTP verb_
|
||||||
|
MARKDOWN;
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFormatOne()
|
||||||
|
{
|
||||||
|
$container = $this->getContainer();
|
||||||
|
|
||||||
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
||||||
|
$data = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::indexAction', 'test_route_1');
|
||||||
|
$result = $container->get('nelmio_api_doc.formatter.markdown_formatter')->formatOne($data['annotation'], $data['route']);
|
||||||
|
|
||||||
|
$expected = <<<MARKDOWN
|
||||||
|
### `GET` /tests ###
|
||||||
|
|
||||||
|
_index action_
|
||||||
|
|
||||||
|
#### Filters ####
|
||||||
|
|
||||||
|
a:
|
||||||
|
|
||||||
|
* dataType: integer
|
||||||
|
|
||||||
|
b:
|
||||||
|
|
||||||
|
* dataType: string
|
||||||
|
* arbitrary: ["arg1","arg2"]
|
||||||
|
|
||||||
|
|
||||||
MARKDOWN;
|
MARKDOWN;
|
||||||
|
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
|
@ -20,10 +20,18 @@ class SimpleFormatterTest extends WebTestCase
|
|||||||
$container = $this->getContainer();
|
$container = $this->getContainer();
|
||||||
|
|
||||||
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
||||||
$data = $extractor->all();
|
$data = $extractor->all();
|
||||||
$result = $container->get('nelmio_api_doc.formatter.simple_formatter')->format($data);
|
$result = $container->get('nelmio_api_doc.formatter.simple_formatter')->format($data);
|
||||||
|
|
||||||
$expected = array(
|
$expected = array(
|
||||||
|
'others' => array(
|
||||||
|
array(
|
||||||
|
'method' => 'ANY',
|
||||||
|
'uri' => '/any',
|
||||||
|
'requirements' => array(),
|
||||||
|
'description' => 'Action without HTTP verb'
|
||||||
|
)
|
||||||
|
),
|
||||||
'/tests' => array(
|
'/tests' => array(
|
||||||
array(
|
array(
|
||||||
'method' => 'GET',
|
'method' => 'GET',
|
||||||
@ -66,4 +74,34 @@ class SimpleFormatterTest extends WebTestCase
|
|||||||
|
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFormatOne()
|
||||||
|
{
|
||||||
|
$container = $this->getContainer();
|
||||||
|
|
||||||
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
||||||
|
$data = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::indexAction', 'test_route_1');
|
||||||
|
$result = $container->get('nelmio_api_doc.formatter.simple_formatter')->formatOne($data['annotation'], $data['route']);
|
||||||
|
|
||||||
|
$expected = array(
|
||||||
|
'method' => 'GET',
|
||||||
|
'uri' => '/tests',
|
||||||
|
'requirements' => array(),
|
||||||
|
'filters' => array(
|
||||||
|
'a' => array(
|
||||||
|
'dataType' => 'integer',
|
||||||
|
),
|
||||||
|
'b' => array(
|
||||||
|
'dataType' => 'string',
|
||||||
|
'arbitrary' => array(
|
||||||
|
'arg1',
|
||||||
|
'arg2',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'description' => 'index action'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user