Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GrandTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class GrandTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $model;
16 
17  protected function setUp()
18  {
19  $objectManager = new ObjectManager($this);
20  $this->model = $objectManager->getObject(\Magento\Quote\Model\Quote\Address\Total\Grand::class);
21  }
22 
23  public function testCollect()
24  {
25  $totals = [1, 2, 3.4];
26  $totalsBase = [4, 5, 6.7];
27  $grandTotal = 6.4; // 1 + 2 + 3.4
28  $grandTotalBase = 15.7; // 4 + 5 + 6.7
29 
30  $totalMock = $this->createPartialMock(\Magento\Quote\Model\Quote\Address\Total::class, [
31  'getAllTotalAmounts',
32  'getAllBaseTotalAmounts',
33  'setGrandTotal',
34  'setBaseGrandTotal',
35  'getGrandTotal',
36  'getBaseGrandTotal'
37  ]);
38  $totalMock->expects($this->once())->method('getGrandTotal')->willReturn(2);
39  $totalMock->expects($this->once())->method('getBaseGrandTotal')->willReturn(2);
40  $totalMock->expects($this->once())->method('getAllTotalAmounts')->willReturn($totals);
41  $totalMock->expects($this->once())->method('getAllBaseTotalAmounts')->willReturn($totalsBase);
42  $totalMock->expects($this->once())->method('setGrandTotal')->with($grandTotal + 2);
43  $totalMock->expects($this->once())->method('setBaseGrandTotal')->with($grandTotalBase + 2);
44 
45  $this->model->collect(
46  $this->createMock(\Magento\Quote\Model\Quote::class),
47  $this->createMock(\Magento\Quote\Api\Data\ShippingAssignmentInterface::class),
48  $totalMock
49  );
50  }
51 }
$objectManager
Definition: bootstrap.php:17
$totals
Definition: totalbar.phtml:10