currentRequest = new Request(); $this->requestStack = $this->createMock(RequestStack::class); $this->requestStack->method('getCurrentRequest')->willReturn($this->currentRequest); $this->optionalGetParameterService = new OptionalGetParameterService($this->requestStack); } public function testConstructor(): void { $this->expectException(UnvalidParameterException::class); $this->currentRequest->query->set('asdwgwe', 'adasa'); new OptionalGetParameterService($this->requestStack); } public function testHasAndGetParameter(): void { foreach (OptionalGetParameterServiceInterface::OPTIONAL_PARAMETERS as $key) { $this->assertFalse($this->optionalGetParameterService->hasParameter($key)); $this->currentRequest->query->set($key, 'adasa'); $this->assertTrue($this->optionalGetParameterService->hasParameter($key)); $this->assertEquals('adasa', $this->optionalGetParameterService->getParameter($key)); } $this->expectException(UnvalidParameterException::class); $this->optionalGetParameterService->getParameter('12312312asdas'); } public function testSetParameterException(): void { $this->expectException(NotDefinedException::class); $this->optionalGetParameterService->getParameter(OptionalGetParameterServiceInterface::VERSION_PARAMETER); } }