public function testGetMetadata() { $this->formatter->expects($this->once())->method('format')->with('test value', true)->willReturn('formatted test label'); $formView = $this->createFormView(); $formView->vars['formatter_options'] = []; $typeFormView = $this->createFormView($formView); $typeFormView->vars['choices'] = []; $unitFormView = $this->createFormView($formView); $unitFormView->vars['choices'] = [new ChoiceView('test data', 'test value', 'test label')]; $formView->children = ['type' => $typeFormView, 'unit' => $unitFormView]; $this->form->expects($this->any())->method('createView')->willReturn($formView); $metadata = $this->productPriceFilter->getMetadata(); $this->assertArrayHasKey('unitChoices', $metadata); $this->assertInternalType('array', $metadata['unitChoices']); $this->assertEquals([['data' => 'test data', 'value' => 'test value', 'label' => 'test label', 'shortLabel' => 'formatted test label']], $metadata['unitChoices']); }
/** * @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']); }
/** * @param string $unitCode * @param bool $isShort * @param string $expected * * @dataProvider formatProvider */ public function testFormat($unitCode, $isShort, $expected) { $this->formatter->expects($this->once())->method('format')->with($unitCode, $isShort)->willReturn($expected); $this->assertEquals($expected, $this->extension->format($unitCode, $isShort)); }