/** * {@inheritdoc} */ public function render($data, array $options) { $dateTime = $this->getValue($data, $options); if ($dateTime === null) { return; } if (!$dateTime instanceof \DateTimeInterface) { throw new InvalidTypeException(sprintf('The "%s" %s column type expects a "\\DateTimeInterface" value, got "%s".', $options['column']->getName(), $this->getName(), is_object($dateTime) ? get_class($dateTime) : gettype($dateTime))); } return $this->formatter->format($dateTime, $options); }
/** * {@inheritdoc} */ public function render($data, array $options) { $number = $this->getValue($data, $options); if ($number === null) { return; } if (!is_numeric($number)) { throw new InvalidTypeException(sprintf('The "%s" %s column type expects a numeric value, got "%s".', $options['column']->getName(), $this->getName(), is_object($number) ? get_class($number) : gettype($number))); } return $this->formatter->format($number, $options); }
public function testRender() { $this->propertyAccessor->expects($this->once())->method('getValue')->with($this->identicalTo($data = new \stdClass()), $this->identicalTo($path = 'path_value'))->will($this->returnValue($number = 123.456)); $this->formatter->expects($this->once())->method('format')->with($this->identicalTo($number), $this->identicalTo($options = ['path' => $path, 'scale' => 4, 'grouping' => true, 'rounding' => \NumberFormatter::ROUND_HALFDOWN]))->will($this->returnValue($result = '123,45')); $this->assertSame($result, $this->type->render($data, $options)); }
public function testRender() { $this->propertyAccessor->expects($this->once())->method('getValue')->with($this->identicalTo($data = new \stdClass()), $this->identicalTo($path = 'path_value'))->will($this->returnValue($dateTime = new \DateTime($date = date($format = 'Y-m-d H:i:s')))); $this->formatter->expects($this->once())->method('format')->with($this->identicalTo($dateTime), $this->identicalTo($options = ['path' => $path]))->will($this->returnValue($result = $date)); $this->assertSame($date, $this->type->render($data, $options)); }