66 lines
2.2 KiB
PHP
Raw Normal View History

<?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 OpenApi\Annotations as OA;
class FOSRestTest extends WebTestCase
{
protected function setUp(): void
{
parent::setUp();
static::createClient([], ['HTTP_HOST' => 'api.example.com']);
}
public function testFOSRestAction()
{
$operation = $this->getOperation('/api/fosrest', 'post');
$this->assertHasParameter('foo', 'query', $operation);
$this->assertInstanceOf(OA\RequestBody::class, $operation->requestBody);
2020-09-01 16:42:55 +02:00
$bodySchema = $operation->requestBody->content['application/json']->schema;
$this->assertHasProperty('bar', $bodySchema);
$this->assertHasProperty('baz', $bodySchema);
$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);
2020-11-03 10:10:31 +01:00
$mappedParameter = $this->getParameter($operation, 'mapped[]', 'query');
$this->assertTrue($mappedParameter->explode);
$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);
2021-03-16 10:42:37 +01:00
$dateTimeProperty = $this->getProperty($bodySchema, 'datetime');
$this->assertEquals('date-time', $dateTimeProperty->format);
2021-03-16 10:40:12 +01:00
2021-03-16 11:05:00 +01:00
$dateTimeAltProperty = $this->getProperty($bodySchema, 'datetimeAlt');
$this->assertEquals('date-time', $dateTimeAltProperty->format);
2021-03-16 10:42:37 +01:00
$dateProperty = $this->getProperty($bodySchema, 'date');
$this->assertEquals('date', $dateProperty->format);
2021-03-16 10:40:12 +01:00
// The _format path attribute should be removed
$this->assertNotHasParameter('_format', 'path', $operation);
}
}