Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SubjectReaderTest.php
Go to the documentation of this file.
1 <?php
7 
8 use Braintree\Result\Successful;
9 use Braintree\Transaction;
11 
15 class SubjectReaderTest extends \PHPUnit\Framework\TestCase
16 {
20  private $subjectReader;
21 
25  protected function setUp()
26  {
27  $this->subjectReader = new SubjectReader();
28  }
29 
36  public function testReadCustomerIdWithException(): void
37  {
38  $this->subjectReader->readCustomerId([]);
39  }
40 
45  public function testReadCustomerId(): void
46  {
47  $customerId = 1;
48  $this->assertEquals($customerId, $this->subjectReader->readCustomerId(['customer_id' => $customerId]));
49  }
50 
57  public function testReadPublicHashWithException(): void
58  {
59  $this->subjectReader->readPublicHash([]);
60  }
61 
66  public function testReadPublicHash(): void
67  {
68  $hash = 'fj23djf2o1fd';
69  $this->assertEquals($hash, $this->subjectReader->readPublicHash(['public_hash' => $hash]));
70  }
71 
78  public function testReadPayPalWithException(): void
79  {
80  $transaction = Transaction::factory([
81  'id' => 'u38rf8kg6vn',
82  ]);
83  $this->subjectReader->readPayPal($transaction);
84  }
85 
90  public function testReadPayPal(): void
91  {
92  $paypal = [
93  'paymentId' => '3ek7dk7fn0vi1',
94  'payerEmail' => '[email protected]',
95  ];
96  $transaction = Transaction::factory([
97  'id' => '4yr95vb',
98  'paypal' => $paypal,
99  ]);
100 
101  $this->assertEquals($paypal, $this->subjectReader->readPayPal($transaction));
102  }
103 
109  public function testReadTransaction(): void
110  {
111  $transaction = Transaction::factory(['id' => 1]);
112  $response = [
113  'object' => new Successful($transaction, 'transaction'),
114  ];
115  $actual = $this->subjectReader->readTransaction($response);
116 
117  $this->assertSame($transaction, $actual);
118  }
119 
129  public function testReadTransactionWithInvalidResponse(array $response, string $expectedMessage): void
130  {
131  $this->expectExceptionMessage($expectedMessage);
132  $this->subjectReader->readTransaction($response);
133  }
134 
140  public function invalidTransactionResponseDataProvider(): array
141  {
142  $transaction = new \stdClass();
143  $response = new \stdClass();
144  $response->transaction = $transaction;
145 
146  return [
147  [
148  'response' => [
149  'object' => [],
150  ],
151  'expectedMessage' => 'Response object does not exist.',
152  ],
153  [
154  'response' => [
155  'object' => new \stdClass(),
156  ],
157  'expectedMessage' => 'The object is not a class \Braintree\Transaction.',
158  ],
159  [
160  'response' => [
161  'object' => $response,
162  ],
163  'expectedMessage' => 'The object is not a class \Braintree\Transaction.',
164  ],
165  ];
166  }
167 }
$transaction
$response
Definition: 404.php:11
testReadTransactionWithInvalidResponse(array $response, string $expectedMessage)