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\Extractor;
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
use Nelmio\ApiDocBundle\Attribute\ApiDoc;
|
2014-09-29 16:18:11 +02:00
|
|
|
use Nelmio\ApiDocBundle\Extractor\ApiDocExtractor;
|
2012-04-13 14:22:07 +02:00
|
|
|
use Nelmio\ApiDocBundle\Tests\WebTestCase;
|
2012-04-13 14:11:54 +02:00
|
|
|
|
|
|
|
class ApiDocExtractorTest extends WebTestCase
|
|
|
|
{
|
2024-10-01 18:33:15 +03:00
|
|
|
private static $ROUTES_QUANTITY_DEFAULT = 26; // Routes in the default view
|
2024-06-18 00:19:53 +03:00
|
|
|
private static $ROUTES_QUANTITY_PREMIUM = 5; // Routes in the premium view
|
2024-10-01 15:54:04 +03:00
|
|
|
private static $ROUTES_QUANTITY_TEST = 2; // Routes in the test view
|
2015-05-16 12:37:28 +02:00
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testAll(): void
|
2012-04-13 14:11:54 +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']);
|
2012-04-13 14:11:54 +02:00
|
|
|
$data = $extractor->all();
|
2013-02-11 14:42:17 +01:00
|
|
|
restore_error_handler();
|
2012-04-13 14:11:54 +02:00
|
|
|
|
2012-04-13 14:42:28 +02:00
|
|
|
$this->assertTrue(is_array($data));
|
2015-05-16 12:37:28 +02:00
|
|
|
$this->assertCount(self::$ROUTES_QUANTITY_DEFAULT, $data);
|
2012-04-13 14:42:28 +02:00
|
|
|
|
2015-07-21 17:13:40 +07:00
|
|
|
$cacheFile = $container->getParameter('kernel.cache_dir') . '/api-doc.cache.' . ApiDoc::DEFAULT_VIEW;
|
2014-07-21 10:26:06 -07:00
|
|
|
$this->assertFileExists($cacheFile);
|
2015-07-21 17:13:40 +07:00
|
|
|
$this->assertStringEqualsFile($cacheFile, serialize($data));
|
2014-07-21 10:26:06 -07:00
|
|
|
|
2015-03-15 23:48:57 +01:00
|
|
|
foreach ($data as $key => $d) {
|
2012-04-13 14:42:28 +02:00
|
|
|
$this->assertTrue(is_array($d));
|
|
|
|
$this->assertArrayHasKey('annotation', $d);
|
|
|
|
$this->assertArrayHasKey('resource', $d);
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
$this->assertInstanceOf('Nelmio\ApiDocBundle\Attribute\ApiDoc', $d['annotation']);
|
2012-07-20 00:58:58 +02:00
|
|
|
$this->assertInstanceOf('Symfony\Component\Routing\Route', $d['annotation']->getRoute());
|
2012-04-13 14:42:28 +02:00
|
|
|
$this->assertNotNull($d['resource']);
|
|
|
|
}
|
2012-04-13 14:11:54 +02:00
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testRouteVersionChecking(): void
|
2019-04-24 12:55:08 +03:00
|
|
|
{
|
|
|
|
$container = $this->getContainer();
|
|
|
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
|
|
|
$data = $extractor->allForVersion('1.5');
|
|
|
|
$this->assertTrue(is_array($data));
|
|
|
|
$this->assertCount(self::$ROUTES_QUANTITY_DEFAULT, $data);
|
|
|
|
$data = $extractor->allForVersion('1.4');
|
|
|
|
$this->assertTrue(is_array($data));
|
|
|
|
$this->assertCount(self::$ROUTES_QUANTITY_DEFAULT - 1, $data);
|
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testGet(): void
|
2012-04-13 14:11:54 +02:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$container = $this->getContainer();
|
|
|
|
$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 23:00:23 +03:00
|
|
|
$this->assertInstanceOf('Nelmio\ApiDocBundle\Attribute\ApiDoc', $annotation);
|
2012-04-13 14:11:54 +02:00
|
|
|
|
2012-07-20 00:58:58 +02:00
|
|
|
$this->assertTrue($annotation->isResource());
|
|
|
|
$this->assertEquals('index action', $annotation->getDescription());
|
2012-04-13 14:42:28 +02:00
|
|
|
|
2012-07-20 00:58:58 +02:00
|
|
|
$array = $annotation->toArray();
|
|
|
|
$this->assertTrue(is_array($array['filters']));
|
2012-07-23 15:44:37 -04:00
|
|
|
$this->assertNull($annotation->getInput());
|
2012-04-14 10:11:52 +02:00
|
|
|
|
2024-06-18 00:19:53 +03:00
|
|
|
$annotation2 = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::indexAction', 'test_service_route_1');
|
2012-07-20 00:58:58 +02:00
|
|
|
$annotation2->getRoute()
|
|
|
|
->setDefault('_controller', $annotation->getRoute()->getDefault('_controller'))
|
2024-10-01 15:54:04 +03:00
|
|
|
->compile() // compile as we changed a default value
|
|
|
|
;
|
2012-07-20 00:58:58 +02:00
|
|
|
$this->assertEquals($annotation, $annotation2);
|
2012-04-13 14:42:28 +02:00
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testGetWithBadController(): void
|
2012-04-13 14:42:28 +02:00
|
|
|
{
|
|
|
|
$container = $this->getContainer();
|
|
|
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
|
|
|
$data = $extractor->get('Undefined\Controller::indexAction', 'test_route_1');
|
|
|
|
|
|
|
|
$this->assertNull($data);
|
2012-04-14 10:11:52 +02:00
|
|
|
|
|
|
|
$data = $extractor->get('undefined_service:index', 'test_service_route_1');
|
|
|
|
|
|
|
|
$this->assertNull($data);
|
2012-04-13 14:42:28 +02:00
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testGetWithBadRoute(): void
|
2012-04-13 14:42:28 +02:00
|
|
|
{
|
|
|
|
$container = $this->getContainer();
|
|
|
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
|
|
|
$data = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::indexAction', 'invalid_route');
|
|
|
|
|
|
|
|
$this->assertNull($data);
|
2012-04-14 10:11:52 +02:00
|
|
|
|
2014-03-27 19:49:59 +00:00
|
|
|
$data = $extractor->get('nelmio.test.controller:indexAction', 'invalid_route');
|
2012-04-14 10:11:52 +02:00
|
|
|
|
|
|
|
$this->assertNull($data);
|
2012-04-13 14:42:28 +02:00
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testGetWithInvalidPath(): void
|
2012-04-13 14:42:28 +02:00
|
|
|
{
|
|
|
|
$container = $this->getContainer();
|
|
|
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
|
|
|
$data = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController', 'test_route_1');
|
|
|
|
|
|
|
|
$this->assertNull($data);
|
2012-04-14 10:11:52 +02:00
|
|
|
|
2014-03-27 19:49:59 +00:00
|
|
|
$data = $extractor->get('nelmio.test.controller', 'test_service_route_1');
|
2012-04-14 10:11:52 +02:00
|
|
|
|
|
|
|
$this->assertNull($data);
|
2012-04-13 14:42:28 +02:00
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testGetWithMethodWithoutApiDocAnnotation(): void
|
2012-04-13 14:42:28 +02:00
|
|
|
{
|
|
|
|
$container = $this->getContainer();
|
|
|
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
|
|
|
$data = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::anotherAction', 'test_route_3');
|
|
|
|
|
|
|
|
$this->assertNull($data);
|
2012-04-14 10:11:52 +02:00
|
|
|
|
2014-03-27 19:49:59 +00:00
|
|
|
$data = $extractor->get('nelmio.test.controller:anotherAction', 'test_service_route_1');
|
2012-04-14 10:11:52 +02:00
|
|
|
|
|
|
|
$this->assertNull($data);
|
2012-04-13 14:11:54 +02:00
|
|
|
}
|
2012-04-19 16:23:26 +02:00
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testGetWithDocComment(): void
|
2012-04-19 16:23:26 +02:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$container = $this->getContainer();
|
|
|
|
$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::myCommentedAction', 'test_route_5');
|
2012-04-19 16:23:26 +02:00
|
|
|
|
2012-07-20 00:58:58 +02:00
|
|
|
$this->assertNotNull($annotation);
|
2012-04-19 17:17:36 +02:00
|
|
|
$this->assertEquals(
|
2024-10-01 15:54:04 +03:00
|
|
|
'This method is useful to test if the getDocComment works.',
|
2012-07-20 00:58:58 +02:00
|
|
|
$annotation->getDescription()
|
2012-04-19 17:17:36 +02:00
|
|
|
);
|
2013-04-24 22:28:46 +02:00
|
|
|
|
2013-05-03 14:37:52 +01:00
|
|
|
$data = $annotation->toArray();
|
|
|
|
$this->assertEquals(
|
|
|
|
4,
|
|
|
|
count($data['requirements'])
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
'The param type',
|
|
|
|
$data['requirements']['paramType']['description']
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
'The param id',
|
|
|
|
$data['requirements']['param']['description']
|
|
|
|
);
|
2012-04-19 16:23:26 +02:00
|
|
|
}
|
2012-12-26 12:23:28 +01:00
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testGetWithDeprecated(): void
|
2013-04-16 19:40:29 +01:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$container = $this->getContainer();
|
|
|
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
2013-04-16 19:59:54 +01:00
|
|
|
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::DeprecatedAction', 'test_route_14');
|
2013-04-16 19:40:29 +01:00
|
|
|
|
|
|
|
$this->assertNotNull($annotation);
|
|
|
|
$this->assertTrue(
|
|
|
|
$annotation->getDeprecated()
|
|
|
|
);
|
|
|
|
}
|
2013-12-05 00:05:47 +01:00
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testOutputWithSelectedParsers(): void
|
2013-12-05 00:05:47 +01:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$container = $this->getContainer();
|
|
|
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
2013-12-05 00:05:47 +01:00
|
|
|
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zReturnSelectedParsersOutputAction', 'test_route_19');
|
|
|
|
|
|
|
|
$this->assertNotNull($annotation);
|
|
|
|
$output = $annotation->getOutput();
|
2014-06-17 17:05:00 -07:00
|
|
|
|
2013-12-05 00:05:47 +01:00
|
|
|
$parsers = $output['parsers'];
|
|
|
|
$this->assertEquals(
|
2024-10-01 15:54:04 +03:00
|
|
|
'Nelmio\\ApiDocBundle\\Parser\\JmsMetadataParser',
|
2013-12-05 00:05:47 +01:00
|
|
|
$parsers[0]
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
2024-10-01 15:54:04 +03:00
|
|
|
'Nelmio\\ApiDocBundle\\Parser\\ValidationParser',
|
2013-12-05 00:05:47 +01:00
|
|
|
$parsers[1]
|
|
|
|
);
|
|
|
|
$this->assertCount(2, $parsers);
|
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testInputWithSelectedParsers(): void
|
2013-12-05 00:05:47 +01:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$container = $this->getContainer();
|
|
|
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
2013-12-05 00:05:47 +01:00
|
|
|
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zReturnSelectedParsersInputAction', 'test_route_20');
|
|
|
|
|
|
|
|
$this->assertNotNull($annotation);
|
|
|
|
$input = $annotation->getInput();
|
|
|
|
$parsers = $input['parsers'];
|
|
|
|
$this->assertEquals(
|
2024-10-01 15:54:04 +03:00
|
|
|
'Nelmio\\ApiDocBundle\\Parser\\FormTypeParser',
|
2013-12-05 00:05:47 +01:00
|
|
|
$parsers[0]
|
|
|
|
);
|
|
|
|
$this->assertCount(1, $parsers);
|
|
|
|
}
|
2014-09-29 16:18:11 +02:00
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testPostRequestDoesRequireParametersWhenMarkedAsSuch(): void
|
2014-09-29 16:18:11 +02:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$container = $this->getContainer();
|
2014-09-29 16:18:11 +02:00
|
|
|
/** @var ApiDocExtractor $extractor */
|
2024-10-01 15:54:04 +03:00
|
|
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
2014-09-29 16:18:11 +02:00
|
|
|
/** @var ApiDoc $annotation */
|
|
|
|
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::requiredParametersAction', 'test_required_parameters');
|
|
|
|
|
|
|
|
$parameters = $annotation->getParameters();
|
|
|
|
$this->assertTrue($parameters['required_field']['required']);
|
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testPatchRequestDoesNeverRequireParameters(): void
|
2014-09-29 16:18:11 +02:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$container = $this->getContainer();
|
2014-09-29 16:18:11 +02:00
|
|
|
/** @var ApiDocExtractor $extractor */
|
2024-10-01 15:54:04 +03:00
|
|
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
2014-09-29 16:18:11 +02:00
|
|
|
/** @var ApiDoc $annotation */
|
2016-01-26 14:20:49 +01:00
|
|
|
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::requiredParametersAction', 'test_patch_disables_required_parameters');
|
2014-09-29 16:18:11 +02:00
|
|
|
|
|
|
|
$parameters = $annotation->getParameters();
|
|
|
|
$this->assertFalse($parameters['required_field']['required']);
|
|
|
|
}
|
2014-11-22 22:27:13 +01:00
|
|
|
|
2024-10-01 17:26:49 +03:00
|
|
|
public static function dataProviderForViews(): array
|
2014-11-22 22:27:13 +01:00
|
|
|
{
|
2015-05-16 12:37:28 +02:00
|
|
|
$offset = 0;
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
return [
|
|
|
|
['default', self::$ROUTES_QUANTITY_DEFAULT + $offset],
|
|
|
|
['premium', self::$ROUTES_QUANTITY_PREMIUM + $offset],
|
|
|
|
['test', self::$ROUTES_QUANTITY_TEST + $offset],
|
|
|
|
['foobar', $offset],
|
|
|
|
['', $offset],
|
|
|
|
[null, $offset],
|
|
|
|
];
|
2014-11-22 22:27:13 +01:00
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testViewNamedTest(): void
|
2014-11-22 22:27:13 +01: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']);
|
2014-11-22 22:27:13 +01:00
|
|
|
$data = $extractor->all('test');
|
|
|
|
restore_error_handler();
|
|
|
|
|
|
|
|
$this->assertTrue(is_array($data));
|
2015-05-16 12:17:59 +02:00
|
|
|
$this->assertCount(self::$ROUTES_QUANTITY_TEST, $data);
|
2014-11-22 22:27:13 +01:00
|
|
|
|
|
|
|
$a1 = $data[0]['annotation'];
|
2015-05-16 12:17:59 +02:00
|
|
|
$this->assertCount(3, $a1->getViews());
|
2014-11-22 22:27:13 +01:00
|
|
|
$this->assertEquals('List resources.', $a1->getDescription());
|
|
|
|
|
|
|
|
$a2 = $data[1]['annotation'];
|
2015-05-16 12:17:59 +02:00
|
|
|
$this->assertCount(2, $a2->getViews());
|
2014-11-22 22:27:13 +01:00
|
|
|
$this->assertEquals('create another test', $a2->getDescription());
|
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testViewNamedPremium(): void
|
2014-11-22 22:27:13 +01: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']);
|
2014-11-22 22:27:13 +01:00
|
|
|
$data = $extractor->all('premium');
|
|
|
|
restore_error_handler();
|
|
|
|
|
|
|
|
$this->assertTrue(is_array($data));
|
2015-05-16 12:17:59 +02:00
|
|
|
$this->assertCount(self::$ROUTES_QUANTITY_PREMIUM, $data);
|
2014-11-22 22:27:13 +01:00
|
|
|
|
|
|
|
$a1 = $data[0]['annotation'];
|
2015-05-16 12:17:59 +02:00
|
|
|
$this->assertCount(2, $a1->getViews());
|
2014-11-22 22:27:13 +01:00
|
|
|
$this->assertEquals('List another resource.', $a1->getDescription());
|
|
|
|
|
|
|
|
$a2 = $data[1]['annotation'];
|
2015-05-16 12:17:59 +02:00
|
|
|
$this->assertCount(3, $a2->getViews());
|
2014-11-22 22:27:13 +01:00
|
|
|
$this->assertEquals('List resources.', $a2->getDescription());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-16 12:37:28 +02:00
|
|
|
* @dataProvider dataProviderForViews
|
2014-11-22 22:27:13 +01:00
|
|
|
*/
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testForViews($view, $count): void
|
2014-11-22 22:27:13 +01: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']);
|
2015-05-16 12:17:59 +02:00
|
|
|
$data = $extractor->all($view);
|
2014-11-22 22:27:13 +01:00
|
|
|
restore_error_handler();
|
|
|
|
|
|
|
|
$this->assertTrue(is_array($data));
|
|
|
|
$this->assertCount($count, $data);
|
|
|
|
}
|
2015-10-27 13:36:07 +01:00
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testOverrideJmsAnnotationWithApiDocParameters(): void
|
2015-10-27 13:36:07 +01:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$container = $this->getContainer();
|
|
|
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
2015-10-27 13:36:07 +01:00
|
|
|
$annotation = $extractor->get(
|
|
|
|
'Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::overrideJmsAnnotationWithApiDocParametersAction',
|
|
|
|
'test_route_27'
|
|
|
|
);
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
$this->assertInstanceOf('Nelmio\ApiDocBundle\Attribute\ApiDoc', $annotation);
|
2015-10-27 13:36:07 +01:00
|
|
|
|
|
|
|
$array = $annotation->toArray();
|
|
|
|
$this->assertTrue(is_array($array['parameters']));
|
|
|
|
|
|
|
|
$this->assertEquals('string', $array['parameters']['foo']['dataType']);
|
|
|
|
$this->assertEquals('DateTime', $array['parameters']['bar']['dataType']);
|
|
|
|
|
|
|
|
$this->assertEquals('integer', $array['parameters']['number']['dataType']);
|
|
|
|
$this->assertEquals('string', $array['parameters']['number']['actualType']);
|
2024-10-01 15:54:04 +03:00
|
|
|
$this->assertNull($array['parameters']['number']['subType']);
|
|
|
|
$this->assertTrue($array['parameters']['number']['required']);
|
2015-10-27 13:36:07 +01:00
|
|
|
$this->assertEquals('This is the new description', $array['parameters']['number']['description']);
|
2024-10-01 15:54:04 +03:00
|
|
|
$this->assertFalse($array['parameters']['number']['readonly']);
|
2015-10-27 13:36:07 +01:00
|
|
|
$this->assertEquals('v3.0', $array['parameters']['number']['sinceVersion']);
|
|
|
|
$this->assertEquals('v4.0', $array['parameters']['number']['untilVersion']);
|
|
|
|
|
|
|
|
$this->assertEquals('object (ArrayCollection)', $array['parameters']['arr']['dataType']);
|
|
|
|
|
|
|
|
$this->assertEquals('object (JmsNested)', $array['parameters']['nested']['dataType']);
|
|
|
|
$this->assertEquals('integer', $array['parameters']['nested']['children']['bar']['dataType']);
|
|
|
|
$this->assertEquals('d+', $array['parameters']['nested']['children']['bar']['format']);
|
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testJmsAnnotation(): void
|
2015-10-27 13:36:07 +01:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$container = $this->getContainer();
|
|
|
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
2015-10-27 13:36:07 +01:00
|
|
|
$annotation = $extractor->get(
|
|
|
|
'Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::defaultJmsAnnotations',
|
|
|
|
'test_route_27'
|
|
|
|
);
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
$this->assertInstanceOf('Nelmio\ApiDocBundle\Attribute\ApiDoc', $annotation);
|
2015-10-27 13:36:07 +01:00
|
|
|
|
|
|
|
$array = $annotation->toArray();
|
|
|
|
$this->assertTrue(is_array($array['parameters']));
|
|
|
|
|
|
|
|
$this->assertEquals('string', $array['parameters']['foo']['dataType']);
|
|
|
|
$this->assertEquals('DateTime', $array['parameters']['bar']['dataType']);
|
|
|
|
|
|
|
|
$this->assertEquals('double', $array['parameters']['number']['dataType']);
|
|
|
|
$this->assertEquals('float', $array['parameters']['number']['actualType']);
|
2024-10-01 15:54:04 +03:00
|
|
|
$this->assertNull($array['parameters']['number']['subType']);
|
|
|
|
$this->assertFalse($array['parameters']['number']['required']);
|
2015-10-27 13:36:07 +01:00
|
|
|
$this->assertEquals('', $array['parameters']['number']['description']);
|
2024-10-01 15:54:04 +03:00
|
|
|
$this->assertFalse($array['parameters']['number']['readonly']);
|
|
|
|
$this->assertNull($array['parameters']['number']['sinceVersion']);
|
|
|
|
$this->assertNull($array['parameters']['number']['untilVersion']);
|
2015-10-27 13:36:07 +01:00
|
|
|
|
|
|
|
$this->assertEquals('array', $array['parameters']['arr']['dataType']);
|
|
|
|
|
|
|
|
$this->assertEquals('object (JmsNested)', $array['parameters']['nested']['dataType']);
|
|
|
|
$this->assertEquals('string', $array['parameters']['nested']['children']['bar']['dataType']);
|
|
|
|
}
|
2015-11-09 22:22:00 +01:00
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testMergeParametersDefaultKeyNotExistingInFirstArray(): void
|
2015-11-09 22:22:00 +01:00
|
|
|
{
|
|
|
|
$container = $this->getContainer();
|
|
|
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
|
|
|
|
|
|
|
$mergeMethod = new \ReflectionMethod('Nelmio\ApiDocBundle\Extractor\ApiDocExtractor', 'mergeParameters');
|
|
|
|
$mergeMethod->setAccessible(true);
|
|
|
|
|
|
|
|
$p1 = [
|
|
|
|
'myPropName' => [
|
2024-10-01 15:54:04 +03:00
|
|
|
'dataType' => 'string',
|
|
|
|
'actualType' => 'string',
|
|
|
|
'subType' => null,
|
|
|
|
'required' => null,
|
2015-11-09 22:22:00 +01:00
|
|
|
'description' => null,
|
2024-10-01 15:54:04 +03:00
|
|
|
'readonly' => null,
|
|
|
|
],
|
2015-11-09 22:22:00 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
$p2 = [
|
|
|
|
'myPropName' => [
|
2024-10-01 15:54:04 +03:00
|
|
|
'dataType' => 'string',
|
|
|
|
'actualType' => 'string',
|
|
|
|
'subType' => null,
|
|
|
|
'required' => null,
|
2015-11-09 22:22:00 +01:00
|
|
|
'description' => null,
|
2024-10-01 15:54:04 +03:00
|
|
|
'readonly' => null,
|
|
|
|
'default' => '',
|
|
|
|
],
|
2015-11-09 22:22:00 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
$mergedResult = $mergeMethod->invokeArgs($extractor, [$p1, $p2]);
|
|
|
|
$this->assertEquals($p2, $mergedResult);
|
|
|
|
}
|
2012-04-13 14:11:54 +02:00
|
|
|
}
|