11<?php declare (strict_types=1 );
22namespace MultiSafepay \Tests \Unit \Api \PaymentMethods ;
33
4+ use Exception ;
45use MultiSafepay \Api \PaymentMethodManager ;
56use MultiSafepay \Api \PaymentMethods \PaymentMethod ;
67use MultiSafepay \Exception \InvalidDataInitializationException ;
78use MultiSafepay \Tests \Integration \MockClient ;
89use PHPUnit \Framework \TestCase ;
10+ use Psr \Http \Client \ClientExceptionInterface ;
911
1012/**
1113 * Class PaymentMethodTest
@@ -23,9 +25,11 @@ class PaymentMethodTest extends TestCase
2325 */
2426 private $ wrongData ;
2527
26-
2728 /**
2829 * Test normal initialization
30+ *
31+ * @throws Exception
32+ * @throws ClientExceptionInterface
2933 */
3034 public function testNormalInitialization ()
3135 {
@@ -50,6 +54,9 @@ public function testNormalInitialization()
5054
5155 /**
5256 * Test wrong initialization
57+ *
58+ * @throws Exception
59+ * @throws ClientExceptionInterface
5360 */
5461 public function testIncompleteData ()
5562 {
@@ -151,6 +158,65 @@ public function testGetDataIncludesManualCaptureWhenEnabled()
151158 $ this ->assertTrue ($ result [PaymentMethod::MANUAL_CAPTURE_KEY ][PaymentMethod::IS_ENABLED_KEY ]);
152159 $ this ->assertTrue ($ result [PaymentMethod::MANUAL_CAPTURE_KEY ][PaymentMethod::SUPPORTED_KEY ]);
153160 }
161+
162+ /**
163+ * Test if the wallet payment method is detected from the payload
164+ *
165+ * @throws InvalidDataInitializationException
166+ */
167+ public function testIsWalletReturnsTrueWhenPayloadMarksWallet ()
168+ {
169+ $ data = $ this ->getValidData ();
170+ $ data [PaymentMethod::IS_WALLET_KEY ] = true ;
171+
172+ $ paymentMethod = new PaymentMethod ($ data );
173+
174+ $ this ->assertTrue ($ paymentMethod ->isWallet ());
175+ }
176+
177+ /**
178+ * Test if a non-wallet payment method is detected from the payload
179+ *
180+ * @throws InvalidDataInitializationException
181+ */
182+ public function testIsWalletReturnsFalseWhenPayloadDoesNotMarkWallet ()
183+ {
184+ $ paymentMethod = new PaymentMethod ($ this ->getValidData ());
185+
186+ $ this ->assertFalse ($ paymentMethod ->isWallet ());
187+ }
188+
189+ /**
190+ * Test if wallet defaults to false when payload omits is_wallet
191+ *
192+ * @throws InvalidDataInitializationException
193+ */
194+ public function testIsWalletReturnsFalseWhenIsWalletKeyIsMissing ()
195+ {
196+ $ data = $ this ->getValidData ();
197+ unset($ data [PaymentMethod::IS_WALLET_KEY ]);
198+
199+ $ paymentMethod = new PaymentMethod ($ data );
200+
201+ $ this ->assertFalse ($ paymentMethod ->isWallet ());
202+ }
203+
204+ /**
205+ * Test if getData includes wallet flag
206+ *
207+ * @throws InvalidDataInitializationException
208+ */
209+ public function testGetDataIncludesIsWallet ()
210+ {
211+ $ data = $ this ->getValidData ();
212+ $ data [PaymentMethod::IS_WALLET_KEY ] = true ;
213+
214+ $ paymentMethod = new PaymentMethod ($ data );
215+ $ result = $ paymentMethod ->getData ();
216+
217+ $ this ->assertArrayHasKey (PaymentMethod::IS_WALLET_KEY , $ result );
218+ $ this ->assertTrue ($ result [PaymentMethod::IS_WALLET_KEY ]);
219+ }
154220
155221 /**
156222 * @return array
@@ -205,6 +271,7 @@ private function getValidData(): array
205271 PaymentMethod::ICON_URLS_VECTOR_KEY => 'https://example.com/visa.svg ' ,
206272 ],
207273 PaymentMethod::ALLOWED_CURRENCIES_KEY => ['EUR ' ],
274+ PaymentMethod::IS_WALLET_KEY => false ,
208275 ];
209276 }
210277
0 commit comments