From 6f7c1fa870550369dd8d080c17ac0a4a3f4e9ef3 Mon Sep 17 00:00:00 2001 From: smoench Date: Fri, 20 Dec 2019 10:49:22 +0100 Subject: [PATCH] remove FOSRest on symfony 5 test runs as FOSRest does not support symfony 5 yet --- .travis.yml | 1 + Tests/Functional/Controller/ApiController.php | 14 ----- .../Controller/FOSRestController.php | 34 +++++++++++ Tests/Functional/FOSRestTest.php | 59 +++++++++++++++++++ Tests/Functional/FunctionalTest.php | 31 ---------- Tests/Functional/TestKernel.php | 27 ++++++--- 6 files changed, 112 insertions(+), 54 deletions(-) create mode 100644 Tests/Functional/Controller/FOSRestController.php create mode 100644 Tests/Functional/FOSRestTest.php diff --git a/.travis.yml b/.travis.yml index 28c01b9..2047217 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,6 +29,7 @@ matrix: before_install: - phpenv config-rm xdebug.ini || true + - if [ "$SYMFONY_VERSION" == "^5.0" ]; then composer remove friendsofsymfony/rest-bundle --dev; fi; - if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --dev --no-update; fi; install: composer update --no-interaction $COMPOSER_FLAGS diff --git a/Tests/Functional/Controller/ApiController.php b/Tests/Functional/Controller/ApiController.php index c79eaab..985209b 100644 --- a/Tests/Functional/Controller/ApiController.php +++ b/Tests/Functional/Controller/ApiController.php @@ -11,8 +11,6 @@ namespace Nelmio\ApiDocBundle\Tests\Functional\Controller; -use FOS\RestBundle\Controller\Annotations\QueryParam; -use FOS\RestBundle\Controller\Annotations\RequestParam; use Nelmio\ApiDocBundle\Annotation\Areas; use Nelmio\ApiDocBundle\Annotation\Model; use Nelmio\ApiDocBundle\Annotation\Operation; @@ -24,8 +22,6 @@ use Nelmio\ApiDocBundle\Tests\Functional\Form\DummyType; use Nelmio\ApiDocBundle\Tests\Functional\Form\UserType; use Swagger\Annotations as SWG; use Symfony\Component\Routing\Annotation\Route; -use Symfony\Component\Validator\Constraints\IsTrue; -use Symfony\Component\Validator\Constraints\Regex; /** * @Route("/api", host="api.example.com") @@ -108,16 +104,6 @@ class ApiController { } - /** - * @Route("/fosrest.{_format}", methods={"POST"}) - * @QueryParam(name="foo", requirements=@Regex("/^\d+$/")) - * @RequestParam(name="bar", requirements="\d+") - * @RequestParam(name="baz", requirements=@IsTrue) - */ - public function fosrestAction() - { - } - /** * This action is deprecated. * diff --git a/Tests/Functional/Controller/FOSRestController.php b/Tests/Functional/Controller/FOSRestController.php new file mode 100644 index 0000000..651e45a --- /dev/null +++ b/Tests/Functional/Controller/FOSRestController.php @@ -0,0 +1,34 @@ + 'api.example.com']); + } + + public function testFOSRestAction() + { + if (!class_exists(FOSRestBundle::class)) { + $this->markTestSkipped('FOSRestBundle is not installed.'); + } + + $operation = $this->getOperation('/api/fosrest', 'post'); + + $parameters = $operation->getParameters(); + $this->assertTrue($parameters->has('foo', 'query')); + $this->assertTrue($parameters->has('body', 'body')); + $body = $parameters->get('body', 'body')->getSchema()->getProperties(); + + $this->assertTrue($body->has('bar')); + $this->assertTrue($body->has('baz')); + + $fooParameter = $parameters->get('foo', 'query'); + $this->assertNotNull($fooParameter->getPattern()); + $this->assertEquals('\d+', $fooParameter->getPattern()); + $this->assertNull($fooParameter->getFormat()); + + $barParameter = $body->get('bar'); + $this->assertNotNull($barParameter->getPattern()); + $this->assertEquals('\d+', $barParameter->getPattern()); + $this->assertNull($barParameter->getFormat()); + + $bazParameter = $body->get('baz'); + $this->assertNotNull($bazParameter->getFormat()); + $this->assertEquals('IsTrue', $bazParameter->getFormat()); + $this->assertNull($bazParameter->getPattern()); + + // The _format path attribute should be removed + $this->assertFalse($parameters->has('_format', 'path')); + } +} diff --git a/Tests/Functional/FunctionalTest.php b/Tests/Functional/FunctionalTest.php index c3ea09a..0c7fc20 100644 --- a/Tests/Functional/FunctionalTest.php +++ b/Tests/Functional/FunctionalTest.php @@ -126,37 +126,6 @@ class FunctionalTest extends WebTestCase $this->assertEmpty($parameter->getFormat()); } - public function testFOSRestAction() - { - $operation = $this->getOperation('/api/fosrest', 'post'); - - $parameters = $operation->getParameters(); - $this->assertTrue($parameters->has('foo', 'query')); - $this->assertTrue($parameters->has('body', 'body')); - $body = $parameters->get('body', 'body')->getSchema()->getProperties(); - - $this->assertTrue($body->has('bar')); - $this->assertTrue($body->has('baz')); - - $fooParameter = $parameters->get('foo', 'query'); - $this->assertNotNull($fooParameter->getPattern()); - $this->assertEquals('\d+', $fooParameter->getPattern()); - $this->assertNull($fooParameter->getFormat()); - - $barParameter = $body->get('bar'); - $this->assertNotNull($barParameter->getPattern()); - $this->assertEquals('\d+', $barParameter->getPattern()); - $this->assertNull($barParameter->getFormat()); - - $bazParameter = $body->get('baz'); - $this->assertNotNull($bazParameter->getFormat()); - $this->assertEquals('IsTrue', $bazParameter->getFormat()); - $this->assertNull($bazParameter->getPattern()); - - // The _format path attribute should be removed - $this->assertFalse($parameters->has('_format', 'path')); - } - public function testDeprecatedAction() { $operation = $this->getOperation('/api/deprecated', 'get'); diff --git a/Tests/Functional/TestKernel.php b/Tests/Functional/TestKernel.php index 862dd83..761478c 100644 --- a/Tests/Functional/TestKernel.php +++ b/Tests/Functional/TestKernel.php @@ -56,10 +56,13 @@ class TestKernel extends Kernel new SensioFrameworkExtraBundle(), new ApiPlatformBundle(), new NelmioApiDocBundle(), - new FOSRestBundle(), new TestBundle(), ]; + if (class_exists(FOSRestBundle::class)) { + $bundles[] = new FOSRestBundle(); + } + if ($this->useJMS) { $bundles[] = new JMSSerializerBundle(); @@ -84,6 +87,10 @@ class TestKernel extends Kernel $routes->add('/docs/{area}', 'nelmio_api_doc.controller.swagger_ui')->setDefault('area', 'default'); $routes->add('/docs.json', 'nelmio_api_doc.controller.swagger'); + if (class_exists(FOSRestBundle::class)) { + $routes->import(__DIR__.'/Controller/FOSRestController.php', '/', 'annotation'); + } + if ($this->useJMS) { $routes->import(__DIR__.'/Controller/JMSController.php', '/', 'annotation'); } @@ -134,16 +141,18 @@ class TestKernel extends Kernel 'mapping' => ['paths' => ['%kernel.project_dir%/Tests/Functional/Entity']], ]); - $c->loadFromExtension('fos_rest', [ - 'format_listener' => [ - 'rules' => [ - [ - 'path' => '^/', - 'fallback_format' => 'json', + if (class_exists(FOSRestBundle::class)) { + $c->loadFromExtension('fos_rest', [ + 'format_listener' => [ + 'rules' => [ + [ + 'path' => '^/', + 'fallback_format' => 'json', + ], ], ], - ], - ]); + ]); + } // Filter routes $c->loadFromExtension('nelmio_api_doc', [