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);
     });
 }
 /**
  * {@inheritdoc}
  */
 public function reverseTransform($value)
 {
     $offer = null;
     $offerQuantity = null;
     if ($value) {
         if (!is_array($value)) {
             throw new UnexpectedTypeException($value, 'array');
         }
         $offerQuantity = $this->getOption($value, QuoteProductToOrderType::FIELD_QUANTITY);
         $offerUnit = $this->getOption($value, QuoteProductToOrderType::FIELD_UNIT);
         if ($offerQuantity && $offerUnit) {
             $offerQuantity = $this->roundQuantity($offerQuantity, $offerUnit);
             $offer = $this->matcher->match($this->quoteProduct, $offerUnit, $offerQuantity);
         }
     }
     return [QuoteProductToOrderType::FIELD_QUANTITY => $offerQuantity, QuoteProductToOrderType::FIELD_OFFER => $offer];
 }
 /**
  * @dataProvider matchDataProvider
  *
  * @param $quoteProduct
  * @param $unitCode
  * @param $quantity
  * @param $expectedResult
  */
 public function testMatch($quoteProduct, $unitCode, $quantity, $expectedResult)
 {
     $this->assertEquals($expectedResult, $this->matcher->match($quoteProduct, $unitCode, $quantity));
 }