Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GeneralResponseValidatorTest.php
Go to the documentation of this file.
1 <?php
7 
8 use Braintree\Result\Error;
14 use Magento\Payment\Gateway\Validator\ResultInterfaceFactory;
15 use PHPUnit_Framework_MockObject_MockObject as MockObject;
16 
17 class GeneralResponseValidatorTest extends \PHPUnit\Framework\TestCase
18 {
22  private $responseValidator;
23 
27  private $resultInterfaceFactory;
28 
34  protected function setUp()
35  {
36  $this->resultInterfaceFactory = $this->getMockBuilder(ResultInterfaceFactory::class)
37  ->disableOriginalConstructor()
38  ->setMethods(['create'])
39  ->getMock();
40 
41  $this->responseValidator = new GeneralResponseValidator(
42  $this->resultInterfaceFactory,
43  new SubjectReader(),
44  new ErrorCodeProvider()
45  );
46  }
47 
59  public function testValidate(array $validationSubject, bool $isValid, $messages, array $errorCodes)
60  {
61  $result = new Result($isValid, $messages);
62 
63  $this->resultInterfaceFactory->method('create')
64  ->with([
65  'isValid' => $isValid,
66  'failsDescription' => $messages,
67  'errorCodes' => $errorCodes
68  ])
69  ->willReturn($result);
70 
71  $actual = $this->responseValidator->validate($validationSubject);
72 
73  self::assertEquals($result, $actual);
74  }
75 
81  public function dataProviderTestValidate()
82  {
83  $successTransaction = new \stdClass();
84  $successTransaction->success = true;
85 
86  $failureTransaction = new \stdClass();
87  $failureTransaction->success = false;
88  $failureTransaction->message = 'Transaction was failed.';
89 
90  $errors = [
91  'errors' => [
92  [
93  'code' => 81804,
94  'attribute' => 'base',
95  'message' => 'Cannot process transaction.'
96  ]
97  ]
98  ];
99  $errorTransaction = new Error(['errors' => $errors]);
100 
101  return [
102  [
103  'validationSubject' => [
104  'response' => [
105  'object' => $successTransaction
106  ],
107  ],
108  'isValid' => true,
109  [],
110  'errorCodes' => []
111  ],
112  [
113  'validationSubject' => [
114  'response' => [
115  'object' => $failureTransaction
116  ]
117  ],
118  'isValid' => false,
119  [
120  __('Transaction was failed.')
121  ],
122  'errorCodes' => []
123  ],
124  [
125  'validationSubject' => [
126  'response' => [
127  'object' => $errorTransaction
128  ]
129  ],
130  'isValid' => false,
131  [
132  __('Braintree error response.')
133  ],
134  'errorCodes' => ['81804']
135  ]
136  ];
137  }
138 }
__()
Definition: __.php:13
testValidate(array $validationSubject, bool $isValid, $messages, array $errorCodes)
$errors
Definition: overview.phtml:9