コード例 #1
0
 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;
 }
コード例 #2
0
 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());
 }
コード例 #3
0
 /**
  * @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);
 }
コード例 #4
0
 private function interpolate(DateDiffResult $dateDiffResult)
 {
     return str_replace('[X]', $dateDiffResult->getValue(), $dateDiffResult->getKey());
 }
コード例 #5
0
 protected function assertDateDiffResult($key, $value, DateDiffResult $currentResult)
 {
     $this->assertSame($key, $currentResult->getKey(), 'Invalid result key');
     $this->assertSame($value, $currentResult->getValue(), 'Invalid result value');
 }