Merge pull request #1560 from piotrantosik/support_twig3

Allow Twig 3
This commit is contained in:
Guilhem Niot 2019-11-21 18:11:18 +01:00 committed by GitHub
commit 220e31667a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -17,6 +17,7 @@ use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Twig\Environment;
final class SwaggerUiController
{
@ -27,8 +28,12 @@ final class SwaggerUiController
/**
* @param ContainerInterface $generatorLocator
*/
public function __construct($generatorLocator, \Twig_Environment $twig)
public function __construct($generatorLocator, $twig)
{
if (!$twig instanceof \Twig_Environment && !$twig instanceof Environment) {
throw new \InvalidArgumentException(sprintf('Providing an instance of "%s" as twig is not supported.', get_class($twig)));
}
if (!$generatorLocator instanceof ContainerInterface) {
if (!$generatorLocator instanceof ApiDocGenerator) {
throw new \InvalidArgumentException(sprintf('Providing an instance of "%s" to "%s" is not supported.', get_class($generatorLocator), __METHOD__));

View File

@ -25,7 +25,13 @@ class ControllersTest extends TestCase
*/
public function testSwaggerUiControllerInstanciation()
{
$controller = new SwaggerUiController(new ApiDocGenerator([], []), $this->createMock('Twig_Environment'));
if (class_exists('Twig_Environment')) {
$twigMock = $this->createMock('Twig_Environment');
} else {
$twigMock = $this->createMock('Twig\Environment');
}
$controller = new SwaggerUiController(new ApiDocGenerator([], []), $twigMock);
$controller(new Request());
}