2012-04-13 14:11:54 +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.
|
|
|
|
*/
|
|
|
|
|
2012-04-13 14:22:07 +02:00
|
|
|
namespace Nelmio\ApiDocBundle\Tests\Formatter;
|
|
|
|
|
|
|
|
use Nelmio\ApiDocBundle\Tests\WebTestCase;
|
2012-04-13 14:11:54 +02:00
|
|
|
|
|
|
|
class SimpleFormatterTest extends WebTestCase
|
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testFormat(): void
|
2015-10-23 10:11:52 +02:00
|
|
|
{
|
|
|
|
$container = $this->getContainer();
|
|
|
|
|
|
|
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
2024-10-01 15:54:04 +03:00
|
|
|
set_error_handler([$this, 'handleDeprecation']);
|
|
|
|
$data = $extractor->all();
|
2015-10-23 10:11:52 +02:00
|
|
|
restore_error_handler();
|
2024-10-01 15:54:04 +03:00
|
|
|
$result = $container->get('nelmio_api_doc.formatter.simple_formatter')->format($data);
|
2015-10-23 10:11:52 +02:00
|
|
|
|
2024-10-01 17:26:49 +03:00
|
|
|
$suffix = '_1';
|
2024-10-01 15:54:04 +03:00
|
|
|
$expected = require __DIR__ . '/testFormat-result' . $suffix . '.php';
|
2015-10-23 10:11:52 +02:00
|
|
|
|
2024-10-01 17:18:04 +03:00
|
|
|
$this->assertEquals($expected, $result, 'file ' . __DIR__ . '/testFormat-result' . $suffix . '.php');
|
2015-10-23 10:11:52 +02:00
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testFormatOne(): void
|
2012-04-13 15:00:46 +02:00
|
|
|
{
|
|
|
|
$container = $this->getContainer();
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
2012-07-20 00:58:58 +02:00
|
|
|
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::indexAction', 'test_route_1');
|
2024-10-01 15:54:04 +03:00
|
|
|
$result = $container->get('nelmio_api_doc.formatter.simple_formatter')->formatOne($annotation);
|
2012-04-13 15:00:46 +02:00
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
$expected = [
|
2012-04-13 15:00:46 +02:00
|
|
|
'method' => 'GET',
|
2012-08-10 11:38:01 +02:00
|
|
|
'uri' => '/tests.{_format}',
|
2024-10-01 15:54:04 +03:00
|
|
|
'filters' => [
|
|
|
|
'a' => [
|
2012-04-13 15:00:46 +02:00
|
|
|
'dataType' => 'integer',
|
2024-10-01 15:54:04 +03:00
|
|
|
],
|
|
|
|
'b' => [
|
2012-04-13 15:00:46 +02:00
|
|
|
'dataType' => 'string',
|
2024-10-01 15:54:04 +03:00
|
|
|
'arbitrary' => [
|
2012-04-13 15:00:46 +02:00
|
|
|
'arg1',
|
|
|
|
'arg2',
|
2024-10-01 15:54:04 +03:00
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
2012-08-10 11:38:01 +02:00
|
|
|
'description' => 'index action',
|
2024-10-01 15:54:04 +03:00
|
|
|
'requirements' => [
|
|
|
|
'_format' => ['dataType' => '', 'description' => '', 'requirement' => ''],
|
|
|
|
],
|
2013-06-24 14:27:22 +02:00
|
|
|
'deprecated' => false,
|
2024-10-01 16:11:23 +03:00
|
|
|
'scope' => null,
|
2024-10-01 15:54:04 +03:00
|
|
|
];
|
2012-04-13 15:00:46 +02:00
|
|
|
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
2012-04-13 14:11:54 +02:00
|
|
|
}
|