2012-04-13 15:20:45 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the NelmioApiDocBundle.
|
|
|
|
*
|
|
|
|
* (c) Nelmio <hello@nelm.io>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Nelmio\ApiDocBundle\Tests\Annotation;
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
use Nelmio\ApiDocBundle\Attribute\ApiDoc;
|
2012-04-13 15:20:45 +02:00
|
|
|
use Nelmio\ApiDocBundle\Tests\TestCase;
|
2015-12-10 09:16:35 +01:00
|
|
|
use Symfony\Component\Routing\Route;
|
2012-04-13 15:20:45 +02:00
|
|
|
|
|
|
|
class ApiDocTest extends TestCase
|
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testConstructWithoutData(): void
|
2012-04-13 15:20:45 +02:00
|
|
|
{
|
2024-10-01 23:00:23 +03:00
|
|
|
$annot = new ApiDoc();
|
2012-07-20 00:58:58 +02:00
|
|
|
$array = $annot->toArray();
|
2012-04-13 15:20:45 +02:00
|
|
|
|
2012-07-20 00:58:58 +02:00
|
|
|
$this->assertTrue(is_array($array));
|
|
|
|
$this->assertFalse(isset($array['filters']));
|
2012-04-13 15:20:45 +02:00
|
|
|
$this->assertFalse($annot->isResource());
|
2015-05-16 12:17:59 +02:00
|
|
|
$this->assertEmpty($annot->getViews());
|
2013-03-18 08:40:03 +01:00
|
|
|
$this->assertFalse($annot->getDeprecated());
|
2012-07-20 00:58:58 +02:00
|
|
|
$this->assertFalse(isset($array['description']));
|
2013-07-17 20:41:27 +02:00
|
|
|
$this->assertFalse(isset($array['requirements']));
|
|
|
|
$this->assertFalse(isset($array['parameters']));
|
2012-07-23 15:44:37 -04:00
|
|
|
$this->assertNull($annot->getInput());
|
2016-05-19 18:20:41 +03:00
|
|
|
$this->assertFalse(isset($array['headers']));
|
2012-04-13 15:20:45 +02:00
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testConstructWithInvalidData(): void
|
2012-04-13 15:20:45 +02:00
|
|
|
{
|
2024-10-01 23:00:23 +03:00
|
|
|
$annot = new ApiDoc();
|
2012-07-20 00:58:58 +02:00
|
|
|
$array = $annot->toArray();
|
2012-04-13 15:20:45 +02:00
|
|
|
|
2012-07-20 00:58:58 +02:00
|
|
|
$this->assertTrue(is_array($array));
|
|
|
|
$this->assertFalse(isset($array['filters']));
|
2012-04-13 15:20:45 +02:00
|
|
|
$this->assertFalse($annot->isResource());
|
2013-03-18 08:40:03 +01:00
|
|
|
$this->assertFalse($annot->getDeprecated());
|
2012-07-20 00:58:58 +02:00
|
|
|
$this->assertFalse(isset($array['description']));
|
2013-07-17 20:41:27 +02:00
|
|
|
$this->assertFalse(isset($array['requirements']));
|
|
|
|
$this->assertFalse(isset($array['parameters']));
|
2012-07-23 15:44:37 -04:00
|
|
|
$this->assertNull($annot->getInput());
|
2012-04-13 15:20:45 +02:00
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testConstruct(): void
|
2012-04-13 15:20:45 +02:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$data = [
|
2012-04-13 15:20:45 +02:00
|
|
|
'description' => 'Heya',
|
2024-10-01 15:54:04 +03:00
|
|
|
];
|
2012-04-13 15:20:45 +02:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
$annot = new ApiDoc(description: $data['description']);
|
2012-07-20 00:58:58 +02:00
|
|
|
$array = $annot->toArray();
|
2012-04-13 15:20:45 +02:00
|
|
|
|
2012-07-20 00:58:58 +02:00
|
|
|
$this->assertTrue(is_array($array));
|
|
|
|
$this->assertFalse(isset($array['filters']));
|
2012-04-13 15:20:45 +02:00
|
|
|
$this->assertFalse($annot->isResource());
|
2013-03-18 08:40:03 +01:00
|
|
|
$this->assertFalse($annot->getDeprecated());
|
2012-07-20 00:58:58 +02:00
|
|
|
$this->assertEquals($data['description'], $array['description']);
|
2013-07-17 20:41:27 +02:00
|
|
|
$this->assertFalse(isset($array['requirements']));
|
|
|
|
$this->assertFalse(isset($array['parameters']));
|
2012-07-23 15:44:37 -04:00
|
|
|
$this->assertNull($annot->getInput());
|
2012-04-13 15:20:45 +02:00
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testConstructDefinesAFormType(): void
|
2012-04-13 15:20:45 +02:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$data = [
|
|
|
|
'description' => 'Heya',
|
|
|
|
'input' => 'My\Form\Type',
|
|
|
|
];
|
2012-04-13 15:20:45 +02:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
$annot = new ApiDoc(
|
|
|
|
description: $data['description'],
|
|
|
|
input: $data['input']
|
|
|
|
);
|
2012-07-20 00:58:58 +02:00
|
|
|
$array = $annot->toArray();
|
2012-04-13 15:20:45 +02:00
|
|
|
|
2012-07-20 00:58:58 +02:00
|
|
|
$this->assertTrue(is_array($array));
|
|
|
|
$this->assertFalse(isset($array['filters']));
|
2012-04-13 15:20:45 +02:00
|
|
|
$this->assertFalse($annot->isResource());
|
2013-03-18 08:40:03 +01:00
|
|
|
$this->assertFalse($annot->getDeprecated());
|
2012-07-20 00:58:58 +02:00
|
|
|
$this->assertEquals($data['description'], $array['description']);
|
2013-07-17 20:41:27 +02:00
|
|
|
$this->assertFalse(isset($array['requirements']));
|
|
|
|
$this->assertFalse(isset($array['parameters']));
|
2012-07-23 15:44:37 -04:00
|
|
|
$this->assertEquals($data['input'], $annot->getInput());
|
2012-04-13 15:20:45 +02:00
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testConstructMethodIsResource(): void
|
2012-04-13 15:20:45 +02:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$data = [
|
|
|
|
'resource' => true,
|
|
|
|
'description' => 'Heya',
|
|
|
|
'deprecated' => true,
|
|
|
|
'input' => 'My\Form\Type',
|
|
|
|
];
|
2012-04-13 15:20:45 +02:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
$annot = new ApiDoc(
|
|
|
|
resource: $data['resource'],
|
|
|
|
description: $data['description'],
|
|
|
|
deprecated: $data['deprecated'],
|
|
|
|
input: $data['input']
|
|
|
|
);
|
2012-07-20 00:58:58 +02:00
|
|
|
$array = $annot->toArray();
|
2012-04-13 15:20:45 +02:00
|
|
|
|
2012-07-20 00:58:58 +02:00
|
|
|
$this->assertTrue(is_array($array));
|
|
|
|
$this->assertFalse(isset($array['filters']));
|
2012-04-13 15:20:45 +02:00
|
|
|
$this->assertTrue($annot->isResource());
|
2013-03-18 08:40:03 +01:00
|
|
|
$this->assertTrue($annot->getDeprecated());
|
2012-07-20 00:58:58 +02:00
|
|
|
$this->assertEquals($data['description'], $array['description']);
|
2013-07-17 20:41:27 +02:00
|
|
|
$this->assertFalse(isset($array['requirements']));
|
|
|
|
$this->assertFalse(isset($array['parameters']));
|
2012-07-23 15:44:37 -04:00
|
|
|
$this->assertEquals($data['input'], $annot->getInput());
|
2012-04-13 15:20:45 +02:00
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testConstructMethodResourceIsFalse(): void
|
2012-04-13 15:20:45 +02:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$data = [
|
|
|
|
'resource' => false,
|
|
|
|
'description' => 'Heya',
|
|
|
|
'deprecated' => false,
|
|
|
|
'input' => 'My\Form\Type',
|
|
|
|
];
|
2012-04-13 15:20:45 +02:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
$annot = new ApiDoc(
|
|
|
|
resource: $data['resource'],
|
|
|
|
description: $data['description'],
|
|
|
|
deprecated: $data['deprecated'],
|
|
|
|
input: $data['input']
|
|
|
|
);
|
2012-07-20 00:58:58 +02:00
|
|
|
$array = $annot->toArray();
|
2012-04-13 15:20:45 +02:00
|
|
|
|
2012-07-20 00:58:58 +02:00
|
|
|
$this->assertTrue(is_array($array));
|
|
|
|
$this->assertFalse(isset($array['filters']));
|
2012-04-13 15:20:45 +02:00
|
|
|
$this->assertFalse($annot->isResource());
|
2012-07-20 00:58:58 +02:00
|
|
|
$this->assertEquals($data['description'], $array['description']);
|
2013-07-17 20:41:27 +02:00
|
|
|
$this->assertFalse(isset($array['requirements']));
|
|
|
|
$this->assertFalse(isset($array['parameters']));
|
2013-03-18 08:40:03 +01:00
|
|
|
$this->assertEquals($data['deprecated'], $array['deprecated']);
|
2012-07-23 15:44:37 -04:00
|
|
|
$this->assertEquals($data['input'], $annot->getInput());
|
2012-04-13 15:20:45 +02:00
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testConstructMethodHasFilters(): void
|
2012-04-13 15:20:45 +02:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$data = [
|
|
|
|
'resource' => true,
|
|
|
|
'deprecated' => false,
|
|
|
|
'description' => 'Heya',
|
|
|
|
'filters' => [
|
|
|
|
['name' => 'a-filter'],
|
|
|
|
],
|
|
|
|
];
|
2012-04-13 15:20:45 +02:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
$annot = new ApiDoc(
|
|
|
|
resource: $data['resource'],
|
|
|
|
description: $data['description'],
|
|
|
|
deprecated: $data['deprecated'],
|
|
|
|
filters: $data['filters']
|
|
|
|
);
|
2012-07-20 00:58:58 +02:00
|
|
|
$array = $annot->toArray();
|
2012-04-13 15:20:45 +02:00
|
|
|
|
2012-07-20 00:58:58 +02:00
|
|
|
$this->assertTrue(is_array($array));
|
|
|
|
$this->assertTrue(is_array($array['filters']));
|
|
|
|
$this->assertCount(1, $array['filters']);
|
2024-10-01 15:54:04 +03:00
|
|
|
$this->assertEquals(['a-filter' => []], $array['filters']);
|
2012-04-13 15:20:45 +02:00
|
|
|
$this->assertTrue($annot->isResource());
|
2012-07-20 00:58:58 +02:00
|
|
|
$this->assertEquals($data['description'], $array['description']);
|
2013-07-17 20:41:27 +02:00
|
|
|
$this->assertFalse(isset($array['requirements']));
|
|
|
|
$this->assertFalse(isset($array['parameters']));
|
2013-03-18 08:40:03 +01:00
|
|
|
$this->assertEquals($data['deprecated'], $array['deprecated']);
|
2012-07-23 15:44:37 -04:00
|
|
|
$this->assertNull($annot->getInput());
|
2012-04-13 15:20:45 +02:00
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testConstructMethodHasFiltersWithoutName(): void
|
2012-04-13 15:20:45 +02:00
|
|
|
{
|
2024-06-18 00:19:53 +03:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
$data = [
|
|
|
|
'description' => 'Heya',
|
|
|
|
'filters' => [
|
|
|
|
['parameter' => 'foo'],
|
|
|
|
],
|
|
|
|
];
|
2012-04-13 15:20:45 +02:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
$annot = new ApiDoc(
|
|
|
|
description: $data['description'],
|
|
|
|
filters: $data['filters']
|
|
|
|
);
|
2012-04-13 15:20:45 +02:00
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testConstructWithStatusCodes(): void
|
2012-11-13 04:45:07 +00:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$data = [
|
2012-11-13 04:45:07 +00:00
|
|
|
'description' => 'Heya',
|
2024-10-01 15:54:04 +03:00
|
|
|
'statusCodes' => [
|
|
|
|
200 => 'Returned when successful',
|
|
|
|
403 => 'Returned when the user is not authorized',
|
|
|
|
404 => [
|
|
|
|
'Returned when the user is not found',
|
|
|
|
'Returned when when something else is not found',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
2012-11-13 04:45:07 +00:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
$annot = new ApiDoc(
|
|
|
|
description: $data['description'],
|
|
|
|
statusCodes: $data['statusCodes']
|
|
|
|
);
|
2012-11-13 04:45:07 +00:00
|
|
|
$array = $annot->toArray();
|
|
|
|
|
|
|
|
$this->assertTrue(is_array($array));
|
|
|
|
$this->assertTrue(is_array($array['statusCodes']));
|
|
|
|
foreach ($data['statusCodes'] as $code => $message) {
|
2024-10-01 15:54:04 +03:00
|
|
|
$this->assertEquals($array['statusCodes'][$code], !is_array($message) ? [$message] : $message);
|
2012-11-13 04:45:07 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-26 12:23:28 +01:00
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testConstructWithRequirements(): void
|
2013-07-17 20:41:27 +02:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$data = [
|
|
|
|
'requirements' => [
|
|
|
|
[
|
2013-07-17 20:41:27 +02:00
|
|
|
'name' => 'fooId',
|
|
|
|
'requirement' => '\d+',
|
|
|
|
'dataType' => 'integer',
|
2024-10-01 15:54:04 +03:00
|
|
|
'description' => 'This requirement might be used withing action method directly from Request object',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
2013-07-17 20:41:27 +02:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
$annot = new ApiDoc(
|
|
|
|
requirements: $data['requirements']
|
|
|
|
);
|
2013-07-17 20:41:27 +02:00
|
|
|
$array = $annot->toArray();
|
|
|
|
|
|
|
|
$this->assertTrue(is_array($array));
|
|
|
|
$this->assertTrue(isset($array['requirements']['fooId']));
|
|
|
|
$this->assertTrue(isset($array['requirements']['fooId']['dataType']));
|
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testConstructWithParameters(): void
|
2013-07-17 20:41:27 +02:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$data = [
|
|
|
|
'parameters' => [
|
|
|
|
[
|
2013-07-17 20:41:27 +02:00
|
|
|
'name' => 'fooId',
|
|
|
|
'dataType' => 'integer',
|
2024-10-01 15:54:04 +03:00
|
|
|
'description' => 'Some description',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
2013-07-17 20:41:27 +02:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
$annot = new ApiDoc(
|
|
|
|
parameters: $data['parameters']
|
|
|
|
);
|
2013-07-17 20:41:27 +02:00
|
|
|
$array = $annot->toArray();
|
|
|
|
|
|
|
|
$this->assertTrue(is_array($array));
|
|
|
|
$this->assertTrue(isset($array['parameters']['fooId']));
|
|
|
|
$this->assertTrue(isset($array['parameters']['fooId']['dataType']));
|
|
|
|
}
|
2014-05-27 13:33:50 +02:00
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testConstructWithHeaders(): void
|
2016-05-19 18:20:41 +03:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$data = [
|
|
|
|
'headers' => [
|
|
|
|
[
|
2016-05-19 18:20:41 +03:00
|
|
|
'name' => 'headerName',
|
2024-10-01 15:54:04 +03:00
|
|
|
'description' => 'Some description',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
2016-05-19 18:20:41 +03:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
$annot = new ApiDoc(
|
|
|
|
headers: $data['headers']
|
|
|
|
);
|
2016-05-19 18:20:41 +03:00
|
|
|
$array = $annot->toArray();
|
|
|
|
|
|
|
|
$this->assertArrayHasKey('headerName', $array['headers']);
|
|
|
|
$this->assertNotEmpty($array['headers']['headerName']);
|
|
|
|
|
|
|
|
$keys = array_keys($array['headers']);
|
|
|
|
$this->assertEquals($data['headers'][0]['name'], $keys[0]);
|
|
|
|
$this->assertEquals($data['headers'][0]['description'], $array['headers']['headerName']['description']);
|
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testConstructWithOneTag(): void
|
2014-05-27 13:33:50 +02:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$data = [
|
|
|
|
'tags' => 'beta',
|
|
|
|
];
|
2014-05-27 13:33:50 +02:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
$annot = new ApiDoc(
|
|
|
|
tags: $data['tags']
|
|
|
|
);
|
2014-05-27 13:33:50 +02:00
|
|
|
$array = $annot->toArray();
|
|
|
|
|
|
|
|
$this->assertTrue(is_array($array));
|
|
|
|
$this->assertTrue(is_array($array['tags']), 'Single tag should be put in array');
|
2024-10-01 15:54:04 +03:00
|
|
|
$this->assertEquals(['beta'], $array['tags']);
|
2014-05-27 13:33:50 +02:00
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testConstructWithOneTagAndColorCode(): void
|
2014-07-19 13:43:39 +02:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$data = [
|
|
|
|
'tags' => [
|
|
|
|
'beta' => '#ff0000',
|
|
|
|
],
|
|
|
|
];
|
2014-07-19 13:43:39 +02:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
$annot = new ApiDoc(
|
|
|
|
tags: $data['tags']
|
|
|
|
);
|
2014-07-19 13:43:39 +02:00
|
|
|
$array = $annot->toArray();
|
|
|
|
|
|
|
|
$this->assertTrue(is_array($array));
|
|
|
|
$this->assertTrue(is_array($array['tags']), 'Single tag should be put in array');
|
2024-10-01 15:54:04 +03:00
|
|
|
$this->assertEquals(['beta' => '#ff0000'], $array['tags']);
|
2014-07-19 13:43:39 +02:00
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testConstructWithMultipleTags(): void
|
2014-05-27 13:33:50 +02:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$data = [
|
|
|
|
'tags' => [
|
2014-07-19 13:43:39 +02:00
|
|
|
'experimental' => '#0000ff',
|
|
|
|
'beta' => '#0000ff',
|
2024-10-01 15:54:04 +03:00
|
|
|
],
|
|
|
|
];
|
2014-05-27 13:33:50 +02:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
$annot = new ApiDoc(
|
|
|
|
tags: $data['tags']
|
|
|
|
);
|
2014-05-27 13:33:50 +02:00
|
|
|
$array = $annot->toArray();
|
|
|
|
|
|
|
|
$this->assertTrue(is_array($array));
|
|
|
|
$this->assertTrue(is_array($array['tags']), 'Tags should be in array');
|
|
|
|
$this->assertEquals($data['tags'], $array['tags']);
|
|
|
|
}
|
2014-06-17 17:05:00 -07:00
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testAlignmentOfOutputAndResponseModels(): void
|
2014-06-17 17:05:00 -07:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$data = [
|
2014-06-17 17:05:00 -07:00
|
|
|
'output' => 'FooBar',
|
2024-10-01 15:54:04 +03:00
|
|
|
'responseMap' => [
|
2014-06-17 17:05:00 -07:00
|
|
|
400 => 'Foo\\ValidationErrorCollection',
|
2024-10-01 15:54:04 +03:00
|
|
|
],
|
|
|
|
];
|
2014-06-17 17:05:00 -07:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
$apiDoc = new ApiDoc(
|
|
|
|
output: $data['output'],
|
|
|
|
responseMap: $data['responseMap']
|
|
|
|
);
|
2014-06-17 17:05:00 -07:00
|
|
|
|
|
|
|
$map = $apiDoc->getResponseMap();
|
|
|
|
|
|
|
|
$this->assertCount(2, $map);
|
|
|
|
$this->assertArrayHasKey(200, $map);
|
|
|
|
$this->assertArrayHasKey(400, $map);
|
|
|
|
$this->assertEquals($data['output'], $map[200]);
|
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testAlignmentOfOutputAndResponseModels2(): void
|
2014-06-17 17:05:00 -07:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$data = [
|
|
|
|
'responseMap' => [
|
2014-06-17 17:05:00 -07:00
|
|
|
200 => 'FooBar',
|
|
|
|
400 => 'Foo\\ValidationErrorCollection',
|
2024-10-01 15:54:04 +03:00
|
|
|
],
|
|
|
|
];
|
2014-06-17 17:05:00 -07:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
$apiDoc = new ApiDoc(
|
|
|
|
responseMap: $data['responseMap']
|
|
|
|
);
|
2014-06-17 17:05:00 -07:00
|
|
|
$map = $apiDoc->getResponseMap();
|
|
|
|
|
|
|
|
$this->assertCount(2, $map);
|
|
|
|
$this->assertArrayHasKey(200, $map);
|
|
|
|
$this->assertArrayHasKey(400, $map);
|
|
|
|
$this->assertEquals($apiDoc->getOutput(), $map[200]);
|
|
|
|
}
|
2015-12-10 09:16:35 +01:00
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function testSetRoute(): void
|
2015-12-10 09:16:35 +01:00
|
|
|
{
|
|
|
|
$route = new Route(
|
|
|
|
'/path/{foo}',
|
|
|
|
[
|
|
|
|
'foo' => 'bar',
|
|
|
|
'nested' => [
|
|
|
|
'key1' => 'value1',
|
|
|
|
'key2' => 'value2',
|
2024-10-01 15:54:04 +03:00
|
|
|
],
|
2015-12-10 09:16:35 +01:00
|
|
|
],
|
|
|
|
[],
|
|
|
|
[],
|
|
|
|
'{foo}.awesome_host.com'
|
|
|
|
);
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
$apiDoc = new ApiDoc();
|
2015-12-10 09:16:35 +01:00
|
|
|
$apiDoc->setRoute($route);
|
|
|
|
|
|
|
|
$this->assertSame($route, $apiDoc->getRoute());
|
|
|
|
$this->assertEquals('bar.awesome_host.com', $apiDoc->getHost());
|
|
|
|
$this->assertEquals('ANY', $apiDoc->getMethod());
|
|
|
|
}
|
2012-04-13 15:20:45 +02:00
|
|
|
}
|