Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CheckoutTest.php
Go to the documentation of this file.
1 <?php
11 
15 
16 class CheckoutTest extends \PHPUnit\Framework\TestCase
17 {
21  private $session;
22 
26  private $checkout;
27 
28  protected function setUp()
29  {
30  $this->session = $this->getMockBuilder(Session::class)
31  ->disableOriginalConstructor()
32  ->getMock();
33 
34  $this->checkout = new Checkout($this->session);
35  }
36 
37  public function testCancelCurrentOrder()
38  {
39  $id = 1;
41  $comment = 'Bla Bla';
42 
43  $order = $this->getMockBuilder(Order::class)
44  ->disableOriginalConstructor()
45  ->getMock();
46 
47  $this->session->expects(static::once())
48  ->method('getLastRealOrder')
49  ->willReturn($order);
50  $order->expects(static::once())
51  ->method('getId')
52  ->willReturn($id);
53  $order->expects(static::once())
54  ->method('getState')
55  ->willReturn($state);
56  $order->expects(static::once())
57  ->method('registerCancellation')
58  ->with($comment)
59  ->willReturnSelf();
60  $order->expects(static::once())
61  ->method('save');
62 
63  static::assertTrue($this->checkout->cancelCurrentOrder($comment));
64  }
65 
67  {
68  $id = 1;
69  $state = Order::STATE_CANCELED;
70  $comment = 'Bla Bla';
71 
72  $order = $this->getMockBuilder(Order::class)
73  ->disableOriginalConstructor()
74  ->getMock();
75 
76  $this->session->expects(static::once())
77  ->method('getLastRealOrder')
78  ->willReturn($order);
79  $order->expects(static::once())
80  ->method('getId')
81  ->willReturn($id);
82  $order->expects(static::once())
83  ->method('getState')
84  ->willReturn($state);
85  $order->expects(static::never())
86  ->method('registerCancellation')
87  ->with($comment)
88  ->willReturnSelf();
89  $order->expects(static::never())
90  ->method('save');
91 
92  static::assertFalse($this->checkout->cancelCurrentOrder($comment));
93  }
94 
95  public function testRestoreQuote()
96  {
97  $this->session->expects(static::once())
98  ->method('restoreQuote')
99  ->willReturn(true);
100 
101  static::assertTrue($this->checkout->restoreQuote());
102  }
103 }
$id
Definition: fieldset.phtml:14
$order
Definition: order.php:55