Mantis Development 239a26d014
Fix Declaration must be compatible error with tests (#1638)
* Fix Declaration must be compatible error with tests

* Fix phpunit deprecation warnings for @expectedExceptions

* Add phpunit.bat for windows users, bump phpunit to version 7.5
2020-05-31 15:16:51 +02:00

59 lines
1.9 KiB
PHP

<?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;
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()
{
if (!class_exists(FOSRestBundle::class)) {
$this->markTestSkipped('FOSRestBundle is not installed.');
}
$operation = $this->getOperation('/api/fosrest', 'post');
$this->assertHasParameter('foo', 'query', $operation);
$this->assertInstanceOf(OA\RequestBody::class, $operation->requestBody);
$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);
$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);
// The _format path attribute should be removed
$this->assertNotHasParameter('_format', 'path', $operation);
}
}