From 57f6226ba62b1a77fa1ff51becf60501562d2d49 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Mon, 5 Apr 2021 21:03:05 +0200 Subject: [PATCH] Add setter check --- src/Model/AuditManager.php | 9 +++++++++ .../Twig/Extension/CanonicalizeExtensionTest.php | 16 +++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Model/AuditManager.php b/src/Model/AuditManager.php index 8fdefa738b0..aa76c4f59c0 100644 --- a/src/Model/AuditManager.php +++ b/src/Model/AuditManager.php @@ -38,6 +38,15 @@ public function __construct(ContainerInterface $container) public function setReader(string $serviceId, array $classes): void { + $reader = $this->container->get($serviceId); + if (!$reader instanceof AuditReaderInterface) { + throw new \InvalidArgumentException(sprintf( + 'Service "%s" MUST implement interface "%s".', + $serviceId, + AuditReaderInterface::class, + )); + } + $this->readers[$serviceId] = $classes; } diff --git a/tests/Twig/Extension/CanonicalizeExtensionTest.php b/tests/Twig/Extension/CanonicalizeExtensionTest.php index 239e68762ce..8a0733a9dd8 100644 --- a/tests/Twig/Extension/CanonicalizeExtensionTest.php +++ b/tests/Twig/Extension/CanonicalizeExtensionTest.php @@ -24,9 +24,9 @@ final class CanonicalizeExtensionTest extends TestCase { /** - * @var RequestStack + * @var Request */ - private $requestStack; + private $request; /** * @var CanonicalizeExtension @@ -35,9 +35,10 @@ final class CanonicalizeExtensionTest extends TestCase protected function setUp(): void { - $this->requestStack = new RequestStack(); - $this->requestStack->push(new Request()); - $this->twigExtension = new CanonicalizeExtension($this->requestStack); + $this->request = new Request(); + $requestStack = new RequestStack(); + $requestStack->push($this->request); + $this->twigExtension = new CanonicalizeExtension($requestStack); } /** @@ -242,9 +243,6 @@ public function select2LocalesProvider() private function changeLocale(string $locale): void { - $request = $this->requestStack->getCurrentRequest(); - \assert(null !== $request); - - $request->setLocale($locale); + $this->request->setLocale($locale); } }