NelmioApiDocBundle/Tests/Formatter/SimpleFormatterTest.php

70 lines
2.2 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
{
public function testFormat()
{
$container = $this->getContainer();
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
set_error_handler(array($this, 'handleDeprecation'));
$data = $extractor->all();
restore_error_handler();
$result = $container->get('nelmio_api_doc.formatter.simple_formatter')->format($data);
2015-11-21 18:30:44 +01:00
$suffix = class_exists('Dunglas\ApiBundle\DunglasApiBundle') ? '' : '-no-dunglas';
$expected = require __DIR__ . '/testFormat-result'.$suffix.'.php';
$this->assertEquals($expected, $result);
}
2012-04-13 15:00:46 +02:00
public function testFormatOne()
{
$container = $this->getContainer();
$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.simple_formatter')->formatOne($annotation);
2012-04-13 15:00:46 +02:00
$expected = array(
'method' => 'GET',
'uri' => '/tests.{_format}',
2012-04-13 15:00:46 +02:00
'filters' => array(
'a' => array(
'dataType' => 'integer',
),
'b' => array(
'dataType' => 'string',
'arbitrary' => array(
'arg1',
'arg2',
),
),
),
'description' => 'index action',
'requirements' => array(
2012-11-17 18:05:05 +01:00
'_format' => array('dataType' => '', 'description' => '', 'requirement' => ''),
),
'https' => false,
2012-12-26 12:23:28 +01:00
'authentication' => false,
'authenticationRoles' => array(),
'deprecated' => false,
2012-04-13 15:00:46 +02:00
);
$this->assertEquals($expected, $result);
}
2012-04-13 14:11:54 +02:00
}