2019-01-11 16:54:58 +01: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\Describer;
|
|
|
|
|
|
|
|
use ApiPlatform\Core\Documentation\Documentation;
|
|
|
|
use ApiPlatform\Core\Metadata\Resource\ResourceNameCollection;
|
|
|
|
use Nelmio\ApiDocBundle\Describer\ApiPlatformDescriber;
|
2020-05-28 13:19:11 +02:00
|
|
|
use OpenApi\Annotations\OpenApi;
|
2019-01-11 16:54:58 +01:00
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
|
|
|
|
|
|
|
class ApiPlatformDescriberTest extends AbstractDescriberTest
|
|
|
|
{
|
|
|
|
private $documentation;
|
|
|
|
|
|
|
|
private $normalizer;
|
|
|
|
|
|
|
|
public function testDescribe()
|
|
|
|
{
|
|
|
|
$this->normalizer->expects($this->once())
|
|
|
|
->method('normalize')
|
|
|
|
->with($this->documentation)
|
|
|
|
->willReturn(['info' => ['title' => 'My Test App']]);
|
|
|
|
|
2020-05-28 13:19:11 +02:00
|
|
|
$expectedApi = new OpenApi(['info' => ['title' => 'My Test App']]);
|
|
|
|
$this->assertEquals($expectedApi->toJson(), $this->getOpenApiDoc()->toJson());
|
2019-01-11 16:54:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDescribeRemovesBasePathAfterNormalization()
|
|
|
|
{
|
|
|
|
$this->normalizer->expects($this->once())
|
|
|
|
->method('normalize')
|
|
|
|
->with($this->documentation)
|
|
|
|
->willReturn(['info' => ['title' => 'My Test App'], 'basePath' => '/foo']);
|
|
|
|
|
2020-05-28 13:19:11 +02:00
|
|
|
$expectedApi = new OpenApi(['info' => ['title' => 'My Test App']]);
|
|
|
|
$this->assertEquals($expectedApi->toJson(), $this->getOpenApiDoc()->toJson());
|
2019-01-11 16:54:58 +01:00
|
|
|
}
|
|
|
|
|
2020-05-31 14:16:51 +01:00
|
|
|
protected function setUp(): void
|
2019-01-11 16:54:58 +01:00
|
|
|
{
|
|
|
|
$this->documentation = new Documentation(new ResourceNameCollection(['dummy' => 'dummy']));
|
|
|
|
|
|
|
|
$this->normalizer = $this->createMock(NormalizerInterface::class);
|
|
|
|
$this->normalizer->expects($this->once())
|
|
|
|
->method('supportsNormalization')
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
$this->describer = new ApiPlatformDescriber($this->documentation, $this->normalizer);
|
|
|
|
}
|
|
|
|
}
|