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/ vendor/
composer.lock composer.lock
phpunit.xml phpunit.xml
.idea
.phpunit.result.cache

View File

@ -12,25 +12,40 @@
namespace Nelmio\ApiDocBundle\Command; namespace Nelmio\ApiDocBundle\Command;
use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request; 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 * @var array
*/ */
protected $availableFormats = array('markdown', 'json', 'html'); 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() protected function configure()
{ {
$this $this
->setDescription('Dumps API documentation in various formats')
->addOption( ->addOption(
'format', '', InputOption::VALUE_REQUIRED, 'format', '', InputOption::VALUE_REQUIRED,
'Output format like: ' . implode(', ', $this->availableFormats), 'Output format like: ' . implode(', ', $this->availableFormats),
@ -40,7 +55,6 @@ class DumpCommand extends Command implements ContainerAwareInterface
->addOption('locale', null, InputOption::VALUE_REQUIRED, 'Locale for translation') ->addOption('locale', null, InputOption::VALUE_REQUIRED, 'Locale for translation')
->addOption('view', '', InputOption::VALUE_OPTIONAL, '', ApiDoc::DEFAULT_VIEW) ->addOption('view', '', InputOption::VALUE_OPTIONAL, '', ApiDoc::DEFAULT_VIEW)
->addOption('no-sandbox', '', InputOption::VALUE_NONE) ->addOption('no-sandbox', '', InputOption::VALUE_NONE)
->setName('api:doc:dump')
; ;
} }
@ -49,9 +63,7 @@ class DumpCommand extends Command implements ContainerAwareInterface
$format = $input->getOption('format'); $format = $input->getOption('format');
$view = $input->getOption('view'); $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'); $formatter = $this->container->get('nelmio_api_doc.formatter.simple_formatter');
} else { } else {
if (!in_array($format, $this->availableFormats)) { if (!in_array($format, $this->availableFormats)) {
@ -62,7 +74,7 @@ class DumpCommand extends Command implements ContainerAwareInterface
} }
if ($input->hasOption('locale')) { if ($input->hasOption('locale')) {
$this->container->get('translator')->setLocale($input->getOption('locale')); $this->translator->setLocale($input->getOption('locale') ?? '');
} }
if ($input->hasOption('api-version')) { if ($input->hasOption('api-version')) {
@ -73,11 +85,6 @@ class DumpCommand extends Command implements ContainerAwareInterface
$formatter->setEnableSandbox(false); $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'); $extractor = $this->container->get('nelmio_api_doc.extractor.api_doc_extractor');
$extractedDoc = $input->hasOption('api-version') ? $extractedDoc = $input->hasOption('api-version') ?
$extractor->allForVersion($input->getOption('api-version'), $view) : $extractor->allForVersion($input->getOption('api-version'), $view) :

View File

@ -12,11 +12,13 @@
namespace Nelmio\ApiDocBundle\Command; namespace Nelmio\ApiDocBundle\Command;
use Nelmio\ApiDocBundle\Formatter\SwaggerFormatter; 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\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
@ -25,7 +27,11 @@ use Symfony\Component\Filesystem\Filesystem;
* *
* @author Bez Hermoso <bez@activelamp.com> * @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 * @var Filesystem
@ -37,25 +43,29 @@ class SwaggerDumpCommand extends ContainerAwareCommand
*/ */
protected $formatter; protected $formatter;
public function __construct(
private ContainerInterface $container,
string $name = null
) {
parent::__construct($name);
}
protected function configure() protected function configure()
{ {
$this->filesystem = new Filesystem(); $this->filesystem = new Filesystem();
$this $this
->setDescription('Dumps Swagger-compliant API definitions.')
->addOption('resource', 'r', InputOption::VALUE_OPTIONAL, 'A specific resource API declaration to dump.') ->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('list-only', 'l', InputOption::VALUE_NONE, 'Dump resource list only.')
->addOption('pretty', 'p', InputOption::VALUE_NONE, 'Dump as prettified JSON.') ->addOption('pretty', 'p', InputOption::VALUE_NONE, 'Dump as prettified JSON.')
->addArgument('destination', InputArgument::OPTIONAL, 'Directory to dump JSON files in.', null) ->addArgument('destination', InputArgument::OPTIONAL, 'Directory to dump JSON files in.', null)
->setName('api:swagger:dump'); ;
} }
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$container = $this->getContainer(); $extractor = $this->container->get('nelmio_api_doc.extractor.api_doc_extractor');
$this->formatter = $this->container->get('nelmio_api_doc.formatter.swagger_formatter');
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
$this->formatter = $container->get('nelmio_api_doc.formatter.swagger_formatter');
if ($input->getOption('list-only') && $input->getOption('resource')) { if ($input->getOption('list-only') && $input->getOption('resource')) {
throw new \RuntimeException('Cannot selectively dump a resource with the --list-only flag.'); 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\Formatter\RequestAwareSwaggerFormatter;
use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@ -20,10 +21,15 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class ApiDocController extends 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'); $extractor = $this->c->get('nelmio_api_doc.extractor.api_doc_extractor');
$formatter = $this->get('nelmio_api_doc.formatter.html_formatter'); $formatter = $this->c->get('nelmio_api_doc.formatter.html_formatter');
$apiVersion = $request->query->get('_version', null); $apiVersion = $request->query->get('_version', null);
if ($apiVersion) { if ($apiVersion) {
@ -37,11 +43,11 @@ class ApiDocController extends AbstractController
return new Response($htmlContent, 200, array('Content-Type' => 'text/html')); 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(); $docs = $this->c->get('nelmio_api_doc.extractor.api_doc_extractor')->all();
$formatter = new RequestAwareSwaggerFormatter($request, $this->get('nelmio_api_doc.formatter.swagger_formatter')); $formatter = new RequestAwareSwaggerFormatter($request, $this->c->get('nelmio_api_doc.formatter.swagger_formatter'));
$spec = $formatter->format($docs, $resource ? '/' . $resource : null); $spec = $formatter->format($docs, $resource ? '/' . $resource : null);

View File

@ -14,6 +14,7 @@ namespace Nelmio\ApiDocBundle\DependencyInjection;
use Nelmio\ApiDocBundle\Parser\FormInfoParser; use Nelmio\ApiDocBundle\Parser\FormInfoParser;
use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
@ -79,8 +80,13 @@ class NelmioApiDocExtension extends Extension
$arguments[] = $config['cache']['file']; $arguments[] = $config['cache']['file'];
$arguments[] = '%kernel.debug%'; $arguments[] = '%kernel.debug%';
$caching->setArguments($arguments); $caching->setArguments($arguments);
$caching->setPublic(true);
$container->setDefinition('nelmio_api_doc.extractor.api_doc_extractor', $caching); $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) public function onKernelRequest(RequestEvent $event)
{ {
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { if (HttpKernelInterface::MAIN_REQUEST !== $event->getRequestType()) {
return; return;
} }

View File

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

View File

@ -42,7 +42,6 @@ class CachingApiDocExtractor extends ApiDocExtractor
* @param RouterInterface $router * @param RouterInterface $router
* @param Reader $reader * @param Reader $reader
* @param DocCommentExtractor $commentExtractor * @param DocCommentExtractor $commentExtractor
* @param ControllerNameParser $controllerNameParser
* @param array $handlers * @param array $handlers
* @param array $annotationsProviders * @param array $annotationsProviders
* @param string $cacheFile * @param string $cacheFile
@ -53,13 +52,12 @@ class CachingApiDocExtractor extends ApiDocExtractor
RouterInterface $router, RouterInterface $router,
Reader $reader, Reader $reader,
DocCommentExtractor $commentExtractor, DocCommentExtractor $commentExtractor,
ControllerNameParser $controllerNameParser,
array $handlers, array $handlers,
array $annotationsProviders, array $annotationsProviders,
$cacheFile, $cacheFile,
$debug = false $debug = false
) { ) {
parent::__construct($container, $router, $reader, $commentExtractor, $controllerNameParser, $handlers, $annotationsProviders); parent::__construct($container, $router, $reader, $commentExtractor, $handlers, $annotationsProviders);
$this->cacheFile = $cacheFile; $this->cacheFile = $cacheFile;
$this->debug = $debug; $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: nelmio_api_doc_index:
path: /{view} path: /{view}
defaults: { _controller: Nelmio\ApiDocBundle\Controller\ApiDocController::indexAction, view: 'default' } defaults: { _controller: Nelmio\ApiDocBundle\Controller\ApiDocController::index, view: 'default' }
methods: [GET] methods: [GET]

View File

@ -1,9 +1,9 @@
nelmio_api_doc_swagger_resource_list: nelmio_api_doc_swagger_resource_list:
path: / path: /
methods: [GET] methods: [GET]
defaults: { _controller: NelmioApiDocBundle:ApiDoc:swagger } defaults: { _controller: Nelmio\ApiDocBundle\Controller\ApiDocController::swagger }
nelmio_api_doc_swagger_api_declaration: nelmio_api_doc_swagger_api_declaration:
path: /{resource} path: /{resource}
methods: [GET] 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()); $this->assertNull($annot->getInput());
} }
/**
* @expectedException \InvalidArgumentException
*/
public function testConstructMethodHasFiltersWithoutName() public function testConstructMethodHasFiltersWithoutName()
{ {
$this->expectException(\InvalidArgumentException::class);
$data = array( $data = array(
'description' => 'Heya', 'description' => 'Heya',
'filters' => array( 'filters' => array(

View File

@ -23,12 +23,12 @@ class ApiDocControllerTest extends WebTestCase
public function testSwaggerDocResourceListRoute() public function testSwaggerDocResourceListRoute()
{ {
$client = static::createClient(); $client = static::createClient();
$client->request('GET', '/api-docs/'); $client->request('GET', '/api-docs');
$response = $client->getResponse(); $response = $client->getResponse();
$this->assertEquals(200, $response->getStatusCode()); $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 class DunglasApiProviderTest extends WebTestCase
{ {
protected function setUp() protected function setUp(): void
{ {
if (!class_exists('Dunglas\ApiBundle\DunglasApiBundle')) { if (!class_exists('Dunglas\ApiBundle\DunglasApiBundle')) {
$this->markTestSkipped( $this->markTestSkipped(

View File

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

View File

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

View File

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

View File

@ -158,24 +158,6 @@ class FosRestHandlerTest extends WebTestCase
$this->assertArrayNotHasKey('default', $parameter); $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() public function testWithRequestParamArrayRequirements()
{ {
$container = $this->getContainer(); $container = $this->getContainer();

View File

@ -51,6 +51,7 @@ class TestController
/** /**
* @ApiDoc( * @ApiDoc(
* resource=true,
* description="create test", * description="create test",
* views={ "default", "premium" }, * views={ "default", "premium" },
* input="Nelmio\ApiDocBundle\Tests\Fixtures\Form\TestType" * 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() * @ApiDoc()
*/ */

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -16,7 +16,7 @@ class JsonSerializableTest implements \JsonSerializable
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
return array( return array(
'id' => 123, '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 class AppKernel extends Kernel
{ {
public function registerBundles() public function registerBundles(): iterable
{ {
$bundles = array( $bundles = array(
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(), new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
@ -37,17 +37,17 @@ class AppKernel extends Kernel
return $bundles; return $bundles;
} }
public function getRootDir() public function getProjectDir(): string
{ {
return __DIR__; return __DIR__;
} }
public function getCacheDir() public function getCacheDir(): string
{ {
return sys_get_temp_dir().'/'.Kernel::VERSION.'/nelmio-api-doc/cache/'.$this->environment; 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'; return sys_get_temp_dir().'/'.Kernel::VERSION.'/nelmio-api-doc/logs';
} }

View File

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

View File

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

View File

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

View File

@ -25,7 +25,7 @@ class SimpleFormatterTest extends WebTestCase
restore_error_handler(); restore_error_handler();
$result = $container->get('nelmio_api_doc.formatter.simple_formatter')->format($data); $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'; $expected = require __DIR__ . '/testFormat-result'.$suffix.'.php';
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);

View File

@ -25,7 +25,7 @@ class SwaggerFormatterTest extends WebTestCase
*/ */
protected $formatter; protected $formatter;
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -908,35 +908,6 @@ With multiple lines.',
'operations' => 'operations' =>
array( 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( array(
'method' => 'GET', 'method' => 'GET',
'summary' => 'index action', 'summary' => 'index action',
@ -1006,45 +977,6 @@ With multiple lines.',
'responseMessages' => 'responseMessages' =>
array(), 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 class DunglasApiParserTest extends WebTestCase
{ {
protected function setUp() protected function setUp(): void
{ {
if (!class_exists('Dunglas\ApiBundle\DunglasApiBundle')) { if (!class_exists('Dunglas\ApiBundle\DunglasApiBundle')) {
$this->markTestSkipped( $this->markTestSkipped(

View File

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

View File

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

View File

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

View File

@ -20,8 +20,9 @@ use Symfony\Component\HttpKernel\Kernel;
class ValidationParserTest extends WebTestCase class ValidationParserTest extends WebTestCase
{ {
protected $handler; protected $handler;
private ValidationParser $parser;
public function setUp() public function setUp(): void
{ {
$container = $this->getContainer(); $container = $this->getContainer();

View File

@ -11,6 +11,6 @@
namespace Nelmio\ApiDocBundle\Tests; 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; namespace Nelmio\ApiDocBundle\Tests;
use PHPUnit\Util\ErrorHandler;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\KernelInterface;
abstract class WebTestCase extends BaseWebTestCase abstract class WebTestCase extends BaseWebTestCase
{ {
public static $container; public static $container;
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); 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) { if ($errorNumber & E_USER_DEPRECATED) {
return true; return true;
} }
return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line); return ErrorHandler::handleError($errorNumber, $message, $file, $line);
} }
/** protected static function getKernelClass(): string
* @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()
{ {
require_once __DIR__.'/Fixtures/app/AppKernel.php'; require_once __DIR__.'/Fixtures/app/AppKernel.php';
return 'Nelmio\ApiDocBundle\Tests\Functional\AppKernel'; return 'Nelmio\ApiDocBundle\Tests\Functional\AppKernel';
} }
protected static function createKernel(array $options = array()) protected static function createKernel(array $options = array()): KernelInterface
{ {
$class = self::getKernelClass(); $class = self::getKernelClass();

View File

@ -15,12 +15,25 @@
} }
], ],
"require": { "require": {
"php": ">=7.1", "php": ">=8.1",
"symfony/twig-bundle": "~2.3|~3.0|~4.0|~5.0", "symfony/form": "^5.0|^6.0",
"symfony/framework-bundle": "~2.3|~3.0|~4.0|~5.0", "symfony/twig-bundle": "^5.0|^6.0",
"symfony/console": "~2.3|~3.0|~4.0|~5.0", "symfony/framework-bundle": "^5.0|^6.0",
"symfony/console": "^5.0|^6.0",
"michelf/php-markdown": "~1.4" "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": { "conflict": {
"jms/serializer": "<0.12", "jms/serializer": "<0.12",
"jms/serializer-bundle": "<0.11", "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" backupGlobals = "false"
backupStaticAttributes = "false" backupStaticAttributes = "false"
colors = "true" colors = "true"
convertDeprecationsToExceptions = "true"
convertErrorsToExceptions = "true" convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true" convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true" convertWarningsToExceptions = "true"
processIsolation = "false" processIsolation = "false"
stopOnFailure = "false" stopOnFailure = "false"
syntaxCheck = "false"
bootstrap = "Tests/bootstrap.php"> bootstrap = "Tests/bootstrap.php">
<testsuites> <testsuites>
@ -16,15 +16,4 @@
<directory>Tests</directory> <directory>Tests</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>
<filter>
<whitelist>
<directory>.</directory>
<exclude>
<directory>Resources</directory>
<directory>Tests</directory>
<directory>vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit> </phpunit>