55namespace Devscast \Flexpay \Tests ;
66
77use Devscast \Flexpay \Client ;
8- use Devscast \Flexpay \Data \TransactionType ;
9- use Devscast \Flexpay \Exception \NetworkException ;
10- use Devscast \Flexpay \Request \PayoutRequest ;
11- use Devscast \Flexpay \Response \PayoutResponse ;
12- use PHPUnit \Framework \TestCase ;
138use Devscast \Flexpay \Credential ;
149use Devscast \Flexpay \Data \Currency ;
1510use Devscast \Flexpay \Data \Transaction ;
11+ use Devscast \Flexpay \Data \Type ;
12+ use Devscast \Flexpay \Exception \NetworkException ;
1613use Devscast \Flexpay \Request \CardRequest ;
1714use Devscast \Flexpay \Request \MobileRequest ;
15+ use Devscast \Flexpay \Request \PayoutRequest ;
1816use Devscast \Flexpay \Response \CardResponse ;
1917use Devscast \Flexpay \Response \CheckResponse ;
2018use Devscast \Flexpay \Response \PaymentResponse ;
19+ use Devscast \Flexpay \Response \PayoutResponse ;
20+ use PHPUnit \Framework \TestCase ;
2121use Symfony \Component \HttpClient \MockHttpClient ;
2222use Symfony \Component \HttpClient \Response \MockResponse ;
2323
2828 */
2929final class ClientTest extends TestCase
3030{
31- private function getFlexpay (callable |MockResponse $ mock ): Client
32- {
33- $ flexpay = new Client (new Credential ('token ' , 'ZONDO ' ));
34- $ reflection = new \ReflectionClass ($ flexpay );
35-
36- $ http = $ reflection ->getProperty ('http ' );
37- $ http ->setAccessible (true );
38- $ http ->setValue ($ flexpay , new MockHttpClient ($ mock ));
39-
40- return $ flexpay ;
41- }
42-
43- private function getResponse (string $ file ): MockResponse
44- {
45- return new MockResponse ((string ) file_get_contents (__DIR__ . '/fixtures/ ' . $ file ));
46- }
47-
4831 public function testCard (): void
4932 {
5033 $ flexpay = $ this ->getFlexpay ($ this ->getResponse ('card_success.json ' ));
@@ -72,24 +55,25 @@ public function testCard(): void
7255 */
7356 public function testPayout (): void
7457 {
75- $ flexpay = $ this ->getFlexpay ($ this ->getResponse ('payout .json ' ));
58+ $ flexpay = $ this ->getFlexpay ($ this ->getResponse ('payout_success .json ' ));
7659
7760 $ request = new PayoutRequest (
7861 amount: 10 ,
7962 reference: 'ref ' ,
8063 currency: Currency::USD ,
8164 callbackUrl: 'http://localhost:8000/callback ' ,
8265 phone: '243123456789 ' ,
83- type: 1
66+ type: Type:: MOBILE
8467 );
8568
8669 $ response = $ flexpay ->payout ($ request );
8770
88- $ this ->assertInstanceOf (PayoutResponse::class,$ response );
71+ $ this ->assertInstanceOf (PayoutResponse::class, $ response );
8972 $ this ->assertTrue ($ response ->isSuccessful ());
90- $ this ->assertEquals ('6708a4708d470_1728619632 ' , $ response ->orderNumber );
91-
73+ $ this ->assertEquals ('Transaction envoyée avec succès. ' , $ response ->message );
74+ $ this -> assertEquals ( ' SQeCGunXEGnr243815877848 ' , $ response -> orderNumber );
9275 }
76+
9377 public function testSuccessCheck (): void
9478 {
9579 $ flexpay = $ this ->getFlexpay ($ this ->getResponse ('check_success.json ' ));
@@ -129,8 +113,6 @@ public function testMobile(): void
129113 $ this ->assertEquals ('DtX9SmCYojWW243123456789 ' , $ response ->orderNumber );
130114 }
131115
132-
133-
134116 public function testHandleCallback (): void
135117 {
136118 /** @var array $data */
@@ -143,4 +125,21 @@ public function testHandleCallback(): void
143125 $ this ->assertEquals ('ZDN000003 ' , $ response ->reference );
144126 $ this ->assertEquals ('UBGC8s9L3VBm243815877848 ' , $ response ->orderNumber );
145127 }
128+
129+ private function getFlexpay (callable |MockResponse $ mock ): Client
130+ {
131+ $ flexpay = new Client (new Credential ('token ' , 'ZONDO ' ));
132+ $ reflection = new \ReflectionClass ($ flexpay );
133+
134+ $ http = $ reflection ->getProperty ('http ' );
135+ $ http ->setAccessible (true );
136+ $ http ->setValue ($ flexpay , new MockHttpClient ($ mock ));
137+
138+ return $ flexpay ;
139+ }
140+
141+ private function getResponse (string $ file ): MockResponse
142+ {
143+ return new MockResponse ((string ) file_get_contents (__DIR__ . '/fixtures/ ' . $ file ));
144+ }
146145}
0 commit comments