Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CostTest.php
Go to the documentation of this file.
1 <?php
8 
12 class CostTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $total;
18 
22  protected $creditmemoMock;
23 
28 
29  protected function setUp()
30  {
31  $this->creditmemoMock = $this->createPartialMock(
32  \Magento\Sales\Model\Order\Creditmemo::class,
33  ['setBaseCost', 'getAllItems']
34  );
35  $this->creditmemoItemMock = $this->createPartialMock(
36  \Magento\Sales\Model\Order\Creditmemo\Item::class,
37  ['getHasChildren', 'getBaseCost', 'getQty']
38  );
39  $this->total = new \Magento\Sales\Model\Order\Creditmemo\Total\Cost();
40  }
41 
42  public function testCollect()
43  {
44  $this->creditmemoMock->expects($this->once())
45  ->method('getAllItems')
46  ->willReturn([$this->creditmemoItemMock, $this->creditmemoItemMock]);
47  $this->creditmemoItemMock->expects($this->exactly(2))
48  ->method('getHasChildren')
49  ->willReturn(false);
50  $this->creditmemoItemMock->expects($this->exactly(2))
51  ->method('getBaseCost')
52  ->willReturn(10);
53  $this->creditmemoItemMock->expects($this->exactly(2))
54  ->method('getQty')
55  ->willReturn(2);
56  $this->creditmemoMock->expects($this->once())
57  ->method('setBaseCost')
58  ->with(40)
59  ->willReturnSelf();
60  $this->assertEquals($this->total, $this->total->collect($this->creditmemoMock));
61  }
62 }