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()); }
/** * @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); }
private function getPlaceholders(DateDiffResult $result) { $placeholders = ['%count%' => $result->getValue()]; if (isset($this->customPlaceholders[$result->getKey()])) { $customPlaceholders = $this->customPlaceholders[$result->getKey()]; foreach ($customPlaceholders as $customPlaceholder => $customPlaceholderFunction) { $placeholders[$customPlaceholder] = call_user_func($customPlaceholderFunction, $result); } } return $placeholders; }
private function interpolate(DateDiffResult $dateDiffResult) { return str_replace('[X]', $dateDiffResult->getValue(), $dateDiffResult->getKey()); }
protected function assertDateDiffResult($key, $value, DateDiffResult $currentResult) { $this->assertSame($key, $currentResult->getKey(), 'Invalid result key'); $this->assertSame($value, $currentResult->getValue(), 'Invalid result value'); }