NelmioApiDocBundle/Tests/Functional/JMSFunctionalTest.php
Filip Benčo 78664ef9ec
OpenApi 3 Support (#1623)
* Initial pass for OA3 upgrade

* Fix Util Tests

* Fix first batch of Unit Tests. Up to Model

* Another batch of fixed tests

* Update annotations

* Convert Model & Property Describers

* Update tests, Fix RouteDescribers, FIx additional bugs

* Another batch of updates

* Another batch of fixed Functional Tests

* Fix FunctionalTest tests

* Fix Bazinga Tests

* FIx FOS Rest

* Fix JMS TEsts & describers

* Fix all Tests

* Fix few stuff from own CR

* CS Fixes

* CS Fixes 2

* CS Fixes 3

* CS Fixes 4

* Remove collection bug

* Updates after first CRs

* CS

* Drop support for SF3

* Update the docs

* Add an upgrade guide

* misc doc fixes

* Configurable media types

* Code Style Fixes

* Don't use ::$ref for @Response and @RequestBody

* Fix upgrading guide

* Fix OA case

Co-authored-by: Filip Benčo <filip.benco@websupport.sk>
Co-authored-by: Guilhem Niot <guilhem.niot@gmail.com>
Co-authored-by: Mantis Development <mantis@users.noreply.github.com>
2020-05-28 13:19:11 +02:00

322 lines
11 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;
class JMSFunctionalTest extends WebTestCase
{
protected function setUp()
{
parent::setUp();
static::createClient([], ['HTTP_HOST' => 'api.example.com']);
}
public function testModelPictureDocumentation()
{
$this->assertEquals([
'type' => 'object',
'properties' => [
'id' => [
'type' => 'integer',
],
],
'schema' => 'JMSPicture',
], json_decode($this->getModel('JMSPicture')->toJson(), true));
$this->assertEquals([
'type' => 'object',
'properties' => [
'only_direct_picture_mini' => [
'type' => 'integer',
],
],
'schema' => 'JMSPicture_mini',
], json_decode($this->getModel('JMSPicture_mini')->toJson(), true));
}
public function testModeChatDocumentation()
{
$this->assertEquals([
'type' => 'object',
'properties' => [
'id' => [
'type' => 'integer',
],
'members' => [
'items' => [
'$ref' => '#/components/schemas/JMSChatUser',
],
'type' => 'array',
],
],
'schema' => 'JMSChat',
], json_decode($this->getModel('JMSChat')->toJson(), true));
$this->assertEquals([
'type' => 'object',
'properties' => [
'picture' => [
'$ref' => '#/components/schemas/JMSPicture',
],
],
'schema' => 'JMSChatUser',
], json_decode($this->getModel('JMSChatUser')->toJson(), true));
}
public function testModelDocumentation()
{
$this->assertEquals([
'type' => 'object',
'properties' => [
'id' => [
'type' => 'integer',
'description' => 'User id',
'readOnly' => true,
'title' => 'userid',
'example' => 1,
'default' => null,
],
'daysOnline' => [
'type' => 'integer',
'default' => 0,
'minimum' => 1,
'maximum' => 300,
],
'email' => [
'type' => 'string',
'readOnly' => false,
],
'roles' => [
'type' => 'array',
'title' => 'roles',
'example' => '["ADMIN","SUPERUSER"]',
'items' => ['type' => 'string'],
'default' => ['user'],
'description' => 'Roles list',
],
'friendsNumber' => [
'type' => 'string',
'maxLength' => 100,
'minLength' => 1,
],
'friends' => [
'type' => 'array',
'items' => [
'$ref' => '#/components/schemas/User',
],
],
'indexed_friends' => [
'type' => 'object',
'additionalProperties' => [
'$ref' => '#/components/schemas/User',
],
],
'favorite_dates' => [
'type' => 'object',
'additionalProperties' => [
'type' => 'string',
'format' => 'date-time',
],
],
'custom_date' => [
'type' => 'string',
'format' => 'date-time',
],
'best_friend' => [
'$ref' => '#/components/schemas/User',
],
'status' => [
'type' => 'string',
'title' => 'Whether this user is enabled or disabled.',
'description' => 'Only enabled users may be used in actions.',
'enum' => ['disabled', 'enabled'],
],
'virtual_type1' => [
'title' => 'JMS custom types handled via Custom Type Handlers.',
'$ref' => '#/components/schemas/VirtualTypeClassDoesNotExistsHandlerDefined',
],
'virtual_type2' => [
'title' => 'JMS custom types handled via Custom Type Handlers.',
'$ref' => '#/components/schemas/VirtualTypeClassDoesNotExistsHandlerNotDefined',
],
'last_update' => [
'type' => 'date',
],
'lat_lon_history' => [
'type' => 'array',
'items' => [
'type' => 'array',
'items' => [
'type' => 'number',
'format' => 'float',
],
],
],
'free_form_object_without_type' => [
'type' => 'object',
'additionalProperties' => true,
],
'free_form_object' => [
'type' => 'object',
'additionalProperties' => true,
],
'deep_object' => [
'type' => 'object',
'additionalProperties' => [
'type' => 'object',
'additionalProperties' => [
'type' => 'string',
'format' => 'date-time',
],
],
],
'deep_object_with_items' => [
'type' => 'object',
'additionalProperties' => [
'type' => 'array',
'items' => [
'type' => 'string',
'format' => 'date-time',
],
],
],
'deep_free_form_object_collection' => [
'type' => 'array',
'items' => [
'type' => 'array',
'items' => [
'type' => 'object',
'additionalProperties' => true,
],
],
],
'long' => [
'type' => 'string',
],
'short' => [
'type' => 'integer',
],
],
'schema' => 'JMSUser',
], json_decode($this->getModel('JMSUser')->toJson(), true));
$this->assertEquals([
'schema' => 'VirtualTypeClassDoesNotExistsHandlerNotDefined',
], json_decode($this->getModel('VirtualTypeClassDoesNotExistsHandlerNotDefined')->toJson(), true));
$this->assertEquals([
'type' => 'object',
'properties' => [
'custom_prop' => [
'type' => 'string',
],
],
'schema' => 'VirtualTypeClassDoesNotExistsHandlerDefined',
], json_decode($this->getModel('VirtualTypeClassDoesNotExistsHandlerDefined')->toJson(), true));
}
public function testModelComplexDualDocumentation()
{
$this->assertEquals([
'type' => 'object',
'properties' => [
'id' => [
'type' => 'integer',
],
'complex' => [
'$ref' => '#/components/schemas/JMSComplex2',
],
'user' => [
'$ref' => '#/components/schemas/JMSUser',
],
],
'schema' => 'JMSDualComplex',
], json_decode($this->getModel('JMSDualComplex')->toJson(), true));
}
public function testNestedGroups()
{
$this->assertEquals([
'type' => 'object',
'properties' => [
'living' => ['$ref' => '#/components/schemas/JMSChatLivingRoom'],
'dining' => ['$ref' => '#/components/schemas/JMSChatRoom'],
],
'schema' => 'JMSChatFriend',
], json_decode($this->getModel('JMSChatFriend')->toJson(), true));
$this->assertEquals([
'type' => 'object',
'properties' => [
'id1' => ['type' => 'integer'],
'id3' => ['type' => 'integer'],
],
'schema' => 'JMSChatRoom',
], json_decode($this->getModel('JMSChatRoom')->toJson(), true));
}
public function testModelComplexDocumentation()
{
$this->assertEquals([
'type' => 'object',
'properties' => [
'id' => ['type' => 'integer'],
'user' => ['$ref' => '#/components/schemas/JMSUser'],
'name' => ['type' => 'string'],
'virtual' => ['$ref' => '#/components/schemas/JMSUser'],
],
'required' => [
'id',
'user',
],
'schema' => 'JMSComplex',
], json_decode($this->getModel('JMSComplex')->toJson(), true));
}
public function testYamlConfig()
{
$this->assertEquals([
'type' => 'object',
'properties' => [
'id' => [
'type' => 'integer',
],
'email' => [
'type' => 'string',
],
],
'schema' => 'VirtualProperty',
], json_decode($this->getModel('VirtualProperty')->toJson(), true));
}
public function testNamingStrategyWithConstraints()
{
$this->assertEquals([
'type' => 'object',
'properties' => [
'beautifulName' => [
'type' => 'string',
'maxLength' => '10',
'minLength' => '3',
],
],
'required' => ['beautifulName'],
'schema' => 'JMSNamingStrategyConstraints',
], json_decode($this->getModel('JMSNamingStrategyConstraints')->toJson(), true));
}
protected static function createKernel(array $options = [])
{
return new TestKernel(true);
}
}