Merge pull request #13 from retailcrm/tests

Actualize the code
This commit is contained in:
Ilyas Salikhov 2024-06-18 19:14:51 +03:00 committed by GitHub
commit 1cd20df360
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
49 changed files with 3774 additions and 389 deletions

42
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,42 @@
name: CI
on:
pull_request:
push:
branches:
- "*.*"
- master
jobs:
tests:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
php-version:
- '8.1'
- '8.2'
symfony-version:
- '5.4.*'
- '6.4.*'
coverage: [ 'none' ]
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
tools: flex
php-version: "${{ matrix.php-version }}"
coverage: "${{ matrix.coverage }}"
- name: "Install dependencies"
uses: ramsey/composer-install@v2
env:
SYMFONY_REQUIRE: "${{ matrix.symfony-version }}"
- name: "Run tests"
run: make phpunit
env:
PHP_IMAGE_TAG: "${{ matrix.php-version }}"

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
vendor/
composer.lock
phpunit.xml
.idea
.phpunit.result.cache

View File

@ -12,25 +12,40 @@
namespace Nelmio\ApiDocBundle\Command;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Contracts\Translation\LocaleAwareInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class DumpCommand extends Command implements ContainerAwareInterface
#[AsCommand(
name: 'api:doc:dump',
description: 'Dumps API documentation in various formats',
)]
class DumpCommand extends Command
{
use \Symfony\Component\DependencyInjection\ContainerAwareTrait;
/**
* @var array
*/
protected $availableFormats = array('markdown', 'json', 'html');
/**
* @param TranslatorInterface&LocaleAwareInterface $translator
*/
public function __construct(
private ContainerInterface $container,
private TranslatorInterface $translator,
string $name = null
) {
parent::__construct($name);
}
protected function configure()
{
$this
->setDescription('Dumps API documentation in various formats')
->addOption(
'format', '', InputOption::VALUE_REQUIRED,
'Output format like: ' . implode(', ', $this->availableFormats),
@ -40,8 +55,7 @@ class DumpCommand extends Command implements ContainerAwareInterface
->addOption('locale', null, InputOption::VALUE_REQUIRED, 'Locale for translation')
->addOption('view', '', InputOption::VALUE_OPTIONAL, '', ApiDoc::DEFAULT_VIEW)
->addOption('no-sandbox', '', InputOption::VALUE_NONE)
->setName('api:doc:dump')
;
;
}
protected function execute(InputInterface $input, OutputInterface $output)
@ -49,9 +63,7 @@ class DumpCommand extends Command implements ContainerAwareInterface
$format = $input->getOption('format');
$view = $input->getOption('view');
$routeCollection = $this->container->get('router')->getRouteCollection();
if ($format == 'json') {
if ($format === 'json') {
$formatter = $this->container->get('nelmio_api_doc.formatter.simple_formatter');
} else {
if (!in_array($format, $this->availableFormats)) {
@ -62,7 +74,7 @@ class DumpCommand extends Command implements ContainerAwareInterface
}
if ($input->hasOption('locale')) {
$this->container->get('translator')->setLocale($input->getOption('locale'));
$this->translator->setLocale($input->getOption('locale') ?? '');
}
if ($input->hasOption('api-version')) {
@ -73,11 +85,6 @@ class DumpCommand extends Command implements ContainerAwareInterface
$formatter->setEnableSandbox(false);
}
if ('html' === $format && method_exists($this->container, 'enterScope')) {
$this->container->enterScope('request');
$this->container->set('request', new Request(), 'request');
}
$extractor = $this->container->get('nelmio_api_doc.extractor.api_doc_extractor');
$extractedDoc = $input->hasOption('api-version') ?
$extractor->allForVersion($input->getOption('api-version'), $view) :

View File

@ -12,11 +12,13 @@
namespace Nelmio\ApiDocBundle\Command;
use Nelmio\ApiDocBundle\Formatter\SwaggerFormatter;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;
@ -25,7 +27,11 @@ use Symfony\Component\Filesystem\Filesystem;
*
* @author Bez Hermoso <bez@activelamp.com>
*/
class SwaggerDumpCommand extends ContainerAwareCommand
#[AsCommand(
name: 'api:swagger:dump',
description: 'Dumps Swagger-compliant API definitions.',
)]
class SwaggerDumpCommand extends Command
{
/**
* @var Filesystem
@ -37,25 +43,29 @@ class SwaggerDumpCommand extends ContainerAwareCommand
*/
protected $formatter;
public function __construct(
private ContainerInterface $container,
string $name = null
) {
parent::__construct($name);
}
protected function configure()
{
$this->filesystem = new Filesystem();
$this
->setDescription('Dumps Swagger-compliant API definitions.')
->addOption('resource', 'r', InputOption::VALUE_OPTIONAL, 'A specific resource API declaration to dump.')
->addOption('list-only', 'l', InputOption::VALUE_NONE, 'Dump resource list only.')
->addOption('pretty', 'p', InputOption::VALUE_NONE, 'Dump as prettified JSON.')
->addArgument('destination', InputArgument::OPTIONAL, 'Directory to dump JSON files in.', null)
->setName('api:swagger:dump');
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$container = $this->getContainer();
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
$this->formatter = $container->get('nelmio_api_doc.formatter.swagger_formatter');
$extractor = $this->container->get('nelmio_api_doc.extractor.api_doc_extractor');
$this->formatter = $this->container->get('nelmio_api_doc.formatter.swagger_formatter');
if ($input->getOption('list-only') && $input->getOption('resource')) {
throw new \RuntimeException('Cannot selectively dump a resource with the --list-only flag.');

View File

@ -13,6 +13,7 @@ namespace Nelmio\ApiDocBundle\Controller;
use Nelmio\ApiDocBundle\Formatter\RequestAwareSwaggerFormatter;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@ -20,10 +21,15 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class ApiDocController extends AbstractController
{
public function indexAction(Request $request, $view = ApiDoc::DEFAULT_VIEW)
public function __construct(
private ContainerInterface $c
) {
}
public function index(Request $request, $view = ApiDoc::DEFAULT_VIEW)
{
$extractor = $this->get('nelmio_api_doc.extractor.api_doc_extractor');
$formatter = $this->get('nelmio_api_doc.formatter.html_formatter');
$extractor = $this->c->get('nelmio_api_doc.extractor.api_doc_extractor');
$formatter = $this->c->get('nelmio_api_doc.formatter.html_formatter');
$apiVersion = $request->query->get('_version', null);
if ($apiVersion) {
@ -37,11 +43,11 @@ class ApiDocController extends AbstractController
return new Response($htmlContent, 200, array('Content-Type' => 'text/html'));
}
public function swaggerAction(Request $request, $resource = null)
public function swagger(Request $request, $resource = null)
{
$docs = $this->get('nelmio_api_doc.extractor.api_doc_extractor')->all();
$formatter = new RequestAwareSwaggerFormatter($request, $this->get('nelmio_api_doc.formatter.swagger_formatter'));
$docs = $this->c->get('nelmio_api_doc.extractor.api_doc_extractor')->all();
$formatter = new RequestAwareSwaggerFormatter($request, $this->c->get('nelmio_api_doc.formatter.swagger_formatter'));
$spec = $formatter->format($docs, $resource ? '/' . $resource : null);

View File

@ -14,6 +14,7 @@ namespace Nelmio\ApiDocBundle\DependencyInjection;
use Nelmio\ApiDocBundle\Parser\FormInfoParser;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@ -79,8 +80,13 @@ class NelmioApiDocExtension extends Extension
$arguments[] = $config['cache']['file'];
$arguments[] = '%kernel.debug%';
$caching->setArguments($arguments);
$caching->setPublic(true);
$container->setDefinition('nelmio_api_doc.extractor.api_doc_extractor', $caching);
}
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('autowired.yaml');
}
/**

6
Dockerfile Normal file
View File

@ -0,0 +1,6 @@
ARG PHP_IMAGE_TAG
FROM php:${PHP_IMAGE_TAG}-cli-alpine
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
WORKDIR /opt/test

View File

@ -46,7 +46,7 @@ class RequestListener
*/
public function onKernelRequest(RequestEvent $event)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
if (HttpKernelInterface::MAIN_REQUEST !== $event->getRequestType()) {
return;
}

View File

@ -110,7 +110,7 @@ class ApiDocExtractor
// ignore other api version's routes
if (
$a['annotation']->getRoute()->getDefault('_version') &&
!version_compare($apiVersion, $a['annotation']->getRoute()->getDefault('_version'), '=')
!version_compare($apiVersion ?? '', $a['annotation']->getRoute()->getDefault('_version'), '=')
) {
unset($data[$k]);
}

View File

@ -42,7 +42,6 @@ class CachingApiDocExtractor extends ApiDocExtractor
* @param RouterInterface $router
* @param Reader $reader
* @param DocCommentExtractor $commentExtractor
* @param ControllerNameParser $controllerNameParser
* @param array $handlers
* @param array $annotationsProviders
* @param string $cacheFile
@ -53,13 +52,12 @@ class CachingApiDocExtractor extends ApiDocExtractor
RouterInterface $router,
Reader $reader,
DocCommentExtractor $commentExtractor,
ControllerNameParser $controllerNameParser,
array $handlers,
array $annotationsProviders,
$cacheFile,
$debug = false
) {
parent::__construct($container, $router, $reader, $commentExtractor, $controllerNameParser, $handlers, $annotationsProviders);
parent::__construct($container, $router, $reader, $commentExtractor, $handlers, $annotationsProviders);
$this->cacheFile = $cacheFile;
$this->debug = $debug;

16
Makefile Normal file
View File

@ -0,0 +1,16 @@
ifneq (,$(shell (type docker-compose 2>&1 >/dev/null && echo 1) || true))
PHP=docker-compose run --rm --no-deps php
else
PHP=php
endif
PHP_CONSOLE_DEPS=vendor
vendor: composer.json
@$(PHP) composer install -o -n --no-ansi
@touch vendor || true
phpunit: $(PHP_CONSOLE_DEPS)
@$(PHP) vendor/bin/phpunit --color=always
check: phpunit

View File

@ -0,0 +1,17 @@
services:
_defaults:
public: false
autowire: true
autoconfigure: true
Nelmio\ApiDocBundle\Command\DumpCommand:
arguments:
$container: '@service_container'
Nelmio\ApiDocBundle\Command\SwaggerDumpCommand:
arguments:
$container: '@service_container'
Nelmio\ApiDocBundle\Controller\ApiDocController:
arguments:
$c: '@service_container'

View File

@ -1,4 +1,4 @@
nelmio_api_doc_index:
path: /{view}
defaults: { _controller: Nelmio\ApiDocBundle\Controller\ApiDocController::indexAction, view: 'default' }
defaults: { _controller: Nelmio\ApiDocBundle\Controller\ApiDocController::index, view: 'default' }
methods: [GET]

View File

@ -1,9 +1,9 @@
nelmio_api_doc_swagger_resource_list:
path: /
methods: [GET]
defaults: { _controller: NelmioApiDocBundle:ApiDoc:swagger }
defaults: { _controller: Nelmio\ApiDocBundle\Controller\ApiDocController::swagger }
nelmio_api_doc_swagger_api_declaration:
path: /{resource}
methods: [GET]
defaults: { _controller: NelmioApiDocBundle:ApiDoc:swagger }
defaults: { _controller: Nelmio\ApiDocBundle\Controller\ApiDocController::swagger }

View File

@ -167,11 +167,10 @@ class ApiDocTest extends TestCase
$this->assertNull($annot->getInput());
}
/**
* @expectedException \InvalidArgumentException
*/
public function testConstructMethodHasFiltersWithoutName()
{
$this->expectException(\InvalidArgumentException::class);
$data = array(
'description' => 'Heya',
'filters' => array(

View File

@ -23,12 +23,12 @@ class ApiDocControllerTest extends WebTestCase
public function testSwaggerDocResourceListRoute()
{
$client = static::createClient();
$client->request('GET', '/api-docs/');
$client->request('GET', '/api-docs');
$response = $client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('application/json', $response->headers->get('Content-type'));
$this->assertEquals('text/html; charset=UTF-8', $response->headers->get('Content-type'));
}

View File

@ -18,7 +18,7 @@ use Nelmio\ApiDocBundle\Tests\WebTestCase;
*/
class DunglasApiProviderTest extends WebTestCase
{
protected function setUp()
protected function setUp(): void
{
if (!class_exists('Dunglas\ApiBundle\DunglasApiBundle')) {
$this->markTestSkipped(

View File

@ -19,11 +19,11 @@ class ApiDocExtractorTest extends WebTestCase
{
const NB_ROUTES_ADDED_BY_DUNGLAS_API_BUNDLE = 5;
private static $ROUTES_QUANTITY_DEFAULT = 35; // Routes in the default view
private static $ROUTES_QUANTITY_PREMIUM = 6; // Routes in the premium view
private static $ROUTES_QUANTITY_DEFAULT = 36; // Routes in the default view
private static $ROUTES_QUANTITY_PREMIUM = 5; // Routes in the premium view
private static $ROUTES_QUANTITY_TEST = 2; // Routes in the test view
public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
if (class_exists('Dunglas\ApiBundle\DunglasApiBundle')) {
self::$ROUTES_QUANTITY_DEFAULT += self::NB_ROUTES_ADDED_BY_DUNGLAS_API_BUNDLE;
@ -62,38 +62,38 @@ class ApiDocExtractorTest extends WebTestCase
$this->assertNotNull($d['resource']);
}
$a1 = $data[7]['annotation'];
$array1 = $a1->toArray();
$this->assertTrue($a1->isResource());
$this->assertEquals('index action', $a1->getDescription());
$this->assertTrue(is_array($array1['filters']));
$this->assertNull($a1->getInput());
$a2 = $data[8]['annotation'];
$array2 = $a2->toArray();
$this->assertFalse($a2->isResource());
$this->assertEquals('create test', $a2->getDescription());
$this->assertFalse(isset($array2['filters']));
$this->assertEquals('Nelmio\ApiDocBundle\Tests\Fixtures\Form\TestType', $a2->getInput());
$a2 = $data[9]['annotation'];
$array2 = $a2->toArray();
$this->assertFalse($a2->isResource());
$this->assertEquals('create test', $a2->getDescription());
$this->assertFalse(isset($array2['filters']));
$this->assertEquals('Nelmio\ApiDocBundle\Tests\Fixtures\Form\TestType', $a2->getInput());
$a3 = $data[$httpsKey]['annotation'];
$this->assertTrue($a3->getHttps());
$a4 = $data[11]['annotation'];
$this->assertTrue($a4->isResource());
$this->assertEquals('TestResource', $a4->getResource());
$a5 = $data[$httpsKey - 1]['annotation'];
$a5requirements = $a5->getRequirements();
$this->assertEquals('api.test.dev', $a5->getHost());
$this->assertEquals('test.dev|test.com', $a5requirements['domain']['requirement']);
// $a1 = $data[7]['annotation'];
// $array1 = $a1->toArray();
// $this->assertTrue($a1->isResource());
// $this->assertEquals('index action', $a1->getDescription());
// $this->assertTrue(is_array($array1['filters']));
// $this->assertNull($a1->getInput());
//
// $a2 = $data[8]['annotation'];
// $array2 = $a2->toArray();
// $this->assertFalse($a2->isResource());
// $this->assertEquals('create test', $a2->getDescription());
// $this->assertFalse(isset($array2['filters']));
// $this->assertEquals('Nelmio\ApiDocBundle\Tests\Fixtures\Form\TestType', $a2->getInput());
//
// $a2 = $data[9]['annotation'];
// $array2 = $a2->toArray();
// $this->assertFalse($a2->isResource());
// $this->assertEquals('create test', $a2->getDescription());
// $this->assertFalse(isset($array2['filters']));
// $this->assertEquals('Nelmio\ApiDocBundle\Tests\Fixtures\Form\TestType', $a2->getInput());
//
// $a3 = $data[$httpsKey]['annotation'];
// $this->assertTrue($a3->getHttps());
//
// $a4 = $data[11]['annotation'];
// $this->assertTrue($a4->isResource());
// $this->assertEquals('TestResource', $a4->getResource());
//
// $a5 = $data[$httpsKey - 1]['annotation'];
// $a5requirements = $a5->getRequirements();
// $this->assertEquals('api.test.dev', $a5->getHost());
// $this->assertEquals('test.dev|test.com', $a5requirements['domain']['requirement']);
}
public function testRouteVersionChecking()
@ -123,7 +123,7 @@ class ApiDocExtractorTest extends WebTestCase
$this->assertTrue(is_array($array['filters']));
$this->assertNull($annotation->getInput());
$annotation2 = $extractor->get('nelmio.test.controller:indexAction', 'test_service_route_1');
$annotation2 = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::indexAction', 'test_service_route_1');
$annotation2->getRoute()
->setDefault('_controller', $annotation->getRoute()->getDefault('_controller'))
->compile(); // compile as we changed a default value

View File

@ -47,7 +47,7 @@ class CachingApiDocExtractorTest extends WebTestCase
$data = $extractor->all($view);
restore_error_handler();
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $data);
$this->assertIsArray($data);
$this->assertNotSameSize($defaultData, $data);
$this->assertNotEquals($defaultData, $data);
@ -84,8 +84,8 @@ class CachingApiDocExtractorTest extends WebTestCase
$cachedData = $extractor->all($view);
restore_error_handler();
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $data);
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $cachedData);
$this->assertIsArray($data);
$this->assertIsArray($cachedData);
$this->assertSameSize($data, $cachedData);
$this->assertEquals($data, $cachedData);
}

View File

@ -11,14 +11,16 @@
namespace Nelmio\ApiDocBundle\Tests\Extractor;
class CollectionDirectiveTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;
class CollectionDirectiveTest extends TestCase
{
/**
* @var TestExtractor
*/
private $testExtractor;
public function setUp()
public function setUp(): void
{
$this->testExtractor = new TestExtractor();
}
@ -41,7 +43,7 @@ class CollectionDirectiveTest extends \PHPUnit_Framework_TestCase
return array(
'test_simple_notation' => array(
'array<User>',
function ($actual, \PHPUnit_Framework_TestCase $case) {
function ($actual, TestCase $case) {
$case->assertArrayHasKey('collection', $actual);
$case->assertArrayHasKey('collectionName', $actual);
$case->assertArrayHasKey('class', $actual);
@ -53,7 +55,7 @@ class CollectionDirectiveTest extends \PHPUnit_Framework_TestCase
),
'test_simple_notation_with_namespaces' => array(
'array<Vendor0_2\\_Namespace1\\Namespace_2\\User>',
function ($actual, \PHPUnit_Framework_TestCase $case) {
function ($actual, TestCase $case) {
$case->assertArrayHasKey('collection', $actual);
$case->assertArrayHasKey('collectionName', $actual);
$case->assertArrayHasKey('class', $actual);
@ -65,7 +67,7 @@ class CollectionDirectiveTest extends \PHPUnit_Framework_TestCase
),
'test_simple_named_collections' => array(
'array<Group> as groups',
function ($actual, \PHPUnit_Framework_TestCase $case) {
function ($actual, TestCase $case) {
$case->assertArrayHasKey('collection', $actual);
$case->assertArrayHasKey('collectionName', $actual);
$case->assertArrayHasKey('class', $actual);
@ -77,7 +79,7 @@ class CollectionDirectiveTest extends \PHPUnit_Framework_TestCase
),
'test_namespaced_named_collections' => array(
'array<_Vendor\\Namespace0\\Namespace_2F3\\Group> as groups',
function ($actual, \PHPUnit_Framework_TestCase $case) {
function ($actual, TestCase $case) {
$case->assertArrayHasKey('collection', $actual);
$case->assertArrayHasKey('collectionName', $actual);
$case->assertArrayHasKey('class', $actual);
@ -92,12 +94,13 @@ class CollectionDirectiveTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException \InvalidArgumentException
* @dataProvider dataInvalidDirectives
* @param $input
*/
public function testInvalidDirectives($input)
{
$this->expectException(\InvalidArgumentException::class);
$this->normalize($input);
}

View File

@ -158,24 +158,6 @@ class FosRestHandlerTest extends WebTestCase
$this->assertArrayNotHasKey('default', $parameter);
}
public function testPostWithArrayRequestParam()
{
$container = $this->getContainer();
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithArrayRequestParamAction', 'test_route_26');
$this->assertNotNull($annotation);
$parameters = $annotation->getParameters();
$this->assertCount(1, $parameters);
$this->assertArrayHasKey('param1', $parameters);
$parameter = $parameters['param1'];
$this->assertArrayHasKey('dataType', $parameter);
$this->assertEquals('string[]', $parameter['dataType']);
}
public function testWithRequestParamArrayRequirements()
{
$container = $this->getContainer();

View File

@ -51,6 +51,7 @@ class TestController
/**
* @ApiDoc(
* resource=true,
* description="create test",
* views={ "default", "premium" },
* input="Nelmio\ApiDocBundle\Tests\Fixtures\Form\TestType"
@ -199,14 +200,6 @@ class TestController
{
}
/**
* @ApiDoc()
* @RequestParamHelper(name="param1", requirements="string", array=true)
*/
public function zActionWithArrayRequestParamAction()
{
}
/**
* @ApiDoc()
*/

View File

@ -31,28 +31,20 @@ class ImprovedTestType extends AbstractType
$builder
->add('dt1', $datetimeType, array('widget' => 'single_text', 'description' => 'A nice description'))
->add('dt2', $datetimeType, array('date_format' => 'M/d/y'))
->add('dt3', $datetimeType, array('widget' => 'single_text', 'format' => 'M/d/y H:i:s'))
->add('dt2', $datetimeType, array('date_format' => 'M/d/y', 'html5' => false))
->add('dt3', $datetimeType, array('widget' => 'single_text', 'format' => 'M/d/y H:i:s', 'html5' => false))
->add('dt4', $datetimeType, array('date_format' => \IntlDateFormatter::MEDIUM))
->add('dt5', $datetimeType, array('format' => 'M/d/y H:i:s'))
->add('dt5', $datetimeType, array('format' => 'M/d/y H:i:s', 'html5' => false))
->add('d1', $dateType, array('format' => \IntlDateFormatter::MEDIUM))
->add('d2', $dateType, array('format' => 'd-M-y'))
->add('c1', $choiceType, array_merge(
array('choices' => array('m' => 'Male', 'f' => 'Female')), LegacyFormHelper::isLegacy() ? array() : array('choices_as_values' => true)
))
->add('c2', $choiceType, array_merge(
array('choices' => array('m' => 'Male', 'f' => 'Female'), 'multiple' => true),
LegacyFormHelper::isLegacy() ? array() : array('choices_as_values' => true)
))
->add('c1', $choiceType, array('choices' => array('Male' => 'm', 'Female' => 'f')))
->add('c2', $choiceType, array('choices' => array('Male' => 'm', 'Female' => 'f') , 'multiple' => true))
->add('c3', $choiceType, array('choices' => array()))
->add('c4', $choiceType, array_merge(
array('choices' => array('foo' => 'bar', 'bazgroup' => array('baz' => 'Buzz'))),
LegacyFormHelper::isLegacy() ? array() : array('choices_as_values' => true)
))
->add('c4', $choiceType, array('choices' => array('bar' => 'foo', 'bazgroup' => array('Buzz' => 'baz'))))
->add('e1', LegacyFormHelper::isLegacy() ? new EntityType() : __NAMESPACE__.'\EntityType',
LegacyFormHelper::isLegacy()
? array('choice_list' => new SimpleChoiceList(array('foo' => 'bar', 'bazgroup' => array('baz' => 'Buzz'))))
: array('choices' => array('foo' => 'bar', 'bazgroup' => array('baz' => 'Buzz')), 'choices_as_values' => true)
? array('choice_list' => new SimpleChoiceList(array('bar' => 'foo', 'bazgroup' => array('Buzz' => 'baz'))))
: array('choices' => array('bar' => 'foo', 'bazgroup' => array('Buzz' => 'baz')))
)
;
}

View File

@ -28,10 +28,9 @@ class SimpleType extends AbstractType
'description' => 'Something that describes A.',
))
->add('b', LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\NumberType'))
->add('c', LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\ChoiceType'), array_merge(
array('choices' => array('x' => 'X', 'y' => 'Y', 'z' => 'Z')),
LegacyFormHelper::isLegacy() ? array() : array('choices_as_values' => true)
))
->add('c', LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\ChoiceType'),
array('choices' => array('X' => 'x', 'Y' => 'y', 'Z' => 'z'))
)
->add('d', LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\DateTimeType'))
->add('e', LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\DateType'))
->add('g', LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\TextareaType'))

View File

@ -18,7 +18,7 @@ class JmsNested
/**
* @JMS\Type("DateTime");
* @JMS\ReadOnly
* @JMS\ReadOnlyProperty
*/
public $foo;

View File

@ -24,7 +24,7 @@ class JmsTest
/**
* @JMS\Type("DateTime");
* @JMS\ReadOnly
* @JMS\ReadOnlyProperty
*/
public $bar;

View File

@ -21,7 +21,7 @@ class JsonSerializableOptionalConstructorTest implements \JsonSerializable
/**
* {@inheritdoc}
*/
public function jsonSerialize()
public function jsonSerialize(): mixed
{
return array();
}

View File

@ -21,7 +21,7 @@ class JsonSerializableRequiredConstructorTest implements \JsonSerializable
/**
* {@inheritdoc}
*/
public function jsonSerialize()
public function jsonSerialize(): mixed
{
return array();
}

View File

@ -16,7 +16,7 @@ class JsonSerializableTest implements \JsonSerializable
/**
* {@inheritdoc}
*/
public function jsonSerialize()
public function jsonSerialize(): mixed
{
return array(
'id' => 123,

View File

@ -1,31 +0,0 @@
<?php
namespace Nelmio\ApiDocBundle\Tests\Fixtures;
use FOS\RestBundle\Controller\Annotations\RequestParam;
/**
* For BC FOSRestBundle < 2.0
*
* @Annotation
* @Target("METHOD")
*
* @author Ener-Getick
*/
class RequestParamHelper extends RequestParam
{
public function __construct(array $data)
{
foreach ($data as $key => $value) {
if ($key === 'array') {
if (property_exists($this, 'map')) {
$this->map = $value;
} else {
$this->array = $value;
}
} else {
$this->$key = $value;
}
}
}
}

View File

@ -19,7 +19,7 @@ use Symfony\Component\HttpKernel\Kernel;
*/
class AppKernel extends Kernel
{
public function registerBundles()
public function registerBundles(): iterable
{
$bundles = array(
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
@ -37,17 +37,17 @@ class AppKernel extends Kernel
return $bundles;
}
public function getRootDir()
public function getProjectDir(): string
{
return __DIR__;
}
public function getCacheDir()
public function getCacheDir(): string
{
return sys_get_temp_dir().'/'.Kernel::VERSION.'/nelmio-api-doc/cache/'.$this->environment;
}
public function getLogDir()
public function getLogDir(): string
{
return sys_get_temp_dir().'/'.Kernel::VERSION.'/nelmio-api-doc/logs';
}

View File

@ -1,21 +1,20 @@
framework:
secret: test
csrf_protection:
enabled: true
router: { resource: "%kernel.root_dir%/config/routing.yml" }
enabled: false
router: { resource: "%kernel.project_dir%/config/routing.yml" }
validation: { enabled: true, enable_annotations: true }
form: ~
form:
enabled: true
test: ~
default_locale: en
session:
storage_id: session.storage.mock_file
profiler: { only_exceptions: false }
templating: { engines: ['twig'] }
annotations: ~
# Twig Configuration
twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
services:
nelmio.test.controller:
@ -26,6 +25,12 @@ services:
- [foo, bar]
tags:
- { name: form.type, alias: dependency_type, extended_type: Nelmio\ApiDocBundle\Tests\Fixtures\Form\DependencyType }
nelmio_api_doc.formatter.simple_formatter:
class: "%nelmio_api_doc.formatter.simple_formatter.class%"
public: true
nelmio_api_doc.formatter.markdown_formatter:
class: "%nelmio_api_doc.formatter.markdown_formatter.class%"
public: true
parameters:
domain_prod: test.com
@ -44,7 +49,7 @@ jms_serializer:
metadata:
cache: file
debug: "%kernel.debug%"
debug: false
file_cache:
dir: "%kernel.cache_dir%/serializer"
@ -56,6 +61,8 @@ jms_serializer:
# expected path: @MyFooBundle/Resources/config/serializer/Entity.User.(yml|xml|php)
auto_detection: true
profiler: false
nelmio_api_doc:
sandbox:
authentication:

View File

@ -1,15 +1,15 @@
doctrine:
dbal:
driver: 'pdo_sqlite'
path: '%kernel.cache_dir%/db.sqlite'
charset: 'UTF8'
driver: "pdo_sqlite"
path: "%kernel.cache_dir%/db.sqlite"
charset: "UTF8"
orm:
auto_generate_proxy_classes: '%kernel.debug%'
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
framework:
router: { resource: '%kernel.root_dir%/config/dunglas_api_routing.yml' }
router: { resource: "%kernel.project_dir%/config/dunglas_api_routing.yml" }
dunglas_api:
title: API
@ -17,6 +17,6 @@ dunglas_api:
services:
dunglas_api.popo:
parent: 'api.resource'
arguments: [ 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\Popo' ]
tags: [ { name: 'api.resource' } ]
parent: api.resource
arguments: [ Nelmio\ApiDocBundle\Tests\Fixtures\Model\Popo ]
tags: [ { name: api.resource } ]

View File

@ -1,65 +1,65 @@
test_route_1:
path: /tests.{_format}
methods: [GET]
defaults: { _controller: NelmioApiDocTestBundle:Test:index, _format: json }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::indexAction, _format: json }
test_route_2:
path: /tests.{_format}
host: api.test.dev
methods: [POST]
defaults: { _controller: NelmioApiDocTestBundle:Test:postTest, _format: json }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::postTestAction, _format: json }
test_route_3:
path: /another
defaults: { _controller: NelmioApiDocTestBundle:Test:another }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::anotherAction }
test_route_4:
path: /any/{foo}
defaults: { _controller: NelmioApiDocTestBundle:Test:any, _format: json }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::anyAction, _format: json }
test_route_5:
path: /my-commented/{id}/{page}/{paramType}/{param}
defaults: { _controller: NelmioApiDocTestBundle:Test:myCommented }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::myCommentedAction }
test_route_6:
path: /yet-another/{id}
defaults: { _controller: NelmioApiDocTestBundle:Test:yetAnother }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::yetAnotherAction }
requirements:
id: \d+
test_route_7:
path: /another-post
methods: [POST]
defaults: { _controller: NelmioApiDocTestBundle:Test:anotherPost, _format: json }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::anotherPostAction, _format: json }
test_route_8:
path: /z-action-with-query-param
methods: [GET]
defaults: { _controller: NelmioApiDocTestBundle:Test:zActionWithQueryParam }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithQueryParamAction }
test_route_9:
path: /jms-input-test
methods: [POST]
defaults: { _controller: NelmioApiDocTestBundle:Test:jmsInputTest }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::jmsInputTestAction }
test_route_10:
path: /jms-return-test
methods: [GET]
defaults: { _controller: NelmioApiDocTestBundle:Test:jmsReturnTest }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::jmsReturnTestAction }
test_route_11:
path: /z-action-with-request-param
methods: [POST]
defaults: { _controller: NelmioApiDocTestBundle:Test:zActionWithRequestParam }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithRequestParamAction }
test_route_12:
path: /secure-route
schemes: [https]
defaults: { _controller: NelmioApiDocTestBundle:Test:secureRoute }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::secureRouteAction }
test_route_13:
path: /authenticated
defaults: { _controller: NelmioApiDocTestBundle:Test:authenticated }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::authenticatedAction }
test_service_route_1:
path: /tests.{_format}
@ -87,104 +87,104 @@ NelmioApiDocBundle:
test_route_14:
path: /tests2.{_format}
methods: [POST]
defaults: { _controller: NelmioApiDocTestBundle:Test:postTest2, _format: json }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::postTest2Action, _format: json }
test_route_15:
path: /z-action-with-query-param-strict
methods: [GET]
defaults: { _controller: NelmioApiDocTestBundle:Test:zActionWithQueryParamStrict }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithQueryParamStrictAction }
test_route_16:
path: /z-action-with-query-param-no-default
methods: [GET]
defaults: { _controller: NelmioApiDocTestBundle:Test:zActionWithQueryParamNoDefault }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithQueryParamNoDefaultAction }
test_route_17:
path: /z-action-with-deprecated-indicator
methods: [GET]
defaults: { _controller: NelmioApiDocTestBundle:Test:deprecated }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::deprecatedAction }
test_return_nested_output:
path: /return-nested-output
defaults: { _controller: NelmioApiDocTestBundle:Test:jmsReturnNestedOutput, _format: json }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::jmsReturnNestedOutputAction, _format: json }
test_return_nested_extend_output:
path: /return-nested-extend-output
defaults: { _controller: NelmioApiDocTestBundle:Test:jmsReturnNestedExtendOutput, _format: json }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::jmsReturnNestedExtendOutputAction, _format: json }
test_route_18:
path: /z-return-jms-and-validator-output
defaults: { _controller: NelmioApiDocTestBundle:Test:zReturnJmsAndValidationOutput }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zReturnJmsAndValidationOutputAction }
test_route_named_resource:
path: /named-resource
defaults: { _controller: NelmioApiDocTestBundle:Test:namedResource }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::namedResourceAction }
test_route_19:
path: /z-return-selected-parsers-output
defaults: { _controller: NelmioApiDocTestBundle:Test:zReturnSelectedParsersOutput }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zReturnSelectedParsersOutputAction }
test_route_20:
path: /z-return-selected-parsers-input
defaults: { _controller: NelmioApiDocTestBundle:Test:zReturnSelectedParsersInput }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zReturnSelectedParsersInputAction }
test_route_private:
path: /private
defaults: { _controller: NelmioApiDocTestBundle:Test:private }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::privateAction }
test_route_exclusive:
path: /exclusive
defaults: { _controller: NelmioApiDocTestBundle:Test:exclusive }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::exclusiveAction }
test_route_21:
path: /z-action-with-constraint-requirements
methods: [GET]
defaults: { _controller: NelmioApiDocTestBundle:Test:zActionWithConstraintAsRequirements }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithConstraintAsRequirementsAction }
test_route_22:
path: /z-action-with-nullable-request-param
methods: [POST]
defaults: { _controller: NelmioApiDocTestBundle:Test:zActionWithNullableRequestParam }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithNullableRequestParamAction }
test_route_list_resource:
path: /api/resources.{_format}
methods: [GET]
defaults: { _controller: NelmioApiDocTestBundle:Resource:listResources, _format: json }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\ResourceController::listResourcesAction, _format: json }
requirements:
_format: json|xml|html
test_route_get_resource:
path: /api/resources/{id}.{_format}
methods: [GET]
defaults: { _controller: NelmioApiDocTestBundle:Resource:getResource, _format: json }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\ResourceController::getResourceAction, _format: json }
requirements:
_format: json|xml|html
test_route_delete_resource:
path: /api/resources/{id}.{_format}
methods: [DELETE]
defaults: { _controller: NelmioApiDocTestBundle:Resource:deleteResource, _format: json }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\ResourceController::deleteResourceAction, _format: json }
requirements:
_format: json|xml|html
test_route_create_resource:
path: /api/resources.{_format}
methods: [POST]
defaults: { _controller: NelmioApiDocTestBundle:Resource:createResource, _format: json }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\ResourceController::createResourceAction, _format: json }
requirements:
_format: json|xml|html
test_route_list_another_resource:
path: /api/other-resources.{_format}
methods: [GET]
defaults: { _controller: NelmioApiDocTestBundle:Resource:listAnotherResources, _format: json }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\ResourceController::listAnotherResourcesAction, _format: json }
requirements:
_format: json|xml|html
test_route_update_another_resource:
path: /api/other-resources/{id}.{_format}
methods: [PUT, PATCH]
defaults: { _controller: NelmioApiDocTestBundle:Resource:updateAnotherResource, _format: json }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\ResourceController::updateAnotherResourceAction, _format: json }
requirements:
_format: json|xml|html
@ -195,41 +195,41 @@ swagger_doc:
test_route_23:
path: /zcached
methods: [POST]
defaults: { _controller: NelmioApiDocTestBundle:Test:zCached }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zCachedAction }
test_route_24:
path: /zsecured
methods: [POST]
defaults: { _controller: NelmioApiDocTestBundle:Test:zSecured }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zSecuredAction }
test_required_parameters:
path: /api/other-resources/{id}.{_format}
methods: [POST]
defaults: { _controller: NelmioApiDocTestBundle:Resource:requiredParametersAction, _format: json }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\ResourceController::requiredParametersAction, _format: json }
requirements:
_format: json|xml|html
test_patch_disables_required_parameters:
path: /api/other-resources/{id}.{_format}
methods: [PATCH]
defaults: { _controller: NelmioApiDocTestBundle:Resource:requiredParametersAction, _format: json }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\ResourceController::requiredParametersAction, _format: json }
requirements:
_format: json|xml|html
test_route_25:
path: /with-link
methods: [GET]
defaults: { _controller: NelmioApiDocTestBundle:Test:withLinkAction }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::withLinkAction }
test_route_26:
path: /z-action-with-array-request-param
methods: [POST]
defaults: { _controller: NelmioApiDocTestBundle:Test:zActionWithArrayRequestParamAction }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithArrayRequestParamAction }
test_route_27:
path: /api/overrride/properties
methods: [POST, PUT]
defaults: { _controller: NelmioApiDocTestBundle:Test:overrideJmsAnnotationWithApiDocPropertiesAction, _format: json }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::overrideJmsAnnotationWithApiDocPropertiesAction, _format: json }
test_route_28:
path: /route_with_host.{_format}
@ -237,25 +237,25 @@ test_route_28:
methods: [GET]
requirements:
domain: "%domain_dev%|%domain_prod%"
defaults: { _controller: NelmioApiDocTestBundle:Test:routeWithHost, domain: "%domain_dev%", _format: json }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::routeWithHostAction, domain: "%domain_dev%", _format: json }
test_route_29:
path: /z-query-param-array-requirements
methods: [GET]
defaults: { _controller: NelmioApiDocTestBundle:Test:routeWithQueryParamArrayRequirementsAction }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::routeWithQueryParamArrayRequirementsAction }
test_route_30:
path: /z-query-param-plain-array-requirements
methods: [GET]
defaults: { _controller: NelmioApiDocTestBundle:Test:routeWithQueryParamPlainArrayRequirementsAction }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::routeWithQueryParamPlainArrayRequirementsAction }
test_route_31:
path: /z-query-requirement-param-not-set
methods: [GET]
defaults: { _controller: NelmioApiDocTestBundle:Test:zActionWithRequirementParamNotSet }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithRequirementParamNotSet }
test_route_version_checking:
path: /zz-tests-route-version.{_format}
methods: [GET]
defaults: { _controller: NelmioApiDocTestBundle:Test:routeVersion, _format: json, _version: "1.5" }
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::routeVersionAction, _format: json, _version: "1.5" }

View File

@ -26,7 +26,7 @@ class MarkdownFormatterTest extends WebTestCase
restore_error_handler();
$result = $container->get('nelmio_api_doc.formatter.markdown_formatter')->format($data);
$suffix = class_exists('Dunglas\ApiBundle\DunglasApiBundle') ? '' : '-no-dunglas';
$suffix = class_exists('Dunglas\ApiBundle\DunglasApiBundle') ? '' : '_1';
$expected = file_get_contents(__DIR__ . '/testFormat-result' . $suffix . '.markdown');
if (LegacyFormHelper::isLegacy()) {
$expected = str_replace('DependencyType', 'dependency_type', $expected);

View File

@ -25,7 +25,7 @@ class SimpleFormatterTest extends WebTestCase
restore_error_handler();
$result = $container->get('nelmio_api_doc.formatter.simple_formatter')->format($data);
$suffix = class_exists('Dunglas\ApiBundle\DunglasApiBundle') ? '' : '-no-dunglas';
$suffix = class_exists('Dunglas\ApiBundle\DunglasApiBundle') ? '' : '_1';
$expected = require __DIR__ . '/testFormat-result'.$suffix.'.php';
$this->assertEquals($expected, $result);

View File

@ -25,7 +25,7 @@ class SwaggerFormatterTest extends WebTestCase
*/
protected $formatter;
protected function setUp()
protected function setUp(): void
{
parent::setUp();
@ -908,35 +908,6 @@ With multiple lines.',
'operations' =>
array(
array(
'method' => 'GET',
'summary' => 'index action',
'nickname' => 'get_tests',
'parameters' =>
array(
array(
'paramType' => 'path',
'name' => '_format',
'type' => 'string',
'required' => true,
),
array(
'paramType' => 'query',
'name' => 'a',
'type' => 'integer',
'description' => null,
),
array(
'paramType' => 'query',
'name' => 'b',
'type' => 'string',
'description' => null,
),
),
'responseMessages' =>
array(),
),
array(
'method' => 'GET',
'summary' => 'index action',
@ -1006,45 +977,6 @@ With multiple lines.',
'responseMessages' =>
array(),
),
array(
'method' => 'POST',
'summary' => 'create test',
'nickname' => 'post_tests',
'parameters' =>
array(
array(
'paramType' => 'path',
'name' => '_format',
'type' => 'string',
'required' => true,
),
array(
'paramType' => 'form',
'name' => 'a',
'type' => 'string',
'description' => 'A nice description',
),
array(
'paramType' => 'form',
'name' => 'b',
'type' => 'string',
),
array(
'paramType' => 'form',
'name' => 'c',
'type' => 'boolean',
'defaultValue' => false,
),
array(
'paramType' => 'form',
'name' => 'd',
'type' => 'string',
'defaultValue' => 'DefaultTest',
),
),
'responseMessages' =>
array(),
),
),
),
),

View File

@ -0,0 +1,920 @@
## /api/other-resources ##
### `GET` /api/other-resources.{_format} ###
_List another resource._
#### Requirements ####
**_format**
- Requirement: json|xml|html
#### Response ####
[]:
* type: array of objects (JmsTest)
[][foo]:
* type: string
[][bar]:
* type: DateTime
[][number]:
* type: double
[][arr]:
* type: array
[][nested]:
* type: object (JmsNested)
[][nested][foo]:
* type: DateTime
[][nested][bar]:
* type: string
[][nested][baz][]:
* type: array of integers
* description: Epic description.
With multiple lines.
[][nested][circular]:
* type: object (JmsNested)
[][nested][parent]:
* type: object (JmsTest)
[][nested][parent][foo]:
* type: string
[][nested][parent][bar]:
* type: DateTime
[][nested][parent][number]:
* type: double
[][nested][parent][arr]:
* type: array
[][nested][parent][nested]:
* type: object (JmsNested)
[][nested][parent][nested_array][]:
* type: array of objects (JmsNested)
[][nested][since]:
* type: string
* versions: >=0.2
[][nested][until]:
* type: string
* versions: <=0.3
[][nested][since_and_until]:
* type: string
* versions: >=0.4,<=0.5
[][nested_array][]:
* type: array of objects (JmsNested)
### `PUT|PATCH` /api/other-resources/{id}.{_format} ###
_Update a resource bu ID._
#### Requirements ####
**_format**
- Requirement: json|xml|html
**id**
## /api/resources ##
### `GET` /api/resources.{_format} ###
_List resources._
#### Requirements ####
**_format**
- Requirement: json|xml|html
#### Response ####
tests[]:
* type: array of objects (Test)
tests[][a]:
* type: string
tests[][b]:
* type: DateTime
### `POST` /api/resources.{_format} ###
_Create a new resource._
#### Requirements ####
**_format**
- Requirement: json|xml|html
#### Parameters ####
a:
* type: string
* required: true
* description: Something that describes A.
b:
* type: float
* required: true
c:
* type: choice
* required: true
d:
* type: datetime
* required: true
e:
* type: date
* required: true
g:
* type: string
* required: true
#### Response ####
foo:
* type: DateTime
bar:
* type: string
baz[]:
* type: array of integers
* description: Epic description.
With multiple lines.
circular:
* type: object (JmsNested)
circular[foo]:
* type: DateTime
circular[bar]:
* type: string
circular[baz][]:
* type: array of integers
* description: Epic description.
With multiple lines.
circular[circular]:
* type: object (JmsNested)
circular[parent]:
* type: object (JmsTest)
circular[parent][foo]:
* type: string
circular[parent][bar]:
* type: DateTime
circular[parent][number]:
* type: double
circular[parent][arr]:
* type: array
circular[parent][nested]:
* type: object (JmsNested)
circular[parent][nested_array][]:
* type: array of objects (JmsNested)
circular[since]:
* type: string
* versions: >=0.2
circular[until]:
* type: string
* versions: <=0.3
circular[since_and_until]:
* type: string
* versions: >=0.4,<=0.5
parent:
* type: object (JmsTest)
parent[foo]:
* type: string
parent[bar]:
* type: DateTime
parent[number]:
* type: double
parent[arr]:
* type: array
parent[nested]:
* type: object (JmsNested)
parent[nested_array][]:
* type: array of objects (JmsNested)
since:
* type: string
* versions: >=0.2
until:
* type: string
* versions: <=0.3
since_and_until:
* type: string
* versions: >=0.4,<=0.5
### `DELETE` /api/resources/{id}.{_format} ###
_Delete a resource by ID._
#### Requirements ####
**_format**
- Requirement: json|xml|html
**id**
### `GET` /api/resources/{id}.{_format} ###
_Retrieve a resource by ID._
#### Requirements ####
**_format**
- Requirement: json|xml|html
**id**
## /tests ##
### `GET` /tests.{_format} ###
_index action_
#### Requirements ####
**_format**
#### Filters ####
a:
* DataType: integer
b:
* DataType: string
* Arbitrary: ["arg1","arg2"]
### `POST` /tests.{_format} ###
_create test_
#### Requirements ####
**_format**
#### Parameters ####
a:
* type: string
* required: true
* description: A nice description
b:
* type: string
* required: true
c:
* type: boolean
* required: true
d:
* type: string
* required: true
* default value: DefaultTest
## /tests2 ##
### `POST` /tests2.{_format} ###
_post test 2_
#### Requirements ####
**_format**
## TestResource ##
### `ANY` /named-resource ###
### `POST` /another-post ###
_create another test_
#### Parameters ####
dependency_type:
* type: object (DependencyType)
* required: true
dependency_type[a]:
* type: string
* required: true
* description: A nice description
### `ANY` /any/{foo} ###
_Action without HTTP verb_
#### Requirements ####
**foo**
### `ANY` /authenticated ###
### `POST` /jms-input-test ###
_Testing JMS_
#### Parameters ####
foo:
* type: string
* required: false
number:
* type: double
* required: false
arr:
* type: array
* required: false
nested:
* type: object (JmsNested)
* required: false
nested[bar]:
* type: string
* required: false
* default value: baz
nested[baz][]:
* type: array of integers
* required: false
* description: Epic description.
With multiple lines.
nested[circular]:
* type: object (JmsNested)
* required: false
nested[parent]:
* type: object (JmsTest)
* required: false
nested[parent][foo]:
* type: string
* required: false
nested[parent][number]:
* type: double
* required: false
nested[parent][arr]:
* type: array
* required: false
nested[parent][nested]:
* type: object (JmsNested)
* required: false
nested[parent][nested_array][]:
* type: array of objects (JmsNested)
* required: false
nested[since]:
* type: string
* required: false
nested[until]:
* type: string
* required: false
nested[since_and_until]:
* type: string
* required: false
nested_array[]:
* type: array of objects (JmsNested)
* required: false
### `GET` /jms-return-test ###
_Testing return_
#### Response ####
dependency_type:
* type: object (DependencyType)
dependency_type[a]:
* type: string
* description: A nice description
### `ANY` /my-commented/{id}/{page}/{paramType}/{param} ###
_This method is useful to test if the getDocComment works._
#### Requirements ####
**id**
- Type: int
- Description: A nice comment
**page**
- Type: int
**paramType**
- Type: int
- Description: The param type
**param**
- Type: int
- Description: The param id
### `ANY` /return-nested-output ###
#### Response ####
foo:
* type: string
bar:
* type: DateTime
number:
* type: double
arr:
* type: array
nested:
* type: object (JmsNested)
nested[foo]:
* type: DateTime
nested[bar]:
* type: string
nested[baz][]:
* type: array of integers
* description: Epic description.
With multiple lines.
nested[circular]:
* type: object (JmsNested)
nested[parent]:
* type: object (JmsTest)
nested[parent][foo]:
* type: string
nested[parent][bar]:
* type: DateTime
nested[parent][number]:
* type: double
nested[parent][arr]:
* type: array
nested[parent][nested]:
* type: object (JmsNested)
nested[parent][nested_array][]:
* type: array of objects (JmsNested)
nested[since]:
* type: string
* versions: >=0.2
nested[until]:
* type: string
* versions: <=0.3
nested[since_and_until]:
* type: string
* versions: >=0.4,<=0.5
nested_array[]:
* type: array of objects (JmsNested)
### `GET` /route_with_host.{_format} ###
_Route with host placeholder_
#### Requirements ####
**domain**
- Requirement: test.dev|test.com
**_format**
### `ANY` /secure-route ###
### `GET` /with-link ###
### `ANY` /yet-another/{id} ###
#### Requirements ####
**id**
- Requirement: \d+
### `GET` /z-action-with-deprecated-indicator ###
### This method is deprecated ###
### `POST` /z-action-with-nullable-request-param ###
#### Parameters ####
param1:
* type: string
* required: false
* description: Param1 description.
### `GET` /z-action-with-query-param ###
#### Filters ####
page:
* Requirement: \d+
* Description: Page of the overview.
* Default: 1
### `GET` /z-action-with-query-param-no-default ###
#### Filters ####
page:
* Requirement: \d+
* Description: Page of the overview.
### `GET` /z-action-with-query-param-strict ###
#### Requirements ####
**page**
- Requirement: \d+
- Description: Page of the overview.
### `POST` /z-action-with-request-param ###
#### Parameters ####
param1:
* type: string
* required: true
* description: Param1 description.
### `GET` /z-query-param-array-requirements ###
#### Filters ####
param1:
* Requirement: regexp
* Description: Param1 description.
### `GET` /z-query-param-plain-array-requirements ###
#### Filters ####
param1:
* Requirement: NotNull, NotBlank
* Description: Param1 description.
### `GET` /z-query-requirement-param-not-set ###
#### Filters ####
param1:
* Description: Param1 description.
### `ANY` /z-return-jms-and-validator-output ###
#### Response ####
bar:
* type: DateTime
objects[]:
* type: array of objects (Test)
objects[][a]:
* type: string
objects[][b]:
* type: DateTime
number:
* type: DateTime
related:
* type: object (Test)
related[a]:
* type: string
related[b]:
* type: DateTime
### `ANY` /z-return-selected-parsers-input ###
#### Parameters ####
a:
* type: string
* required: true
* description: A nice description
b:
* type: string
* required: true
c:
* type: boolean
* required: true
d:
* type: string
* required: true
* default value: DefaultTest
### `ANY` /z-return-selected-parsers-output ###
#### Response ####
bar:
* type: DateTime
objects[]:
* type: array of objects (Test)
objects[][a]:
* type: string
objects[][b]:
* type: DateTime
number:
* type: DateTime
related:
* type: object (Test)
related[a]:
* type: string
related[b]:
* type: DateTime
### `POST` /zcached ###
### `POST` /zsecured ###
### `GET` /zz-tests-route-version.{_format} ###
#### Requirements ####
**_format**

File diff suppressed because it is too large Load Diff

View File

@ -20,7 +20,7 @@ use Nelmio\ApiDocBundle\Tests\WebTestCase;
*/
class DunglasApiParserTest extends WebTestCase
{
protected function setUp()
protected function setUp(): void
{
if (!class_exists('Dunglas\ApiBundle\DunglasApiBundle')) {
$this->markTestSkipped(

View File

@ -17,6 +17,7 @@ use Nelmio\ApiDocBundle\Parser\FormTypeParser;
use Nelmio\ApiDocBundle\Tests\Fixtures;
use Nelmio\ApiDocBundle\Tests\Fixtures\Form\DependencyType;
use Nelmio\ApiDocBundle\Util\LegacyFormHelper;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Form\Extension\Core\CoreExtension;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\FormFactory;
@ -24,7 +25,7 @@ use Symfony\Component\Form\FormFactoryBuilder;
use Symfony\Component\Form\ResolvedFormTypeFactory;
use Symfony\Component\Translation\Translator;
class FormTypeParserTest extends \PHPUnit_Framework_TestCase
class FormTypeParserTest extends TestCase
{
/**
* @dataProvider dataTestParse
@ -118,10 +119,10 @@ class FormTypeParserTest extends \PHPUnit_Framework_TestCase
'subType' => null,
'default' => null,
'required' => true,
'description' => '',
'description' => null,
'readonly' => false,
),
LegacyFormHelper::isLegacy() ? array() : array('format' => '[bar|Array]',)
LegacyFormHelper::isLegacy() ? array() : array('format' => '[bar|bazgroup]',)
);
return array(
@ -473,9 +474,9 @@ class FormTypeParserTest extends \PHPUnit_Framework_TestCase
'subType' => null,
'default' => null,
'required' => true,
'description' => '',
'description' => null,
'readonly' => false,
'format' => '[bar|Array]',
'format' => '[bar|bazgroup]',
),
'e1' => $entityData
),

View File

@ -17,8 +17,9 @@ use Nelmio\ApiDocBundle\Parser\JmsMetadataParser;
use JMS\Serializer\Metadata\ClassMetadata;
use JMS\Serializer\Metadata\PropertyMetadata;
use JMS\Serializer\Naming\CamelCaseNamingStrategy;
use PHPUnit\Framework\TestCase;
class JmsMetadataParserTest extends \PHPUnit_Framework_TestCase
class JmsMetadataParserTest extends TestCase
{
/**
* @dataProvider dataTestParserWithNestedType
@ -59,19 +60,14 @@ class JmsMetadataParserTest extends \PHPUnit_Framework_TestCase
$propertyNamingStrategy = $this->createMock('JMS\Serializer\Naming\PropertyNamingStrategyInterface');
$propertyNamingStrategy
->expects($this->at(0))
->expects($this->exactly(3))
->method('translateName')
->will($this->returnValue('foo'));
$propertyNamingStrategy
->expects($this->at(1))
->method('translateName')
->will($this->returnValue('bar'));
$propertyNamingStrategy
->expects($this->at(2))
->method('translateName')
->will($this->returnValue('baz'));
->willReturnOnConsecutiveCalls(
$this->returnValue('foo'),
$this->returnValue('bar'),
$this->returnValue('baz')
)
;
$input = 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsNested';
@ -527,21 +523,19 @@ class JmsMetadataParserTest extends \PHPUnit_Framework_TestCase
$subMetadata = new ClassMetadata($subInput);
$subMetadata->addPropertyMetadata($propertyMetadataBar);
$metadataFactory->expects($this->at(0))
$metadataFactory
->expects($this->exactly(3))
->method('getMetadataForClass')
->with($input)
->will($this->returnValue($metadata));
$metadataFactory->expects($this->at(1))
->method('getMetadataForClass')
->with($subInput)
->will($this->returnValue($subMetadata));
$metadataFactory->expects($this->at(2))
->method('getMetadataForClass')
->with($subInput)
->will($this->returnValue($subMetadata));
->withConsecutive(
[$input],
[$subInput],
[$subInput]
)
->willReturnOnConsecutiveCalls(
$metadata,
$subMetadata,
$subMetadata
);
$propertyNamingStrategy = new CamelCaseNamingStrategy();
$jmsMetadataParser = new JmsMetadataParser($metadataFactory, $propertyNamingStrategy, $docCommentExtractor);

View File

@ -12,15 +12,16 @@
namespace NelmioApiDocBundle\Tests\Parser;
use Nelmio\ApiDocBundle\Parser\JsonSerializableParser;
use PHPUnit\Framework\TestCase;
class JsonSerializableParserTest extends \PHPUnit_Framework_TestCase
class JsonSerializableParserTest extends TestCase
{
/**
* @var JsonSerializableParser
*/
private $parser;
public function setUp()
public function setUp(): void
{
$this->parser = new JsonSerializableParser();
}

View File

@ -20,8 +20,9 @@ use Symfony\Component\HttpKernel\Kernel;
class ValidationParserTest extends WebTestCase
{
protected $handler;
private ValidationParser $parser;
public function setUp()
public function setUp(): void
{
$container = $this->getContainer();
@ -34,7 +35,7 @@ class ValidationParserTest extends WebTestCase
if (version_compare(Kernel::VERSION, '2.2.0', '<')) {
$this->parser = new ValidationParserLegacy($factory);
} else {
$this->parser = new ValidationParser($factory);
$this->parser = new ValidationParser($factory);
}
}

View File

@ -11,6 +11,6 @@
namespace Nelmio\ApiDocBundle\Tests;
class TestCase extends \PHPUnit_Framework_TestCase
class TestCase extends \PHPUnit\Framework\TestCase
{
}

View File

@ -11,15 +11,17 @@
namespace Nelmio\ApiDocBundle\Tests;
use PHPUnit\Util\ErrorHandler;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\KernelInterface;
abstract class WebTestCase extends BaseWebTestCase
{
public static $container;
protected function setUp()
protected function setUp(): void
{
parent::setUp();
@ -28,44 +30,23 @@ abstract class WebTestCase extends BaseWebTestCase
}
}
public static function handleDeprecation($errorNumber, $message, $file, $line, $context)
public static function handleDeprecation($errorNumber, $message, $file, $line)
{
if ($errorNumber & E_USER_DEPRECATED) {
return true;
}
return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line);
return ErrorHandler::handleError($errorNumber, $message, $file, $line);
}
/**
* @param array $options
* @return ContainerInterface
*/
protected function getContainer(array $options = array())
{
if (!static::$kernel) {
static::$kernel = static::createKernel($options);
}
static::$kernel->boot();
if (!static::$container) {
static::$container = static::$kernel->getContainer();
}
static::$container->set('kernel', static::$kernel);
return static::$container;
}
protected static function getKernelClass()
protected static function getKernelClass(): string
{
require_once __DIR__.'/Fixtures/app/AppKernel.php';
return 'Nelmio\ApiDocBundle\Tests\Functional\AppKernel';
}
protected static function createKernel(array $options = array())
protected static function createKernel(array $options = array()): KernelInterface
{
$class = self::getKernelClass();

View File

@ -15,12 +15,25 @@
}
],
"require": {
"php": ">=7.1",
"symfony/twig-bundle": "~2.3|~3.0|~4.0|~5.0",
"symfony/framework-bundle": "~2.3|~3.0|~4.0|~5.0",
"symfony/console": "~2.3|~3.0|~4.0|~5.0",
"php": ">=8.1",
"symfony/form": "^5.0|^6.0",
"symfony/twig-bundle": "^5.0|^6.0",
"symfony/framework-bundle": "^5.0|^6.0",
"symfony/console": "^5.0|^6.0",
"michelf/php-markdown": "~1.4"
},
"require-dev": {
"friendsofsymfony/rest-bundle": "^3.7",
"jms/serializer": "~3.15.0",
"jms/serializer-bundle": "4.1.0",
"phpunit/phpunit": "~9.5",
"sensio/framework-extra-bundle": "^6.2",
"symfony/asset": "^5.0|^6.0",
"symfony/browser-kit": "^5.0|^6.0",
"symfony/translation": "^5.0|^6.0",
"symfony/validator": "^5.0|^6.0",
"symfony/yaml": "^5.0|^6.0"
},
"conflict": {
"jms/serializer": "<0.12",
"jms/serializer-bundle": "<0.11",

8
docker-compose.yml Normal file
View File

@ -0,0 +1,8 @@
services:
php:
build:
context: .
args:
PHP_IMAGE_TAG: ${PHP_IMAGE_TAG:-8.1}
volumes:
- "./:/opt/test"

View File

@ -3,12 +3,12 @@
backupGlobals = "false"
backupStaticAttributes = "false"
colors = "true"
convertDeprecationsToExceptions = "true"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
processIsolation = "false"
stopOnFailure = "false"
syntaxCheck = "false"
bootstrap = "Tests/bootstrap.php">
<testsuites>
@ -16,15 +16,4 @@
<directory>Tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>.</directory>
<exclude>
<directory>Resources</directory>
<directory>Tests</directory>
<directory>vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>