mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 23:59:26 +03:00
remove FOSRest on symfony 5 test runs as FOSRest does not support symfony 5 yet
This commit is contained in:
parent
d458761251
commit
6f7c1fa870
@ -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
|
||||
|
@ -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.
|
||||
*
|
||||
|
34
Tests/Functional/Controller/FOSRestController.php
Normal file
34
Tests/Functional/Controller/FOSRestController.php
Normal 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()
|
||||
{
|
||||
}
|
||||
}
|
59
Tests/Functional/FOSRestTest.php
Normal file
59
Tests/Functional/FOSRestTest.php
Normal 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'));
|
||||
}
|
||||
}
|
@ -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');
|
||||
|
@ -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', [
|
||||
|
Loading…
x
Reference in New Issue
Block a user