/** * Less type specifier than values. * * @expectedException \Budgegeria\IntlFormat\Exception\InvalidTypeSpecifierException */ public function testEscapedInvalidTypeSpecifierCount() { $message = 'Hello %%world'; $parsed = new MessageMetaData(); $parsed->typeSpecifiers = []; $parsed->values = ['island']; $parsed->parsedMessage = ['Hello ', '%world']; $parser = $this->createMock(MessageParserInterface::class); $parser->expects($this->once())->method('parseMessage')->with($message, ['island'])->willReturn($parsed); $intlFormat = new IntlFormat([], $parser); $intlFormat->format($message, 'island'); }
/** * @dataProvider formattingWorksProvider */ public function testFormattingWorks($expected, $message, ...$args) { $formatter = [new SprintfFormatter()]; $intlFormat = new IntlFormat($formatter); $this->assertSame($expected, $intlFormat->format($message, ...$args)); }
public function testAddFormatOverride() { $message = 'Hello "%world", how are you'; $formatter1 = $this->createMock(FormatterInterface::class); $formatter1->method('has')->willReturn(true); $formatter1->method('formatValue')->willReturn('island'); $formatter2 = $this->createMock(FormatterInterface::class); $formatter2->method('has')->willReturn(true); $formatter2->method('formatValue')->willReturn('city'); $intlFormat = new IntlFormat([]); $intlFormat->addFormatter($formatter1); $intlFormat->addFormatter($formatter2); $this->assertSame('Hello "city", how are you', $intlFormat->format($message, 'city')); }