|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Omnipay\IcepayPayments\Tests\Message; |
| 4 | + |
| 5 | +use GuzzleHttp\Psr7\Request; |
| 6 | +use Omnipay\IcepayPayments\Message\CompleteAuthoriseAndCaptureRequest; |
| 7 | +use Omnipay\IcepayPayments\Message\CompleteAuthoriseAndCaptureResponse; |
| 8 | +use Omnipay\IcepayPayments\Tests\AbstractTestCase; |
| 9 | +use Symfony\Component\HttpFoundation\Request as SymfonyRequest; |
| 10 | + |
| 11 | +/** |
| 12 | + * Class CompleteAuthoriseAndCaptureRequestTest. |
| 13 | + */ |
| 14 | +class CompleteAuthoriseAndCaptureRequestTest extends AbstractTestCase |
| 15 | +{ |
| 16 | + /** |
| 17 | + * @var CompleteAuthoriseAndCaptureRequest |
| 18 | + */ |
| 19 | + protected $request; |
| 20 | + |
| 21 | + /** |
| 22 | + * Creates a new CompleteAuthoriseAndCaptureRequestTest instance. |
| 23 | + */ |
| 24 | + protected function setUp(): void |
| 25 | + { |
| 26 | + parent::setUp(); |
| 27 | + |
| 28 | + $this->request = new CompleteAuthoriseAndCaptureRequest($this->httpClient, $this->httpRequest); |
| 29 | + $this->request->setBaseUrl('https://www.superbrave.nl'); |
| 30 | + $this->request->setSecretKey('NjRlYjM3MTctOGI1ZC00MDg4LTgxMDgtOTMyMjQ2NzVlNTM4'); |
| 31 | + $this->request->setContractProfileId('64eb3717-8b5d-4088-8108-93224675e538'); |
| 32 | + $this->request->setTransactionReference('e7ca29c8-f1f4-4a4c-a968-0f9667d0519d'); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Tests if CompleteAuthoriseAndCaptureRequest::getData validates the basic keys and returns an array of data. |
| 37 | + */ |
| 38 | + public function testGetData(): void |
| 39 | + { |
| 40 | + $expectedData = [ |
| 41 | + 'ContractProfileId' => '64eb3717-8b5d-4088-8108-93224675e538', |
| 42 | + ]; |
| 43 | + $this->assertEquals($expectedData, $this->request->getData()); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Tests if CompleteAuthoriseAndCaptureRequest::sendData returns a CompleteAuthoriseAndCaptureResponse. |
| 48 | + */ |
| 49 | + public function testSendData(): void |
| 50 | + { |
| 51 | + $data = [ |
| 52 | + 'AmountInCents' => 1337, |
| 53 | + 'CurrencyCode' => 'EUR', |
| 54 | + 'Reference' => '2fad9b1b-a2d3-455c-bc29-b79516fd3257', |
| 55 | + 'Timestamp' => '2019-03-09T12:00:00Z', |
| 56 | + ]; |
| 57 | + $response = $this->request->sendData($data); |
| 58 | + |
| 59 | + $this->assertInstanceOf(CompleteAuthoriseAndCaptureResponse::class, $response); |
| 60 | + |
| 61 | + $expectedRequest = new Request( |
| 62 | + SymfonyRequest::METHOD_POST, |
| 63 | + 'https://www.superbrave.nl/transaction/e7ca29c8-f1f4-4a4c-a968-0f9667d0519d' |
| 64 | + ); |
| 65 | + |
| 66 | + $this->assertEquals($expectedRequest->getMethod(), $this->clientMock->getLastRequest()->getMethod()); |
| 67 | + $this->assertEquals($expectedRequest->getUri(), $this->clientMock->getLastRequest()->getUri()); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Tests if CompleteAuthoriseAndCaptureRequest getRequest function will return a Symfony HttpRequest object. |
| 72 | + */ |
| 73 | + public function testGetHttpRequest(): void |
| 74 | + { |
| 75 | + $this->assertSame($this->httpRequest, $this->request->getHttpRequest()); |
| 76 | + $this->assertInstanceOf(SymfonyRequest::class, $this->request->getHttpRequest()); |
| 77 | + } |
| 78 | +} |
0 commit comments