Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PaymentNonceResponseValidatorTest.php
Go to the documentation of this file.
1 <?php
7 
12 use Magento\Payment\Gateway\Validator\ResultInterfaceFactory;
13 use PHPUnit_Framework_MockObject_MockObject as MockObject;
14 
15 class PaymentNonceResponseValidatorTest extends \PHPUnit\Framework\TestCase
16 {
20  private $validator;
21 
25  private $resultInterfaceFactory;
26 
27  protected function setUp()
28  {
29  $this->resultInterfaceFactory = $this->getMockBuilder(ResultInterfaceFactory::class)
30  ->disableOriginalConstructor()
31  ->setMethods(['create'])
32  ->getMock();
33 
34  $this->validator = new PaymentNonceResponseValidator(
35  $this->resultInterfaceFactory,
36  new SubjectReader(),
37  new ErrorCodeProvider()
38  );
39  }
40 
41  public function testFailedValidate()
42  {
43  $obj = new \stdClass();
44  $obj->success = true;
45  $subject = [
46  'response' => [
47  'object' => $obj
48  ]
49  ];
50 
51  $result = new Result(false, [__('Payment method nonce can\'t be retrieved.')]);
52  $this->resultInterfaceFactory->method('create')
53  ->willReturn($result);
54 
55  $actual = $this->validator->validate($subject);
56  self::assertEquals($result, $actual);
57  }
58 
59  public function testValidateSuccess()
60  {
61  $obj = new \stdClass();
62  $obj->success = true;
63  $obj->paymentMethodNonce = new \stdClass();
64  $obj->paymentMethodNonce->nonce = 'fj2hd9239kd1kq9';
65 
66  $subject = [
67  'response' => [
68  'object' => $obj
69  ]
70  ];
71 
72  $result = new Result(true);
73  $this->resultInterfaceFactory->method('create')
74  ->willReturn($result);
75 
76  $actual = $this->validator->validate($subject);
77  self::assertEquals($result, $actual);
78  }
79 }
__()
Definition: __.php:13