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');
|
2013-02-15 13:33:05 +01:00
|
|
|
set_error_handler(array($this, 'handleDeprecation'));
|
2012-04-13 14:27:51 +02:00
|
|
|
$data = $extractor->all();
|
2013-02-11 14:42:17 +01:00
|
|
|
restore_error_handler();
|
2012-04-13 14:27:51 +02:00
|
|
|
$result = $container->get('nelmio_api_doc.formatter.markdown_formatter')->format($data);
|
|
|
|
|
2015-11-21 18:30:44 +01:00
|
|
|
$suffix = class_exists('Dunglas\ApiBundle\DunglasApiBundle') ? '' : '-no-dunglas';
|
|
|
|
$expected = file_get_contents(__DIR__ . '/testFormat-result' . $suffix . '.markdown');
|
2015-10-23 10:11:52 +02:00
|
|
|
|
2015-10-23 10:36:53 +02:00
|
|
|
$this->assertEquals($expected, $result . "\n");
|
2012-04-13 15:00:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|