/** * Asserts that the given parameters are passed to the inner formatter. * * It is only asserted that the given parameters with the provided values exists, * it is not guaranteed that no other parameters are passed. * * @param array<string, mixed> $parameters */ protected function assertExpectedParameters(array $parameterSubSet) { $checkParameters = function (array $parameters) use($parameterSubSet) { foreach ($parameterSubSet as $name => $value) { $this->assertArrayHasKey($name, $parameters, sprintf('Missing parameter. Available parameters: %s', implode(',', array_keys($parameters)))); $this->assertEquals($parameters[$name], $value, sprintf('Parameter "%s" does not have the expected value.', $name)); } return true; }; $this->innerFormatter->expects($this->atLeastOnce())->method('format')->with($this->anything(), $this->anything(), $this->callback($checkParameters))->will($this->returnValue('formatted message')); }
/** * Ensures that the inner formatter throws the given exception. * * @param \Exception $exception */ private function simulateFormatterException(\Exception $exception) { $this->innerFormatter->expects($this->once())->method('format')->will($this->throwException($exception)); }
/** * Formats the provided message. * * @param string $locale * @param string $message * @param array(string=>mixed) $parameters * @return string The formatted message. */ public function format($locale, $message, array $parameters) { return $this->innerFormatter->format($this->preProcessLocale($locale), $this->preProcessMessage($message), $this->preProcessParameters($parameters)); }