diff --git a/Controller/SwaggerUiController.php b/Controller/SwaggerUiController.php index a80f013..8c88e3b 100644 --- a/Controller/SwaggerUiController.php +++ b/Controller/SwaggerUiController.php @@ -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__)); diff --git a/Tests/Controller/ControllersTest.php b/Tests/Controller/ControllersTest.php index d94f57d..3c83e0d 100644 --- a/Tests/Controller/ControllersTest.php +++ b/Tests/Controller/ControllersTest.php @@ -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()); }