remove FOSRest on symfony 5 test runs as FOSRest does not support symfony 5 yet

This commit is contained in:
smoench 2019-12-20 10:49:22 +01:00
parent d458761251
commit 6f7c1fa870
No known key found for this signature in database
GPG Key ID: EB008C0F094A779B
6 changed files with 112 additions and 54 deletions

View File

@ -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

View File

@ -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.
*

View File

@ -0,0 +1,34 @@
<?php
/*
* This file is part of the NelmioApiDocBundle package.
*
* (c) Nelmio
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nelmio\ApiDocBundle\Tests\Functional\Controller;
use FOS\RestBundle\Controller\Annotations\QueryParam;
use FOS\RestBundle\Controller\Annotations\RequestParam;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Constraints\IsTrue;
use Symfony\Component\Validator\Constraints\Regex;
/**
* @Route("/api", host="api.example.com")
*/
class FOSRestController
{
/**
* @Route("/fosrest.{_format}", methods={"POST"})
* @QueryParam(name="foo", requirements=@Regex("/^\d+$/"))
* @RequestParam(name="bar", requirements="\d+")
* @RequestParam(name="baz", requirements=@IsTrue)
*/
public function fosrestAction()
{
}
}

View File

@ -0,0 +1,59 @@
<?php
/*
* This file is part of the NelmioApiDocBundle package.
*
* (c) Nelmio
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nelmio\ApiDocBundle\Tests\Functional;
use FOS\RestBundle\FOSRestBundle;
class FOSRestTest extends WebTestCase
{
protected function setUp()
{
parent::setUp();
static::createClient([], ['HTTP_HOST' => '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'));
}
}

View File

@ -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');

View File

@ -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', [