2
2
3
3
namespace Unit \Service ;
4
4
5
- use Flutterwave \Helper \Config ;
5
+ use Flutterwave \Test \ Resources \ Setup \Config ;
6
6
use Flutterwave \Payload ;
7
7
use Flutterwave \Service \PaymentPlan ;
8
8
use PHPUnit \Framework \TestCase ;
9
9
10
10
class PaymentPlanTest extends TestCase
11
11
{
12
+
13
+ public PaymentPlan $ service ;
14
+ protected function setUp (): void
15
+ {
16
+ $ this ->service = new PaymentPlan (
17
+ Config::setUp (
18
+ $ _SERVER [Config::SECRET_KEY ],
19
+ $ _SERVER [Config::PUBLIC_KEY ],
20
+ $ _SERVER [Config::ENCRYPTION_KEY ],
21
+ $ _SERVER [Config::ENV ]
22
+ )
23
+ );
24
+ }
25
+
12
26
public function testPlanCreation ()
13
27
{
14
28
$ payload = new Payload ();
@@ -17,9 +31,8 @@ public function testPlanCreation()
17
31
$ payload ->set ("interval " , "monthly " );
18
32
$ payload ->set ("duration " , "1 " );
19
33
20
- $ service = new PaymentPlan ();
21
34
22
- $ request = $ service ->create ($ payload );
35
+ $ request = $ this -> service ->create ($ payload );
23
36
24
37
$ this ->assertTrue (property_exists ($ request ,'data ' ) && !empty ($ request ->data ->id ));
25
38
@@ -31,15 +44,13 @@ public function testPlanCreation()
31
44
*/
32
45
public function testRetrievingPlan ($ id )
33
46
{
34
- $ service = new PaymentPlan ();
35
- $ request = $ service ->get ($ id );
47
+ $ request = $ this ->service ->get ($ id );
36
48
$ this ->assertTrue (property_exists ($ request ,'data ' ) && !empty ($ request ->data ->id ));
37
49
}
38
50
39
51
public function testRetrievingPlans ()
40
52
{
41
- $ service = new PaymentPlan ();
42
- $ request = $ service ->list ();
53
+ $ request = $ this ->service ->list ();
43
54
$ this ->assertTrue (property_exists ($ request ,'data ' ) && \is_array ($ request ->data ));
44
55
}
45
56
@@ -48,11 +59,10 @@ public function testRetrievingPlans()
48
59
*/
49
60
public function testUpdatingPlan ($ id )
50
61
{
51
- $ service = new PaymentPlan ();
52
62
$ payload = new Payload ();
53
63
$ payload ->set ("amount " ,"600 " );
54
64
$ payload ->set ("status " , "active " );
55
- $ request = $ service ->update ($ id , $ payload );
65
+ $ request = $ this -> service ->update ($ id , $ payload );
56
66
$ this ->assertTrue (property_exists ($ request ,'data ' ) && isset ($ request ->data ->id ));
57
67
}
58
68
@@ -61,8 +71,7 @@ public function testUpdatingPlan($id)
61
71
*/
62
72
public function testCancelingPlan ($ id )
63
73
{
64
- $ service = new PaymentPlan ();
65
- $ request = $ service ->cancel ($ id );
74
+ $ request = $ this ->service ->cancel ($ id );
66
75
$ this ->assertTrue (property_exists ($ request ,'data ' ) && $ request ->data ->status == "cancelled " );
67
76
}
68
77
}
0 commit comments