NelmioApiDocBundle/Tests/Functional/JMSFunctionalTest.php

123 lines
3.7 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 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',
],
],
'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',
],
2017-06-25 15:40:07 +02:00
],
], $this->getModel('JMSUser')->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());
}
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);
}
}