51 lines
1.4 KiB
PHP
Raw Normal View History

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;
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
}
2018-10-06 14:42:47 +02:00
protected function getSwaggerDefinition($area = 'default')
{
2018-10-06 14:42:47 +02:00
return static::$kernel->getContainer()->get(sprintf('nelmio_api_doc.generator.%s', $area))->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
}