2017-06-25 15:40:07 +02: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;
|
|
|
|
|
|
|
|
class JMSFunctionalTest extends WebTestCase
|
|
|
|
{
|
2019-12-19 15:41:14 +01:00
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
static::createClient([], ['HTTP_HOST' => 'api.example.com']);
|
|
|
|
}
|
|
|
|
|
2018-05-02 16:56:20 +02:00
|
|
|
public function testModelPictureDocumentation()
|
|
|
|
{
|
|
|
|
$this->assertEquals([
|
|
|
|
'type' => 'object',
|
|
|
|
'properties' => [
|
2019-03-11 12:53:35 +01:00
|
|
|
'id' => [
|
2018-05-02 16:56:20 +02:00
|
|
|
'type' => 'integer',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
], $this->getModel('JMSPicture')->toArray());
|
2019-03-11 12:53:35 +01:00
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
'type' => 'object',
|
|
|
|
'properties' => [
|
|
|
|
'only_direct_picture_mini' => [
|
|
|
|
'type' => 'integer',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
], $this->getModel('JMSPicture_mini')->toArray());
|
2018-05-02 16:56:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testModeChatDocumentation()
|
|
|
|
{
|
|
|
|
$this->assertEquals([
|
|
|
|
'type' => 'object',
|
|
|
|
'properties' => [
|
|
|
|
'id' => [
|
|
|
|
'type' => 'integer',
|
|
|
|
],
|
|
|
|
'members' => [
|
|
|
|
'items' => [
|
|
|
|
'$ref' => '#/definitions/JMSChatUser',
|
|
|
|
],
|
|
|
|
'type' => 'array',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
], $this->getModel('JMSChat')->toArray());
|
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
'type' => 'object',
|
|
|
|
'properties' => [
|
|
|
|
'picture' => [
|
2019-03-11 12:53:35 +01:00
|
|
|
'$ref' => '#/definitions/JMSPicture',
|
2018-05-02 16:56:20 +02:00
|
|
|
],
|
|
|
|
],
|
|
|
|
], $this->getModel('JMSChatUser')->toArray());
|
|
|
|
}
|
|
|
|
|
2017-06-25 15:40:07 +02:00
|
|
|
public function testModelDocumentation()
|
|
|
|
{
|
|
|
|
$this->assertEquals([
|
|
|
|
'type' => 'object',
|
|
|
|
'properties' => [
|
2017-12-03 20:30:44 +02:00
|
|
|
'id' => [
|
|
|
|
'type' => 'integer',
|
2017-12-17 10:44:07 +01:00
|
|
|
'description' => 'User id',
|
2017-12-03 20:30:44 +02:00
|
|
|
'readOnly' => true,
|
2017-12-17 10:44:07 +01:00
|
|
|
'title' => 'userid',
|
2017-12-03 20:30:44 +02:00
|
|
|
'example' => 1,
|
|
|
|
],
|
2017-12-17 17:58:41 +02:00
|
|
|
'daysOnline' => [
|
|
|
|
'type' => 'integer',
|
|
|
|
'default' => 0,
|
2018-01-24 15:20:20 +01:00
|
|
|
'minimum' => 1,
|
|
|
|
'maximum' => 300,
|
2017-12-17 17:58:41 +02:00
|
|
|
],
|
2017-12-03 20:30:44 +02:00
|
|
|
'email' => [
|
|
|
|
'type' => 'string',
|
|
|
|
'readOnly' => false,
|
|
|
|
],
|
2017-06-25 15:40:07 +02:00
|
|
|
'roles' => [
|
|
|
|
'type' => 'array',
|
2017-12-17 10:44:07 +01:00
|
|
|
'title' => 'roles',
|
2017-12-15 17:39:18 +01:00
|
|
|
'example' => '["ADMIN","SUPERUSER"]',
|
2017-06-25 15:40:07 +02:00
|
|
|
'items' => ['type' => 'string'],
|
2017-12-17 17:58:41 +02:00
|
|
|
'default' => ['user'],
|
|
|
|
'description' => 'Roles list',
|
2017-06-25 15:40:07 +02:00
|
|
|
],
|
2017-12-03 20:30:44 +02:00
|
|
|
'friendsNumber' => [
|
|
|
|
'type' => 'string',
|
2018-01-24 15:20:20 +01:00
|
|
|
'maxLength' => 100,
|
|
|
|
'minLength' => 1,
|
2017-12-03 20:30:44 +02:00
|
|
|
],
|
2017-06-25 15:40:07 +02:00
|
|
|
'friends' => [
|
|
|
|
'type' => 'array',
|
|
|
|
'items' => [
|
|
|
|
'$ref' => '#/definitions/User',
|
|
|
|
],
|
|
|
|
],
|
2018-04-21 16:57:37 +02:00
|
|
|
'indexed_friends' => [
|
|
|
|
'type' => 'object',
|
|
|
|
'additionalProperties' => [
|
|
|
|
'$ref' => '#/definitions/User',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'favorite_dates' => [
|
|
|
|
'type' => 'object',
|
|
|
|
'additionalProperties' => [
|
|
|
|
'type' => 'string',
|
|
|
|
'format' => 'date-time',
|
|
|
|
],
|
|
|
|
],
|
2018-05-03 13:36:24 -03:00
|
|
|
'custom_date' => [
|
|
|
|
'type' => 'string',
|
|
|
|
'format' => 'date-time',
|
|
|
|
],
|
2017-06-25 15:40:07 +02:00
|
|
|
'best_friend' => [
|
|
|
|
'$ref' => '#/definitions/User',
|
|
|
|
],
|
2017-12-17 17:58:41 +02:00
|
|
|
'status' => [
|
|
|
|
'type' => 'string',
|
2017-12-19 08:56:00 +01:00
|
|
|
'title' => 'Whether this user is enabled or disabled.',
|
|
|
|
'description' => 'Only enabled users may be used in actions.',
|
2017-12-18 21:07:44 +01:00
|
|
|
'enum' => ['disabled', 'enabled'],
|
2017-12-17 17:58:41 +02:00
|
|
|
],
|
2019-04-16 12:13:33 +02:00
|
|
|
'virtual_type1' => [
|
|
|
|
'$ref' => '#/definitions/VirtualTypeClassDoesNotExistsHandlerDefined',
|
|
|
|
],
|
|
|
|
'virtual_type2' => [
|
|
|
|
'$ref' => '#/definitions/VirtualTypeClassDoesNotExistsHandlerNotDefined',
|
|
|
|
],
|
2018-02-19 21:41:05 +01:00
|
|
|
'last_update' => [
|
2018-01-11 12:26:59 +01:00
|
|
|
'type' => 'date',
|
|
|
|
],
|
2018-07-23 13:35:05 -03:00
|
|
|
'lat_lon_history' => [
|
|
|
|
'type' => 'array',
|
|
|
|
'items' => [
|
|
|
|
'type' => 'array',
|
|
|
|
'items' => [
|
|
|
|
'type' => 'number',
|
|
|
|
'format' => 'float',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
2018-08-21 12:41:32 -03:00
|
|
|
'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,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
2020-05-07 20:00:01 +02:00
|
|
|
'long' => [
|
|
|
|
'type' => 'string',
|
|
|
|
],
|
|
|
|
'short' => [
|
|
|
|
'type' => 'integer',
|
|
|
|
],
|
2017-06-25 15:40:07 +02:00
|
|
|
],
|
|
|
|
], $this->getModel('JMSUser')->toArray());
|
2019-04-16 12:13:33 +02:00
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
], $this->getModel('VirtualTypeClassDoesNotExistsHandlerNotDefined')->toArray());
|
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
'type' => 'object',
|
|
|
|
'properties' => [
|
|
|
|
'custom_prop' => [
|
|
|
|
'type' => 'string',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
], $this->getModel('VirtualTypeClassDoesNotExistsHandlerDefined')->toArray());
|
2017-06-25 15:40:07 +02:00
|
|
|
}
|
|
|
|
|
2018-07-26 14:14:26 +02:00
|
|
|
public function testModelComplexDualDocumentation()
|
|
|
|
{
|
|
|
|
$this->assertEquals([
|
|
|
|
'type' => 'object',
|
|
|
|
'properties' => [
|
|
|
|
'id' => [
|
|
|
|
'type' => 'integer',
|
|
|
|
],
|
|
|
|
'complex' => [
|
|
|
|
'$ref' => '#/definitions/JMSComplex2',
|
|
|
|
],
|
|
|
|
'user' => [
|
|
|
|
'$ref' => '#/definitions/JMSUser',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
], $this->getModel('JMSDualComplex')->toArray());
|
|
|
|
}
|
|
|
|
|
2019-03-11 12:53:35 +01:00
|
|
|
public function testNestedGroups()
|
2019-01-26 14:52:13 +01:00
|
|
|
{
|
|
|
|
$this->assertEquals([
|
|
|
|
'type' => 'object',
|
|
|
|
'properties' => [
|
|
|
|
'living' => ['$ref' => '#/definitions/JMSChatLivingRoom'],
|
|
|
|
'dining' => ['$ref' => '#/definitions/JMSChatRoom'],
|
|
|
|
],
|
|
|
|
], $this->getModel('JMSChatFriend')->toArray());
|
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
'type' => 'object',
|
|
|
|
'properties' => [
|
|
|
|
'id1' => ['type' => 'integer'],
|
|
|
|
'id3' => ['type' => 'integer'],
|
|
|
|
],
|
|
|
|
], $this->getModel('JMSChatRoom')->toArray());
|
|
|
|
}
|
|
|
|
|
2017-12-07 14:00:40 +08:00
|
|
|
public function testModelComplexDocumentation()
|
|
|
|
{
|
|
|
|
$this->assertEquals([
|
|
|
|
'type' => 'object',
|
|
|
|
'properties' => [
|
2018-02-05 18:39:58 +01:00
|
|
|
'id' => ['type' => 'integer'],
|
2019-03-11 12:53:35 +01:00
|
|
|
'user' => ['$ref' => '#/definitions/JMSUser'],
|
2018-01-04 11:34:23 +01:00
|
|
|
'name' => ['type' => 'string'],
|
2018-03-17 19:23:29 +01:00
|
|
|
'virtual' => ['$ref' => '#/definitions/JMSUser'],
|
2017-12-07 14:00:40 +08:00
|
|
|
],
|
2018-01-24 15:20:20 +01:00
|
|
|
'required' => [
|
|
|
|
'id',
|
|
|
|
'user',
|
|
|
|
],
|
2017-12-07 14:00:40 +08:00
|
|
|
], $this->getModel('JMSComplex')->toArray());
|
2017-12-21 17:17:36 +01:00
|
|
|
}
|
2017-12-07 14:00:40 +08:00
|
|
|
|
2017-12-09 21:31:56 +08:00
|
|
|
public function testYamlConfig()
|
|
|
|
{
|
|
|
|
$this->assertEquals([
|
|
|
|
'type' => 'object',
|
|
|
|
'properties' => [
|
|
|
|
'id' => [
|
|
|
|
'type' => 'integer',
|
|
|
|
],
|
|
|
|
'email' => [
|
2017-12-17 10:44:07 +01:00
|
|
|
'type' => 'string',
|
2017-12-09 21:31:56 +08:00
|
|
|
],
|
|
|
|
],
|
|
|
|
], $this->getModel('VirtualProperty')->toArray());
|
|
|
|
}
|
|
|
|
|
2018-09-11 13:42:50 +03:00
|
|
|
public function testNamingStrategyWithConstraints()
|
|
|
|
{
|
|
|
|
$this->assertEquals([
|
|
|
|
'type' => 'object',
|
|
|
|
'properties' => [
|
|
|
|
'beautifulName' => [
|
|
|
|
'type' => 'string',
|
|
|
|
'maxLength' => '10',
|
|
|
|
'minLength' => '3',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'required' => ['beautifulName'],
|
|
|
|
], $this->getModel('JMSNamingStrategyConstraints')->toArray());
|
|
|
|
}
|
|
|
|
|
2017-12-22 17:42:18 +00:00
|
|
|
protected static function createKernel(array $options = [])
|
2017-06-25 15:40:07 +02:00
|
|
|
{
|
|
|
|
return new TestKernel(true);
|
|
|
|
}
|
|
|
|
}
|