Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SuccessValidatorTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class SuccessValidatorTest extends \PHPUnit\Framework\TestCase
11 {
14 
15  protected function setUp()
16  {
17  $this->objectManagerHelper = new ObjectManagerHelper($this);
18  }
19 
20  public function testIsValid()
21  {
22  $checkoutSession = $this->getMockBuilder(
23  \Magento\Checkout\Model\Session::class
24  )->disableOriginalConstructor()->getMock();
25  $this->assertFalse($this->createSuccessValidator($checkoutSession)->isValid($checkoutSession));
26  }
27 
29  {
30  $checkoutSession = $this->getMockBuilder(
31  \Magento\Checkout\Model\Session::class
32  )->disableOriginalConstructor()->getMock();
33 
34  $checkoutSession->expects(
35  $this->at(0)
36  )->method(
37  '__call'
38  )->with(
39  'getLastSuccessQuoteId'
40  )->will(
41  $this->returnValue(1)
42  );
43 
44  $checkoutSession->expects($this->at(1))->method('__call')->with('getLastQuoteId')->will($this->returnValue(0));
45 
46  $this->assertFalse($this->createSuccessValidator($checkoutSession)->isValid($checkoutSession));
47  }
48 
50  {
51  $checkoutSession = $this->getMockBuilder(
52  \Magento\Checkout\Model\Session::class
53  )->disableOriginalConstructor()->getMock();
54  $checkoutSession->expects(
55  $this->at(0)
56  )->method(
57  '__call'
58  )->with(
59  'getLastSuccessQuoteId'
60  )->will(
61  $this->returnValue(1)
62  );
63 
64  $checkoutSession->expects($this->at(1))->method('__call')->with('getLastQuoteId')->will($this->returnValue(1));
65 
66  $checkoutSession->expects($this->at(2))->method('__call')->with('getLastOrderId')->will($this->returnValue(0));
67 
68  $this->assertFalse($this->createSuccessValidator($checkoutSession)->isValid($checkoutSession));
69  }
70 
71  public function testIsValidTrue()
72  {
73  $checkoutSession = $this->getMockBuilder(
74  \Magento\Checkout\Model\Session::class
75  )->disableOriginalConstructor()->getMock();
76  $checkoutSession->expects(
77  $this->at(0)
78  )->method(
79  '__call'
80  )->with(
81  'getLastSuccessQuoteId'
82  )->will(
83  $this->returnValue(1)
84  );
85 
86  $checkoutSession->expects($this->at(1))->method('__call')->with('getLastQuoteId')->will($this->returnValue(1));
87 
88  $checkoutSession->expects($this->at(2))->method('__call')->with('getLastOrderId')->will($this->returnValue(1));
89 
90  $this->assertTrue($this->createSuccessValidator($checkoutSession)->isValid($checkoutSession));
91  }
92 
97  protected function createSuccessValidator(\PHPUnit_Framework_MockObject_MockObject $checkoutSession)
98  {
99  return $this->objectManagerHelper->getObject(
100  \Magento\Checkout\Model\Session\SuccessValidator::class,
101  ['checkoutSession' => $checkoutSession]
102  );
103  }
104 }
createSuccessValidator(\PHPUnit_Framework_MockObject_MockObject $checkoutSession)