|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace ComgateTest; |
| 4 | + |
| 5 | +use Comgate\Enum\ResponseCode; |
| 6 | +use Comgate\Exception\InvalidArgumentException; |
| 7 | +use Comgate\Response\CreatePaymentResponse; |
| 8 | +use PHPUnit\Framework\TestCase; |
| 9 | + |
| 10 | +class CreatePaymentResponseTest extends TestCase |
| 11 | +{ |
| 12 | + |
| 13 | + /** |
| 14 | + * test only if no exception throws |
| 15 | + * @doesNotPerformAssertions |
| 16 | + */ |
| 17 | + public function test__construct() |
| 18 | + { |
| 19 | + new CreatePaymentResponse( |
| 20 | + [ |
| 21 | + 'code' => ResponseCode::CODE_OK, |
| 22 | + 'message' => 'OK', |
| 23 | + 'transId' => 'asd-asd-asd-asd', |
| 24 | + 'redirect' => 'http://test.cz', |
| 25 | + ] |
| 26 | + ); |
| 27 | + } |
| 28 | + |
| 29 | + |
| 30 | + public function test__constructCodeException() |
| 31 | + { |
| 32 | + $this->expectException(InvalidArgumentException::class); |
| 33 | + |
| 34 | + new CreatePaymentResponse( |
| 35 | + [ |
| 36 | + 'message' => 'OK', |
| 37 | + 'transId' => 'asd-asd-asd-asd', |
| 38 | + 'redirect' => 'http://test.cz', |
| 39 | + ] |
| 40 | + ); |
| 41 | + } |
| 42 | + |
| 43 | + |
| 44 | + public function test__constructMessageException() |
| 45 | + { |
| 46 | + $this->expectException(InvalidArgumentException::class); |
| 47 | + |
| 48 | + new CreatePaymentResponse( |
| 49 | + [ |
| 50 | + 'code' => ResponseCode::CODE_OK, |
| 51 | + 'transId' => 'asd-asd-asd-asd', |
| 52 | + 'redirect' => 'http://test.cz', |
| 53 | + ] |
| 54 | + ); |
| 55 | + } |
| 56 | + |
| 57 | + |
| 58 | + public function test__constructTransIdException() |
| 59 | + { |
| 60 | + $this->expectException(InvalidArgumentException::class); |
| 61 | + |
| 62 | + new CreatePaymentResponse( |
| 63 | + [ |
| 64 | + 'code' => ResponseCode::CODE_OK, |
| 65 | + 'message' => 'OK', |
| 66 | + 'redirect' => 'http://test.cz', |
| 67 | + ] |
| 68 | + ); |
| 69 | + } |
| 70 | + |
| 71 | + |
| 72 | + public function test__constructRedirectException() |
| 73 | + { |
| 74 | + $this->expectException(InvalidArgumentException::class); |
| 75 | + |
| 76 | + new CreatePaymentResponse( |
| 77 | + [ |
| 78 | + 'code' => ResponseCode::CODE_OK, |
| 79 | + 'message' => 'OK', |
| 80 | + 'transId' => 'asd-asd-asd-asd', |
| 81 | + ] |
| 82 | + ); |
| 83 | + } |
| 84 | + |
| 85 | + public function testIsOk() |
| 86 | + { |
| 87 | + $response = new CreatePaymentResponse( |
| 88 | + [ |
| 89 | + 'code' => ResponseCode::CODE_OK, |
| 90 | + 'message' => 'OK', |
| 91 | + 'transId' => 'asd-asd-asd-asd', |
| 92 | + 'redirect' => 'http://test.cz', |
| 93 | + ] |
| 94 | + ); |
| 95 | + |
| 96 | + $this->assertSame(true, $response->isOk()); |
| 97 | + } |
| 98 | + |
| 99 | + public function testIsNotOk() |
| 100 | + { |
| 101 | + $response = new CreatePaymentResponse( |
| 102 | + [ |
| 103 | + 'code' => ResponseCode::CODE_CHOOSE_CORRECT_METHOD, |
| 104 | + 'message' => 'OK', |
| 105 | + 'transId' => 'asd-asd-asd-asd', |
| 106 | + 'redirect' => 'http://test.cz', |
| 107 | + ] |
| 108 | + ); |
| 109 | + |
| 110 | + $this->assertSame(false, $response->isOk()); |
| 111 | + } |
| 112 | + |
| 113 | + public function testGetMessage() |
| 114 | + { |
| 115 | + $response = new CreatePaymentResponse( |
| 116 | + [ |
| 117 | + 'code' => ResponseCode::CODE_CHOOSE_CORRECT_METHOD, |
| 118 | + 'message' => 'OK', |
| 119 | + 'transId' => 'asd-asd-asd-asd', |
| 120 | + 'redirect' => 'http://test.cz', |
| 121 | + ] |
| 122 | + ); |
| 123 | + |
| 124 | + $this->assertSame('OK', $response->getMessage()); |
| 125 | + } |
| 126 | + |
| 127 | + public function testGetTransId() |
| 128 | + { |
| 129 | + $response = new CreatePaymentResponse( |
| 130 | + [ |
| 131 | + 'code' => ResponseCode::CODE_CHOOSE_CORRECT_METHOD, |
| 132 | + 'message' => 'OK', |
| 133 | + 'transId' => 'asd-asd-asd-asd', |
| 134 | + 'redirect' => 'http://test.cz', |
| 135 | + ] |
| 136 | + ); |
| 137 | + |
| 138 | + $this->assertSame('asd-asd-asd-asd', $response->getTransId()); |
| 139 | + } |
| 140 | + |
| 141 | + public function testGetRedirect() |
| 142 | + { |
| 143 | + $response = new CreatePaymentResponse( |
| 144 | + [ |
| 145 | + 'code' => ResponseCode::CODE_CHOOSE_CORRECT_METHOD, |
| 146 | + 'message' => 'OK', |
| 147 | + 'transId' => 'asd-asd-asd-asd', |
| 148 | + 'redirect' => 'http://test.cz', |
| 149 | + ] |
| 150 | + ); |
| 151 | + |
| 152 | + $this->assertSame('http://test.cz', $response->getRedirectUrl()); |
| 153 | + } |
| 154 | + |
| 155 | +} |
0 commit comments