NelmioApiDocBundle/Tests/Formatter/SimpleFormatterTest.php

204 lines
6.7 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');
2012-04-13 15:00:46 +02:00
$data = $extractor->all();
$result = $container->get('nelmio_api_doc.formatter.simple_formatter')->format($data);
2012-04-13 14:11:54 +02:00
$expected = array(
'/tests' =>
array(
0 =>
2012-04-13 15:00:46 +02:00
array(
'method' => 'GET',
'uri' => '/tests',
'requirements' =>
array(
),
'filters' =>
array(
'a' =>
array(
'dataType' => 'integer',
),
'b' =>
array(
'dataType' => 'string',
'arbitrary' =>
array(
0 => 'arg1',
1 => 'arg2',
),
),
),
'description' => 'index action',
),
1 =>
2012-04-13 14:11:54 +02:00
array(
'method' => 'GET',
'uri' => '/tests',
'requirements' =>
array(
),
'filters' =>
array(
'a' =>
array(
2012-04-13 14:11:54 +02:00
'dataType' => 'integer',
),
'b' =>
array(
2012-04-13 14:11:54 +02:00
'dataType' => 'string',
'arbitrary' =>
array(
0 => 'arg1',
1 => 'arg2',
2012-04-13 14:11:54 +02:00
),
),
),
'description' => 'index action',
),
2 =>
array(
'method' => 'POST',
'uri' => '/tests',
'requirements' =>
array(
),
'parameters' =>
array(
'a' =>
array(
'dataType' => 'string',
'required' => true,
'description' => 'A nice description',
),
'b' =>
array(
'dataType' => 'string',
'required' => true,
'description' => '',
),
),
'description' => 'create test',
),
3 =>
2012-04-13 14:11:54 +02:00
array(
'method' => 'POST',
'uri' => '/tests',
'requirements' =>
array(
),
'parameters' =>
array(
'a' =>
array(
2012-04-13 14:11:54 +02:00
'dataType' => 'string',
'required' => true,
2012-04-13 14:20:12 +02:00
'description' => 'A nice description',
2012-04-13 14:11:54 +02:00
),
'b' =>
array(
2012-04-13 14:11:54 +02:00
'dataType' => 'string',
'required' => true,
2012-04-13 14:20:12 +02:00
'description' => '',
2012-04-13 14:11:54 +02:00
),
),
'description' => 'create test',
),
),
'others' =>
array(
0 =>
array(
'method' => 'ANY',
'uri' => '/any',
'requirements' =>
array(
),
'description' => 'Action without HTTP verb',
),
1 =>
array(
'method' => 'ANY',
'uri' => '/any/{foo}',
'requirements' =>
array(
'foo' => array('type' => '', 'description' => '', 'value' => ''),
),
'description' => 'Action without HTTP verb',
),
2012-04-19 17:05:59 +02:00
2 =>
array(
'method' => 'ANY',
'uri' => '/my-commented/{id}',
2012-04-19 17:05:59 +02:00
'requirements' =>
array(
'id' => array('type' => 'int', 'description' => 'A nice comment', 'value' => '')
2012-04-19 17:05:59 +02:00
),
'description' => 'This method is useful to test if the getDocComment works. And, it supports multilines until the first \'@\' char.',
2012-04-19 17:05:59 +02:00
),
3 =>
array(
'method' => 'ANY',
'uri' => '/yet-another/{id}',
'requirements' =>
array(
'id' => array('type' => '', 'description' => '', 'value' => '\d+')
),
),
),
2012-04-13 14:11:54 +02:00
);
$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');
$data = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::indexAction', 'test_route_1');
$result = $container->get('nelmio_api_doc.formatter.simple_formatter')->formatOne($data['annotation'], $data['route']);
$expected = array(
'method' => 'GET',
'uri' => '/tests',
'requirements' => array(),
'filters' => array(
'a' => array(
'dataType' => 'integer',
),
'b' => array(
'dataType' => 'string',
'arbitrary' => array(
'arg1',
'arg2',
),
),
),
'description' => 'index action'
);
$this->assertEquals($expected, $result);
}
2012-04-13 14:11:54 +02:00
}