From 5cbcba78df5bdab6aa8b67964228925f5ea6bcaf Mon Sep 17 00:00:00 2001 From: Ilyas Salikhov Date: Tue, 18 Jun 2024 12:30:31 +0300 Subject: [PATCH] Symfony 6 compability --- .github/workflows/ci.yml | 1 + Command/DumpCommand.php | 18 +++--- Tests/Extractor/ApiDocExtractorTest.php | 2 +- .../Extractor/Handler/FosRestHandlerTest.php | 18 ------ Tests/Fixtures/Controller/TestController.php | 8 --- Tests/Fixtures/RequestParamHelper.php | 31 ----------- Tests/Fixtures/app/config/default.yml | 2 - Tests/Formatter/MarkdownFormatterTest.php | 2 +- Tests/Formatter/testFormat-result_1.markdown | 13 +---- Tests/Formatter/testFormat-result_1.php | 55 ++++++------------- Tests/WebTestCase.php | 26 +-------- composer.json | 18 +++--- 12 files changed, 40 insertions(+), 154 deletions(-) delete mode 100644 Tests/Fixtures/RequestParamHelper.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ba3f1c8..6bc496f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,7 @@ jobs: - '8.1' symfony-version: - '5.4.*' + - '6.4.*' coverage: [ 'none' ] steps: - name: "Checkout" diff --git a/Command/DumpCommand.php b/Command/DumpCommand.php index ca67526..69378e1 100644 --- a/Command/DumpCommand.php +++ b/Command/DumpCommand.php @@ -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) : diff --git a/Tests/Extractor/ApiDocExtractorTest.php b/Tests/Extractor/ApiDocExtractorTest.php index 3a11692..0bf31ad 100644 --- a/Tests/Extractor/ApiDocExtractorTest.php +++ b/Tests/Extractor/ApiDocExtractorTest.php @@ -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 diff --git a/Tests/Extractor/Handler/FosRestHandlerTest.php b/Tests/Extractor/Handler/FosRestHandlerTest.php index 616bb2e..227d3b8 100644 --- a/Tests/Extractor/Handler/FosRestHandlerTest.php +++ b/Tests/Extractor/Handler/FosRestHandlerTest.php @@ -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(); diff --git a/Tests/Fixtures/Controller/TestController.php b/Tests/Fixtures/Controller/TestController.php index 5ea6a8d..38200dd 100644 --- a/Tests/Fixtures/Controller/TestController.php +++ b/Tests/Fixtures/Controller/TestController.php @@ -200,14 +200,6 @@ class TestController { } - /** - * @ApiDoc() - * @RequestParamHelper(name="param1", requirements="string", array=true) - */ - public function zActionWithArrayRequestParamAction() - { - } - /** * @ApiDoc() */ diff --git a/Tests/Fixtures/RequestParamHelper.php b/Tests/Fixtures/RequestParamHelper.php deleted file mode 100644 index d8f6a9d..0000000 --- a/Tests/Fixtures/RequestParamHelper.php +++ /dev/null @@ -1,31 +0,0 @@ - $value) { - if ($key === 'array') { - if (property_exists($this, 'map')) { - $this->map = $value; - } else { - $this->array = $value; - } - } else { - $this->$key = $value; - } - } - } -} diff --git a/Tests/Fixtures/app/config/default.yml b/Tests/Fixtures/app/config/default.yml index 612ed15..0e4ecaf 100644 --- a/Tests/Fixtures/app/config/default.yml +++ b/Tests/Fixtures/app/config/default.yml @@ -8,8 +8,6 @@ framework: enabled: true test: ~ default_locale: en - session: - storage_id: session.storage.mock_file profiler: { only_exceptions: false } annotations: ~ diff --git a/Tests/Formatter/MarkdownFormatterTest.php b/Tests/Formatter/MarkdownFormatterTest.php index dfbae27..3e17827 100644 --- a/Tests/Formatter/MarkdownFormatterTest.php +++ b/Tests/Formatter/MarkdownFormatterTest.php @@ -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() diff --git a/Tests/Formatter/testFormat-result_1.markdown b/Tests/Formatter/testFormat-result_1.markdown index c9cba11..f023860 100644 --- a/Tests/Formatter/testFormat-result_1.markdown +++ b/Tests/Formatter/testFormat-result_1.markdown @@ -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 ### @@ -928,4 +917,4 @@ related[b]: #### Requirements #### -**_format** \ No newline at end of file +**_format** diff --git a/Tests/Formatter/testFormat-result_1.php b/Tests/Formatter/testFormat-result_1.php index b678389..798b905 100644 --- a/Tests/Formatter/testFormat-result_1.php +++ b/Tests/Formatter/testFormat-result_1.php @@ -1942,30 +1942,7 @@ 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 => + 11 => 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}', @@ -2511,4 +2488,4 @@ With multiple lines.', 'deprecated' => false, ), ), -); \ No newline at end of file +); diff --git a/Tests/WebTestCase.php b/Tests/WebTestCase.php index c4f6194..203d1a0 100644 --- a/Tests/WebTestCase.php +++ b/Tests/WebTestCase.php @@ -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(); diff --git a/composer.json b/composer.json index 8788b80..865536d 100644 --- a/composer.json +++ b/composer.json @@ -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",