2019-12-20 10:49:22 +01:00
|
|
|
<?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;
|
2020-05-28 13:19:11 +02:00
|
|
|
use OpenApi\Annotations as OA;
|
2019-12-20 10:49:22 +01:00
|
|
|
|
|
|
|
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');
|
|
|
|
|
2020-05-28 13:19:11 +02:00
|
|
|
$this->assertHasParameter('foo', 'query', $operation);
|
|
|
|
$this->assertInstanceOf(OA\RequestBody::class, $operation->requestBody);
|
2019-12-20 10:49:22 +01:00
|
|
|
|
2020-05-28 13:19:11 +02:00
|
|
|
$bodySchema = $operation->requestBody->content['application\json']->schema;
|
2019-12-20 10:49:22 +01:00
|
|
|
|
2020-05-28 13:19:11 +02:00
|
|
|
$this->assertHasProperty('bar', $bodySchema);
|
|
|
|
$this->assertHasProperty('baz', $bodySchema);
|
2019-12-20 10:49:22 +01:00
|
|
|
|
2020-05-28 13:19:11 +02:00
|
|
|
$fooParameter = $this->getParameter($operation, 'foo', 'query');
|
|
|
|
$this->assertInstanceOf(OA\Schema::class, $fooParameter->schema);
|
|
|
|
$this->assertEquals('\d+', $fooParameter->schema->pattern);
|
|
|
|
$this->assertEquals(OA\UNDEFINED, $fooParameter->schema->format);
|
2019-12-20 10:49:22 +01:00
|
|
|
|
2020-05-28 13:19:11 +02:00
|
|
|
$barProperty = $this->getProperty($bodySchema, 'bar');
|
|
|
|
$this->assertEquals('\d+', $barProperty->pattern);
|
|
|
|
$this->assertEquals(OA\UNDEFINED, $barProperty->format);
|
|
|
|
|
|
|
|
$bazProperty = $this->getProperty($bodySchema, 'baz');
|
|
|
|
$this->assertEquals(OA\UNDEFINED, $bazProperty->pattern);
|
|
|
|
$this->assertEquals('IsTrue', $bazProperty->format);
|
2019-12-20 10:49:22 +01:00
|
|
|
|
|
|
|
// The _format path attribute should be removed
|
2020-05-28 13:19:11 +02:00
|
|
|
$this->assertNotHasParameter('_format', 'path', $operation);
|
2019-12-20 10:49:22 +01:00
|
|
|
}
|
|
|
|
}
|