From 67db76990e8dc5ce5e2f06f7cea9cc2c256ac1d2 Mon Sep 17 00:00:00 2001 From: Pierre-Yves LEBECQ Date: Thu, 21 Mar 2013 12:15:44 +0100 Subject: [PATCH] [Formatter] Fixed MarkdownFormatter. --- Formatter/MarkdownFormatter.php | 6 ++++-- Tests/Extractor/ApiDocExtratorTest.php | 4 ++-- Tests/Fixtures/Controller/TestController.php | 10 ++++++++++ Tests/Fixtures/app/config/routing.yml | 6 ++++++ Tests/Formatter/MarkdownFormatterTest.php | 12 ++++++++++++ Tests/Formatter/SimpleFormatterTest.php | 20 ++++++++++++++++++++ 6 files changed, 54 insertions(+), 4 deletions(-) diff --git a/Formatter/MarkdownFormatter.php b/Formatter/MarkdownFormatter.php index ec51769..f869ea0 100644 --- a/Formatter/MarkdownFormatter.php +++ b/Formatter/MarkdownFormatter.php @@ -123,13 +123,15 @@ class MarkdownFormatter extends AbstractFormatter { if ('_others' !== $section) { $markdown = sprintf("# %s #\n\n", $section); + } else { + $markdown = ''; } foreach ($resources as $resource => $methods) { if ('_others' === $section && 'others' !== $resource) { - $markdown = sprintf("## %s ##\n\n", $resource); + $markdown .= sprintf("## %s ##\n\n", $resource); } elseif ('others' !== $resource) { - $markdown = sprintf("## %s ##\n\n", $resource); + $markdown .= sprintf("## %s ##\n\n", $resource); } foreach ($methods as $method) { diff --git a/Tests/Extractor/ApiDocExtratorTest.php b/Tests/Extractor/ApiDocExtratorTest.php index b0aa152..b4217fa 100644 --- a/Tests/Extractor/ApiDocExtratorTest.php +++ b/Tests/Extractor/ApiDocExtratorTest.php @@ -24,7 +24,7 @@ class ApiDocExtractorTest extends WebTestCase restore_error_handler(); $this->assertTrue(is_array($data)); - $this->assertCount(15, $data); + $this->assertCount(16, $data); foreach ($data as $d) { $this->assertTrue(is_array($d)); @@ -64,7 +64,7 @@ class ApiDocExtractorTest extends WebTestCase $this->assertFalse(isset($array2['filters'])); $this->assertEquals('Nelmio\ApiDocBundle\Tests\Fixtures\Form\TestType', $a2->getInput()); - $a3 = $data['11']['annotation']; + $a3 = $data['12']['annotation']; $this->assertTrue($a3->getHttps()); } diff --git a/Tests/Fixtures/Controller/TestController.php b/Tests/Fixtures/Controller/TestController.php index 2402c8a..1c33286 100644 --- a/Tests/Fixtures/Controller/TestController.php +++ b/Tests/Fixtures/Controller/TestController.php @@ -43,6 +43,16 @@ class TestController { } + /** + * @ApiDoc( + * description="post test 2", + * resource=true + * ) + */ + public function postTest2Action() + { + } + public function anotherAction() { } diff --git a/Tests/Fixtures/app/config/routing.yml b/Tests/Fixtures/app/config/routing.yml index d128ce0..43c6dd2 100644 --- a/Tests/Fixtures/app/config/routing.yml +++ b/Tests/Fixtures/app/config/routing.yml @@ -91,3 +91,9 @@ test_service_route_4: NelmioApiDocBundle: resource: "@NelmioApiDocBundle/Resources/config/routing.yml" prefix: / + +test_route_14: + pattern: /tests2.{_format} + defaults: { _controller: NelmioApiDocTestBundle:Test:postTest2, _format: json } + requirements: + _method: POST diff --git a/Tests/Formatter/MarkdownFormatterTest.php b/Tests/Formatter/MarkdownFormatterTest.php index bfd9638..7f9de03 100644 --- a/Tests/Formatter/MarkdownFormatterTest.php +++ b/Tests/Formatter/MarkdownFormatterTest.php @@ -126,6 +126,18 @@ c: * required: true +## /tests2 ## + +### `POST` /tests2.{_format} ### + +_post test 2_ + +#### Requirements #### + +**_format** + + + ### `POST` /another-post ### _create another test_ diff --git a/Tests/Formatter/SimpleFormatterTest.php b/Tests/Formatter/SimpleFormatterTest.php index 7da0bf8..4de4e89 100644 --- a/Tests/Formatter/SimpleFormatterTest.php +++ b/Tests/Formatter/SimpleFormatterTest.php @@ -477,6 +477,26 @@ And, it supports multilines until the first \'@\' char.', 'authentication' => false, ), ), + '/tests2' => + array ( + 0 => + array ( + 'method' => 'POST', + 'uri' => '/tests2.{_format}', + 'description' => 'post test 2', + 'requirements' => + array ( + '_format' => + array ( + 'requirement' => '', + 'dataType' => '', + 'description' => '', + ), + ), + 'https' => false, + 'authentication' => false, + ), + ), ); $this->assertEquals($expected, $result);