Added more tests

This commit is contained in:
William DURAND 2012-04-13 15:00:46 +02:00
parent 2c1e100094
commit 4ecf03ce8a
5 changed files with 90 additions and 3 deletions

View File

@ -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));

View File

@ -42,4 +42,11 @@ class TestController
public function anotherAction() public function anotherAction()
{ {
} }
/**
* @ApiDoc(description="Action without HTTP verb")
*/
public function anyAction()
{
}
} }

View File

@ -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: /

View File

@ -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);

View File

@ -24,6 +24,14 @@ class SimpleFormatterTest extends WebTestCase
$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);
}
} }