NelmioApiDocBundle/Tests/Functional/SwaggerPHPApiComplianceTest.php

47 lines
1.2 KiB
PHP
Raw Normal View History

2022-04-30 20:06:37 +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;
use Nelmio\ApiDocBundle\OpenApiPhp\Util;
use OpenApi\Analysis;
2022-04-30 20:13:55 +02:00
use OpenApi\Context;
2022-04-30 20:06:37 +02:00
class SwaggerPHPApiComplianceTest extends WebTestCase
{
protected function setUp(): void
{
parent::setUp();
static::createClient([], ['HTTP_HOST' => 'api.example.com']);
}
public function testAllContextsHaveSameRoot()
{
2022-04-30 20:13:55 +02:00
// zircote/swagger-php < 4.2 support
$getRootContext = \Closure::bind(function (Context $context) use (&$getRootContext) {
if (null !== $context->_parent) {
return $getRootContext($context->_parent);
}
return $context;
}, null, Context::class);
2022-04-30 20:06:37 +02:00
$openApi = $this->getOpenApiDefinition();
$root = $openApi->_context;
$counter = 0;
foreach ((new Analysis([$openApi], Util::createContext()))->annotations as $annotation) {
2022-04-30 20:13:55 +02:00
$this->assertSame($getRootContext($annotation->_context), $root);
2022-04-30 20:06:37 +02:00
}
}
}