2017-06-14 13:47:53 +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;
|
|
|
|
|
2017-06-26 10:34:42 +02:00
|
|
|
use EXSyst\Component\Swagger\Operation;
|
|
|
|
use EXSyst\Component\Swagger\Schema;
|
2017-06-14 13:47:53 +02:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
|
|
|
|
|
|
|
|
class WebTestCase extends BaseWebTestCase
|
|
|
|
{
|
2017-12-22 17:42:18 +00:00
|
|
|
protected static function createKernel(array $options = [])
|
2017-06-14 13:47:53 +02:00
|
|
|
{
|
2017-06-25 15:40:07 +02:00
|
|
|
return new TestKernel();
|
2017-06-14 13:47:53 +02:00
|
|
|
}
|
2017-06-26 10:34:42 +02:00
|
|
|
|
|
|
|
protected function getSwaggerDefinition()
|
|
|
|
{
|
2018-03-13 12:40:36 -03:00
|
|
|
static::createClient([], ['HTTP_HOST' => 'api.example.com']);
|
2017-06-26 10:34:42 +02:00
|
|
|
|
|
|
|
return static::$kernel->getContainer()->get('nelmio_api_doc.generator')->generate();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getModel($name): Schema
|
|
|
|
{
|
|
|
|
$definitions = $this->getSwaggerDefinition()->getDefinitions();
|
|
|
|
$this->assertTrue($definitions->has($name));
|
|
|
|
|
|
|
|
return $definitions->get($name);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getOperation($path, $method): Operation
|
|
|
|
{
|
|
|
|
$api = $this->getSwaggerDefinition();
|
|
|
|
$paths = $api->getPaths();
|
|
|
|
|
|
|
|
$this->assertTrue($paths->has($path), sprintf('Path "%s" does not exist.', $path));
|
|
|
|
$action = $paths->get($path);
|
|
|
|
|
|
|
|
$this->assertTrue($action->hasOperation($method), sprintf('Operation "%s" for path "%s" does not exist', $path, $method));
|
|
|
|
|
|
|
|
return $action->getOperation($method);
|
|
|
|
}
|
2017-06-14 13:47:53 +02:00
|
|
|
}
|