Symfony 6 compability

This commit is contained in:
Ilyas Salikhov 2024-06-18 12:30:31 +03:00
parent 72441d6bf3
commit 5cbcba78df
12 changed files with 40 additions and 154 deletions

View File

@ -17,6 +17,7 @@ jobs:
- '8.1'
symfony-version:
- '5.4.*'
- '6.4.*'
coverage: [ 'none' ]
steps:
- name: "Checkout"

View File

@ -18,7 +18,8 @@ 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\HttpFoundation\Request;
use Symfony\Contracts\Translation\LocaleAwareInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
#[AsCommand(
name: 'api:doc:dump',
@ -31,8 +32,12 @@ class DumpCommand extends Command
*/
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);
@ -58,9 +63,7 @@ class DumpCommand extends Command
$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)) {
@ -71,7 +74,7 @@ class DumpCommand extends Command
}
if ($input->hasOption('locale')) {
$this->container->get('translator')->setLocale($input->getOption('locale') ?? '');
$this->translator->setLocale($input->getOption('locale') ?? '');
}
if ($input->hasOption('api-version')) {
@ -82,11 +85,6 @@ class DumpCommand extends Command
$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

@ -19,7 +19,7 @@ class ApiDocExtractorTest extends WebTestCase
{
const NB_ROUTES_ADDED_BY_DUNGLAS_API_BUNDLE = 5;
private static $ROUTES_QUANTITY_DEFAULT = 37; // Routes in the default 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

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

@ -200,14 +200,6 @@ class TestController
{
}
/**
* @ApiDoc()
* @RequestParamHelper(name="param1", requirements="string", array=true)
*/
public function zActionWithArrayRequestParamAction()
{
}
/**
* @ApiDoc()
*/

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

@ -8,8 +8,6 @@ framework:
enabled: true
test: ~
default_locale: en
session:
storage_id: session.storage.mock_file
profiler: { only_exceptions: false }
annotations: ~

View File

@ -32,7 +32,7 @@ class MarkdownFormatterTest extends WebTestCase
$expected = str_replace('DependencyType', 'dependency_type', $expected);
}
$this->assertEquals($expected, $result);
$this->assertEquals($expected, $result . "\n");
}
public function testFormatOne()

View File

@ -704,17 +704,6 @@ _Route with host placeholder_
- Requirement: \d+
### `POST` /z-action-with-array-request-param ###
#### Parameters ####
param1:
* type: string[]
* required: true
### `GET` /z-action-with-deprecated-indicator ###
### This method is deprecated ###

View File

@ -1943,29 +1943,6 @@ With multiple lines.',
'deprecated' => false,
),
11 =>
array (
'method' => 'POST',
'uri' => '/z-action-with-array-request-param',
'parameters' =>
array (
'param1' =>
array (
'required' => true,
'dataType' => 'string[]',
'actualType' => 'string',
'subType' => NULL,
'description' => NULL,
'readonly' => false,
),
),
'https' => false,
'authentication' => false,
'authenticationRoles' =>
array (
),
'deprecated' => false,
),
12 =>
array (
'method' => 'GET',
'uri' => '/z-action-with-deprecated-indicator',
@ -1976,7 +1953,7 @@ With multiple lines.',
),
'deprecated' => true,
),
13 =>
12 =>
array (
'method' => 'POST',
'uri' => '/z-action-with-nullable-request-param',
@ -1999,7 +1976,7 @@ With multiple lines.',
),
'deprecated' => false,
),
14 =>
13 =>
array (
'method' => 'GET',
'uri' => '/z-action-with-query-param',
@ -2019,7 +1996,7 @@ With multiple lines.',
),
'deprecated' => false,
),
15 =>
14 =>
array (
'method' => 'GET',
'uri' => '/z-action-with-query-param-no-default',
@ -2038,7 +2015,7 @@ With multiple lines.',
),
'deprecated' => false,
),
16 =>
15 =>
array (
'method' => 'GET',
'uri' => '/z-action-with-query-param-strict',
@ -2058,7 +2035,7 @@ With multiple lines.',
),
'deprecated' => false,
),
17 =>
16 =>
array (
'method' => 'POST',
'uri' => '/z-action-with-request-param',
@ -2081,7 +2058,7 @@ With multiple lines.',
),
'deprecated' => false,
),
18 =>
17 =>
array (
'method' => 'GET',
'uri' => '/z-query-param-array-requirements',
@ -2100,7 +2077,7 @@ With multiple lines.',
),
'deprecated' => false,
),
19 =>
18 =>
array (
'method' => 'GET',
'uri' => '/z-query-param-plain-array-requirements',
@ -2119,7 +2096,7 @@ With multiple lines.',
),
'deprecated' => false,
),
20 =>
19 =>
array (
'method' => 'GET',
'uri' => '/z-query-requirement-param-not-set',
@ -2137,7 +2114,7 @@ With multiple lines.',
),
'deprecated' => false,
),
21 =>
20 =>
array (
'method' => 'ANY',
'uri' => '/z-return-jms-and-validator-output',
@ -2275,7 +2252,7 @@ With multiple lines.',
),
'deprecated' => false,
),
22 =>
21 =>
array (
'method' => 'ANY',
'uri' => '/z-return-selected-parsers-input',
@ -2329,7 +2306,7 @@ With multiple lines.',
),
'deprecated' => false,
),
23 =>
22 =>
array (
'method' => 'ANY',
'uri' => '/z-return-selected-parsers-output',
@ -2467,7 +2444,7 @@ With multiple lines.',
),
'deprecated' => false,
),
24 =>
23 =>
array (
'method' => 'POST',
'uri' => '/zcached',
@ -2479,7 +2456,7 @@ With multiple lines.',
),
'deprecated' => false,
),
25 =>
24 =>
array (
'method' => 'POST',
'uri' => '/zsecured',
@ -2490,7 +2467,7 @@ With multiple lines.',
),
'deprecated' => false,
),
26 =>
25 =>
array (
'method' => 'GET',
'uri' => '/zz-tests-route-version.{_format}',

View File

@ -15,6 +15,7 @@ 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
{
@ -38,35 +39,14 @@ abstract class WebTestCase extends BaseWebTestCase
return ErrorHandler::handleError($errorNumber, $message, $file, $line);
}
/**
* @param array $options
* @return ContainerInterface
*/
protected static function getContainer(array $options = array()): ContainerInterface
{
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

@ -16,10 +16,10 @@
],
"require": {
"php": ">=8.1",
"symfony/form": "^5.0",
"symfony/twig-bundle": "^5.0",
"symfony/framework-bundle": "^5.0",
"symfony/console": "^5.0",
"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": {
@ -28,11 +28,11 @@
"jms/serializer-bundle": "4.1.0",
"phpunit/phpunit": "~9.5",
"sensio/framework-extra-bundle": "^6.2",
"symfony/asset": "^5.0",
"symfony/browser-kit": "^5.0",
"symfony/translation": "^5.0",
"symfony/validator": "^5.0",
"symfony/yaml": "^5.0"
"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",