2016-07-12 00:33:55 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2016-12-29 12:09:26 +01:00
|
|
|
* This file is part of the NelmioApiDocBundle package.
|
2016-07-12 00:33:55 +02:00
|
|
|
*
|
2016-12-29 12:09:26 +01:00
|
|
|
* (c) Nelmio
|
2016-07-12 00:33:55 +02:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2017-06-14 13:47:53 +02:00
|
|
|
namespace Nelmio\ApiDocBundle\Tests\Functional;
|
|
|
|
|
2016-07-29 10:22:40 +02:00
|
|
|
use ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle;
|
2018-05-05 14:49:17 +02:00
|
|
|
use Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle;
|
2017-06-20 20:49:50 +02:00
|
|
|
use FOS\RestBundle\FOSRestBundle;
|
2017-06-25 15:40:07 +02:00
|
|
|
use JMS\SerializerBundle\JMSSerializerBundle;
|
2016-12-29 12:09:26 +01:00
|
|
|
use Nelmio\ApiDocBundle\NelmioApiDocBundle;
|
2016-07-12 00:33:55 +02:00
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
|
2016-11-18 22:16:53 +01:00
|
|
|
use Symfony\Bundle\TwigBundle\TwigBundle;
|
2016-07-12 00:33:55 +02:00
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
|
use Symfony\Component\HttpKernel\Kernel;
|
|
|
|
use Symfony\Component\Routing\RouteCollectionBuilder;
|
|
|
|
|
|
|
|
class TestKernel extends Kernel
|
|
|
|
{
|
|
|
|
use MicroKernelTrait;
|
|
|
|
|
2017-06-25 15:40:07 +02:00
|
|
|
private $useJMS;
|
2018-05-05 14:49:17 +02:00
|
|
|
private $useBazinga;
|
2017-06-25 15:40:07 +02:00
|
|
|
|
2018-05-05 14:49:17 +02:00
|
|
|
public function __construct(bool $useJMS = false, bool $useBazinga = false)
|
2017-06-25 15:40:07 +02:00
|
|
|
{
|
2018-05-05 14:49:17 +02:00
|
|
|
parent::__construct('test'.(int) $useJMS.(int) $useBazinga, true);
|
2017-06-25 15:40:07 +02:00
|
|
|
|
|
|
|
$this->useJMS = $useJMS;
|
2018-05-05 14:49:17 +02:00
|
|
|
$this->useBazinga = $useBazinga;
|
2017-06-25 15:40:07 +02:00
|
|
|
}
|
|
|
|
|
2016-07-12 00:33:55 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function registerBundles()
|
|
|
|
{
|
2017-06-25 15:40:07 +02:00
|
|
|
$bundles = [
|
2016-07-12 00:33:55 +02:00
|
|
|
new FrameworkBundle(),
|
2016-11-18 22:16:53 +01:00
|
|
|
new TwigBundle(),
|
2016-07-12 00:33:55 +02:00
|
|
|
new SensioFrameworkExtraBundle(),
|
2016-07-29 10:22:40 +02:00
|
|
|
new ApiPlatformBundle(),
|
2016-12-29 12:09:26 +01:00
|
|
|
new NelmioApiDocBundle(),
|
2017-06-20 20:49:50 +02:00
|
|
|
new FOSRestBundle(),
|
2016-07-29 10:22:40 +02:00
|
|
|
new TestBundle(),
|
2016-07-12 00:33:55 +02:00
|
|
|
];
|
2017-06-25 15:40:07 +02:00
|
|
|
|
|
|
|
if ($this->useJMS) {
|
|
|
|
$bundles[] = new JMSSerializerBundle();
|
2018-05-05 14:49:17 +02:00
|
|
|
|
|
|
|
if ($this->useBazinga) {
|
|
|
|
$bundles[] = new BazingaHateoasBundle();
|
|
|
|
}
|
2017-06-25 15:40:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $bundles;
|
2016-07-12 00:33:55 +02:00
|
|
|
}
|
2016-07-15 00:04:07 +02:00
|
|
|
|
2016-07-12 00:33:55 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
protected function configureRoutes(RouteCollectionBuilder $routes)
|
|
|
|
{
|
2018-01-05 13:08:02 +01:00
|
|
|
$routes->import(__DIR__.'/Controller/TestController.php', '/', 'annotation');
|
2017-06-25 15:40:07 +02:00
|
|
|
$routes->import(__DIR__.'/Controller/ApiController.php', '/', 'annotation');
|
2018-04-16 13:43:42 +02:00
|
|
|
$routes->import(__DIR__.'/Controller/ClassApiController.php', '/', 'annotation');
|
2017-06-25 15:40:07 +02:00
|
|
|
$routes->import(__DIR__.'/Controller/UndocumentedController.php', '/', 'annotation');
|
2016-07-29 10:22:40 +02:00
|
|
|
$routes->import('', '/api', 'api_platform');
|
2018-01-05 13:08:02 +01:00
|
|
|
$routes->add('/docs/{area}', 'nelmio_api_doc.controller.swagger_ui')->setDefault('area', 'default');
|
2017-06-26 10:34:42 +02:00
|
|
|
$routes->add('/docs.json', 'nelmio_api_doc.controller.swagger');
|
2017-06-25 15:40:07 +02:00
|
|
|
|
|
|
|
if ($this->useJMS) {
|
|
|
|
$routes->import(__DIR__.'/Controller/JMSController.php', '/', 'annotation');
|
|
|
|
}
|
2018-05-05 14:49:17 +02:00
|
|
|
|
|
|
|
if ($this->useBazinga) {
|
|
|
|
$routes->import(__DIR__.'/Controller/BazingaController.php', '/', 'annotation');
|
|
|
|
}
|
2016-07-12 00:33:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
|
|
|
|
{
|
|
|
|
$c->loadFromExtension('framework', [
|
|
|
|
'secret' => 'MySecretKey',
|
2016-07-29 10:22:40 +02:00
|
|
|
'test' => null,
|
|
|
|
'validation' => null,
|
2017-06-24 17:49:00 +02:00
|
|
|
'form' => null,
|
2017-01-18 18:02:00 +01:00
|
|
|
'templating' => [
|
|
|
|
'engines' => ['twig'],
|
|
|
|
],
|
2017-06-14 13:47:53 +02:00
|
|
|
'serializer' => ['enable_annotations' => true],
|
2016-07-12 00:33:55 +02:00
|
|
|
]);
|
2016-11-30 14:08:10 +01:00
|
|
|
|
2018-11-04 12:24:45 +01:00
|
|
|
$c->loadFromExtension('twig', [
|
|
|
|
'strict_variables' => '%kernel.debug%',
|
|
|
|
]);
|
|
|
|
|
2017-06-20 20:49:50 +02:00
|
|
|
$c->loadFromExtension('fos_rest', [
|
|
|
|
'format_listener' => [
|
|
|
|
'rules' => [
|
|
|
|
[
|
|
|
|
'path' => '^/',
|
|
|
|
'fallback_format' => 'json',
|
2017-06-26 10:34:42 +02:00
|
|
|
],
|
2017-06-20 20:49:50 +02:00
|
|
|
],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
2016-11-30 14:08:10 +01:00
|
|
|
// Filter routes
|
2016-12-29 12:09:26 +01:00
|
|
|
$c->loadFromExtension('nelmio_api_doc', [
|
2017-01-25 18:53:19 +01:00
|
|
|
'documentation' => [
|
|
|
|
'info' => [
|
2018-10-06 14:42:47 +02:00
|
|
|
'title' => 'My Default App',
|
2017-01-25 18:53:19 +01:00
|
|
|
],
|
2018-02-19 10:49:52 +01:00
|
|
|
'definitions' => [
|
|
|
|
'Test' => [
|
|
|
|
'type' => 'string',
|
|
|
|
],
|
|
|
|
],
|
2018-05-10 18:46:48 +02:00
|
|
|
'parameters' => [
|
|
|
|
'test' => [
|
|
|
|
'name' => 'id',
|
|
|
|
'in' => 'path',
|
|
|
|
'required' => true,
|
|
|
|
],
|
|
|
|
],
|
2018-10-02 16:06:18 +07:00
|
|
|
'responses' => [
|
|
|
|
'201' => [
|
|
|
|
'description' => 'Awesome description',
|
|
|
|
],
|
|
|
|
],
|
2017-01-25 18:53:19 +01:00
|
|
|
],
|
2018-01-05 13:08:02 +01:00
|
|
|
'areas' => [
|
2018-07-27 09:59:45 +05:00
|
|
|
'default' => [
|
|
|
|
'path_patterns' => ['^/api(?!/admin)'],
|
|
|
|
'host_patterns' => ['^api\.'],
|
|
|
|
],
|
|
|
|
'test' => [
|
|
|
|
'path_patterns' => ['^/test'],
|
|
|
|
'host_patterns' => ['^api-test\.'],
|
|
|
|
'documentation' => [
|
|
|
|
'info' => [
|
|
|
|
'title' => 'My Test App',
|
|
|
|
],
|
2018-07-27 09:44:19 +05:00
|
|
|
],
|
2018-07-27 09:59:45 +05:00
|
|
|
],
|
2016-11-30 14:08:10 +01:00
|
|
|
],
|
|
|
|
]);
|
2016-07-12 00:33:55 +02:00
|
|
|
}
|
2017-06-25 15:40:07 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getCacheDir()
|
|
|
|
{
|
|
|
|
return parent::getCacheDir().'/'.(int) $this->useJMS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getLogDir()
|
|
|
|
{
|
|
|
|
return parent::getLogDir().'/'.(int) $this->useJMS;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function serialize()
|
|
|
|
{
|
|
|
|
return serialize($this->useJMS);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function unserialize($str)
|
|
|
|
{
|
|
|
|
$this->__construct(unserialize($str));
|
|
|
|
}
|
2016-07-12 00:33:55 +02:00
|
|
|
}
|