Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpdateQuoteItemsTest.php
Go to the documentation of this file.
1 <?php
7 
8 class UpdateQuoteItemsTest extends \PHPUnit\Framework\TestCase
9 {
13  private $model;
14 
18  private $quoteResource ;
19 
20  protected function setUp()
21  {
22  $this->quoteResource = $this->getMockBuilder(\Magento\Quote\Model\ResourceModel\Quote::class)
23  ->disableOriginalConstructor()
24  ->getMock();
25  $this->model = new \Magento\Quote\Model\Product\Plugin\UpdateQuoteItems($this->quoteResource);
26  }
27 
35  public function testAfterUpdate($originalPrice, $newPrice, $callMethod, $tierPriceChanged = false)
36  {
37  $productResourceMock = $this->createMock(\Magento\Catalog\Model\ResourceModel\Product::class);
38  $productMock = $this->getMockBuilder(\Magento\Framework\Model\AbstractModel::class)
39  ->disableOriginalConstructor()
40  ->setMethods(['getOrigData', 'getPrice', 'getId', 'getData'])
41  ->getMockForAbstractClass();
42  $productId = 1;
43  $productMock->expects($this->any())->method('getOrigData')->with('price')->willReturn($originalPrice);
44  $productMock->expects($this->any())->method('getPrice')->willReturn($newPrice);
45  $productMock->expects($this->any())->method('getId')->willReturn($productId);
46  $productMock->expects($this->any())->method('getData')->willReturn($tierPriceChanged);
47  $this->quoteResource->expects($this->$callMethod())->method('markQuotesRecollect')->with($productId);
48  $result = $this->model->afterSave($productResourceMock, $productResourceMock, $productMock);
49  $this->assertEquals($result, $productResourceMock);
50  }
51 
55  public function aroundUpdateDataProvider()
56  {
57  return [
58  [10, 20, 'once'],
59  [null, 10, 'never'],
60  [10, 10, 'never'],
61  [10, 10, 'once', true],
62  ];
63  }
64 }
testAfterUpdate($originalPrice, $newPrice, $callMethod, $tierPriceChanged=false)