/** * @dataProvider customPlaceholdersTestCases */ public function testCustomPlaceholders(DateDiffResult $result) { $translator = $this->getMockForAbstractClass(TranslatorInterface::class); $formatter = new TranslatorFormatter($translator); $formatter->registerCustomPlaceholder(['yesterday', 'tomorrow'], '%at%', function (DateDiffResult $result) { return $result->getRequest()->getDate()->format('H:i'); }); $translator->expects($this->once())->method('transChoice')->with($result->getKey(), $this->isNull(), ['%count%' => $result->getValue(), '%at%' => $result->getRequest()->getDate()->format('H:i')]); $formatter->format($result); }
public function format(DateDiffResult $result) { if ($result->getKey() === DateDiffResult::FULL_DATE) { return $result->getRequest()->getDate()->format($this->dateFormat); } return $this->translatorInterface->transChoice($result->getKey(), $result->getValue(), $this->getPlaceholders($result), $this->domain); }
public function testItsAnImmutableObjectWithGettersMate() { $request = $this->createRequestForSeconds(5); $result = new DateDiffResult($request, 'some-key', 1); $this->assertSame($request, $result->getRequest()); $this->assertSame('some-key', $result->getKey()); $this->assertSame(1, $result->getValue()); }