コード例 #1
0
 /**
  * @param SaleableInterface $salableItem
  * @param string $priceCode
  * @param float $quantity
  * @return PriceInterface
  * @throws \InvalidArgumentException
  */
 public function createPriceObject(SaleableInterface $salableItem, $priceCode, $quantity)
 {
     if (!isset($this->metadata[$priceCode])) {
         throw new \InvalidArgumentException($priceCode . ' is not registered in prices list');
     }
     $className = $this->metadata[$priceCode]['class'];
     return $this->priceFactory->create($salableItem, $className, $quantity);
 }
コード例 #2
0
 /**
  * @codingStandardsIgnoreStart
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Magento\Framework\Pricing\PriceInfo\Base doesn't implement \Magento\Framework\Pricing\Price\PriceInterface
  * @codingStandardsIgnoreEnd
  */
 public function testCreateWithException()
 {
     $quantity = 2.2;
     $className = 'Magento\\Framework\\Pricing\\PriceInfo\\Base';
     $priceMock = $this->getMockBuilder($className)->disableOriginalConstructor()->getMock();
     $saleableItem = $this->getMock('Magento\\Framework\\Pricing\\SaleableInterface');
     $arguments = [];
     $argumentsResult = array_merge($arguments, ['saleableItem' => $saleableItem, 'quantity' => $quantity]);
     $this->objectManagerMock->expects($this->once())->method('create')->with($className, $argumentsResult)->will($this->returnValue($priceMock));
     $this->model->create($saleableItem, $className, $quantity, $arguments);
 }
コード例 #3
0
 /**
  * Returns price model by code
  *
  * @param string $code
  * @return PriceInterface
  */
 public function get($code)
 {
     if (!isset($this->priceModels[$code])) {
         $this->priceModels[$code] = $this->priceFactory->create($this->saleableItem, $this->pool[$code], $this->quantity);
     }
     return $this->priceModels[$code];
 }
コード例 #4
0
 /**
  * Test current method
  */
 public function testCurrent()
 {
     $this->factoryMock->expects($this->once())->method('create')->with($this->equalTo($this->saleableItemMock), $this->equalTo($this->pool->current()), $this->quantity)->will($this->returnValue($this->priceMock));
     $this->assertEquals($this->priceMock, $this->collection->current());
 }
コード例 #5
0
 /**
  * Returns price model by code
  *
  * @param string $code
  * @return PriceInterface
  */
 public function get($code)
 {
     return $this->priceFactory->create($this->saleableItem, $this->pool[$code], $this->quantity);
 }