public function testFormatShort() { $value = 42; $unit = (new ProductUnit())->setCode('kg'); $expectedResult = '42 kg'; $this->formatter->expects($this->once())->method('formatShort')->with($value, $unit)->willReturn($expectedResult); $this->assertEquals($expectedResult, $this->extension->formatShort($value, $unit)); }
/** * @param array $inputData * @param array $expectedData * * @dataProvider formatOfferProvider */ public function testFormatOffer(array $inputData, array $expectedData) { /* @var $item QuoteProductOffer */ $item = $inputData['item']; $item->setQuantity($inputData['quantity'])->setProductUnit($inputData['unit'])->setProductUnitCode($inputData['unitCode'])->setPrice($inputData['price']); $this->productUnitValueFormatter->expects($inputData['unit'] ? $this->once() : $this->never())->method('format')->with($inputData['quantity'], $inputData['unitCode'])->will($this->returnValue($expectedData['formattedUnits'])); $price = $inputData['price'] ?: new Price(); $this->numberFormatter->expects($price ? $this->once() : $this->never())->method('formatCurrency')->with($price->getValue(), $price->getCurrency())->will($this->returnValue($expectedData['formattedPrice'])); $this->productUnitLabelFormatter->expects($this->once())->method('format')->with($inputData['unitCode'])->will($this->returnValue($expectedData['formattedUnit'])); $this->translator->expects($this->once())->method('transChoice')->with($expectedData['transConstant'], $expectedData['transIndex'], ['{units}' => $expectedData['formattedUnits'], '{price}' => $expectedData['formattedPrice'], '{unit}' => $expectedData['formattedUnit']]); $this->formatter->formatOffer($inputData['item']); }