/** * Method testNoPrecision */ public function testNoPrecision() { $this->roundingService->expects($this->never())->method('round'); $lineItemManager = new LineItemManager($this->roundingService); $product = $this->getProductEntityWithPrecision('kg', 3); $quantity = $this->getRandomQuantity(); $roundedQuantity = $lineItemManager->roundProductQuantity($product, 'unit', $quantity); $this->assertEquals($quantity, $roundedQuantity); }
/** * @param ProductPrice $defaultData * @param array $submittedData * @param ProductPrice $expectedData * @param boolean $rounding * @dataProvider submitProvider */ public function testSubmit(ProductPrice $defaultData, array $submittedData, ProductPrice $expectedData, $rounding = false) { if ($rounding) { $this->roundingService->expects($this->once())->method('round')->willReturnCallback(function ($value, $precision) { return round($value, $precision); }); } $form = $this->factory->create($this->formType, $defaultData, []); $this->assertEquals($defaultData, $form->getData()); $form->submit($submittedData); $this->assertEquals([], $form->getErrors()); $this->assertTrue($form->isValid()); $this->assertEquals($expectedData, $form->getData()); }
protected function setUp() { $this->matcher = $this->getMockBuilder('OroB2B\\Bundle\\SaleBundle\\Model\\QuoteProductOfferMatcher')->disableOriginalConstructor()->getMock(); $this->matcher->expects($this->any())->method('match')->willReturnCallback(function (QuoteProduct $quoteProduct, $unitCode, $quantity) { // simple emulation of original match algorithm return $quoteProduct->getQuoteProductOffers()->filter(function (QuoteProductOffer $offer) use($quantity) { return $offer->getQuantity() === $quantity; })->first(); }); $this->roundingService = $this->getMockBuilder('OroB2B\\Bundle\\ProductBundle\\Rounding\\RoundingService')->disableOriginalConstructor()->getMock(); $this->roundingService->expects($this->any())->method('round')->willReturnCallback(function ($value, $precision) { return round($value, $precision, PHP_ROUND_HALF_UP); }); }
/** * @param array $sourceData * @param array $expectedData * @dataProvider onPreSubmitDataProvider */ public function testOnPreSubmit(array $sourceData, array $expectedData) { $this->roundingService->expects($this->any())->method('round')->willReturnCallback(function ($quantity, $precision) { return round($quantity, $precision); }); $event = $this->createEvent($sourceData); $this->extension->onPreSubmit($event); $this->assertEquals($expectedData, $event->getData()); }