6 declare(strict_types=1);
10 use Braintree\Result\Error;
12 use PHPUnit\Framework\TestCase;
16 use Magento\Payment\Gateway\Validator\ResultInterfaceFactory;
17 use PHPUnit_Framework_MockObject_MockObject as MockObject;
32 private $generalValidator;
37 private $resultFactory;
44 $this->generalValidator = $this->getMockBuilder(GeneralResponseValidator::class)
45 ->disableOriginalConstructor()
48 $this->resultFactory = $this->getMockBuilder(ResultInterfaceFactory::class)
49 ->disableOriginalConstructor()
54 $this->generalValidator,
64 public function testValidateSuccessfulTransaction(): void
67 $result = $this->getMockForAbstractClass(ResultInterface::class);
68 $result->method(
'isValid')->willReturn(
true);
69 $this->generalValidator->method(
'validate')->willReturn(
$result);
70 $actual = $this->validator->validate([]);
72 $this->assertSame(
$result, $actual);
81 public function testValidateExpiredTransaction(): void
84 $result = $this->getMockForAbstractClass(ResultInterface::class);
85 $result->method(
'isValid')->willReturn(
false);
86 $this->generalValidator->method(
'validate')->willReturn(
$result);
88 $expected = $this->getMockForAbstractClass(ResultInterface::class);
89 $expected->method(
'isValid')->willReturn(
true);
90 $this->resultFactory->method(
'create')
94 'failsDescription' => [
'Transaction is cancelled offline.'],
97 )->willReturn($expected);
103 'message' =>
'Transaction can only be voided if status is authorized.',
109 'object' =>
new Error([
'errors' =>
$errors]),
113 $actual = $this->validator->validate($buildSubject);
115 $this->assertSame($expected, $actual);
125 public function testValidateWithMultipleErrors(array $responseErrors): void
128 $result = $this->getMockForAbstractClass(ResultInterface::class);
129 $result->method(
'isValid')->willReturn(
false);
131 $this->generalValidator->method(
'validate')->willReturn(
$result);
133 $this->resultFactory->expects($this->never())->method(
'create');
136 'errors' => $responseErrors,
140 'object' =>
new Error([
'errors' =>
$errors]),
144 $actual = $this->validator->validate($buildSubject);
146 $this->assertSame(
$result, $actual);
161 'message' =>
'Credit card type is not accepted by this merchant account.',
165 'message' =>
'Transaction can only be voided if status is authorized.',
173 'message' =>
'Credit card type is not accepted by this merchant account.',