NelmioApiDocBundle/Tests/Formatter/SimpleFormatterTest.php

71 lines
2.3 KiB
PHP
Raw Normal View History

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
{
$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();
restore_error_handler();
2024-10-01 15:54:04 +03:00
$result = $container->get('nelmio_api_doc.formatter.simple_formatter')->format($data);
$suffix = class_exists('Dunglas\ApiBundle\DunglasApiBundle') ? '' : '_1';
2024-10-01 15:54:04 +03:00
$expected = require __DIR__ . '/testFormat-result' . $suffix . '.php';
2024-10-01 17:18:04 +03:00
$this->assertEquals($expected, $result, 'file ' . __DIR__ . '/testFormat-result' . $suffix . '.php');
}
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');
$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',
'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
],
],
],
'description' => 'index action',
2024-10-01 15:54:04 +03:00
'requirements' => [
'_format' => ['dataType' => '', 'description' => '', 'requirement' => ''],
],
'https' => false,
2012-12-26 12:23:28 +01:00
'authentication' => false,
2024-10-01 15:54:04 +03:00
'authenticationRoles' => [],
'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
}