NelmioApiDocBundle/Tests/Functional/JMSFunctionalTest.php

260 lines
8.2 KiB
PHP
Raw Normal View History

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
{
public function testModelPictureDocumentation()
{
$this->assertEquals([
'type' => 'object',
'properties' => [
'only_direct_picture_mini' => [
'type' => 'integer',
],
],
], $this->getModel('JMSPicture')->toArray());
}
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' => [
'$ref' => '#/definitions/JMSPicture',
],
],
], $this->getModel('JMSChatUser')->toArray());
}
2017-06-25 15:40:07 +02:00
public function testModelDocumentation()
{
$this->assertEquals([
'type' => 'object',
'properties' => [
'id' => [
'type' => 'integer',
2017-12-17 10:44:07 +01:00
'description' => 'User id',
'readOnly' => true,
2017-12-17 10:44:07 +01:00
'title' => 'userid',
'example' => 1,
],
'daysOnline' => [
'type' => 'integer',
'default' => 0,
'minimum' => 1,
'maximum' => 300,
],
'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',
'example' => '["ADMIN","SUPERUSER"]',
2017-06-25 15:40:07 +02:00
'items' => ['type' => 'string'],
'default' => ['user'],
'description' => 'Roles list',
2017-06-25 15:40:07 +02:00
],
'friendsNumber' => [
'type' => 'string',
'maxLength' => 100,
'minLength' => 1,
],
2017-06-25 15:40:07 +02:00
'friends' => [
'type' => 'array',
'items' => [
'$ref' => '#/definitions/User',
],
],
'indexed_friends' => [
'type' => 'object',
'additionalProperties' => [
'$ref' => '#/definitions/User',
],
],
'favorite_dates' => [
'type' => 'object',
'additionalProperties' => [
'type' => 'string',
'format' => 'date-time',
],
],
'custom_date' => [
'type' => 'string',
'format' => 'date-time',
],
2017-06-25 15:40:07 +02:00
'best_friend' => [
'$ref' => '#/definitions/User',
],
'status' => [
'type' => 'string',
'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'],
],
2018-02-19 21:41:05 +01:00
'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,
],
],
],
2017-06-25 15:40:07 +02:00
],
], $this->getModel('JMSUser')->toArray());
}
public function testModelComplexDualDocumentation()
{
$this->assertEquals([
'type' => 'object',
'properties' => [
'id' => [
'type' => 'integer',
],
'complex' => [
'$ref' => '#/definitions/JMSComplex2',
],
'user' => [
'$ref' => '#/definitions/JMSUser',
],
],
], $this->getModel('JMSDualComplex')->toArray());
}
2017-12-07 14:00:40 +08:00
public function testModelComplexDocumentation()
{
$this->assertEquals([
'type' => 'object',
'properties' => [
'id' => ['type' => 'integer'],
2017-12-07 14:00:40 +08:00
'user' => ['$ref' => '#/definitions/JMSUser2'],
2018-01-04 11:34:23 +01:00
'name' => ['type' => 'string'],
'virtual' => ['$ref' => '#/definitions/JMSUser'],
2017-12-07 14:00:40 +08:00
],
'required' => [
'id',
'user',
],
2017-12-07 14:00:40 +08:00
], $this->getModel('JMSComplex')->toArray());
$this->assertEquals([
'type' => 'object',
'properties' => [
'id' => [
'type' => 'integer',
'title' => 'userid',
'description' => 'User id',
'readOnly' => true,
'example' => '1',
],
],
], $this->getModel('JMSUser2')->toArray());
}
2017-12-07 14:00:40 +08:00
public function testYamlConfig()
{
$this->assertEquals([
'type' => 'object',
'properties' => [
'id' => [
'type' => 'integer',
],
'email' => [
2017-12-17 10:44:07 +01:00
'type' => 'string',
],
],
], $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);
}
}