@@ -22,12 +22,15 @@ public function createApplication()
22
22
23
23
public function testCallY (): void
24
24
{
25
-
25
+ $ mock = new MockHandler ([
26
+ new Response (200 , ['Content-Type ' => 'application/json ' ], json_encode (['status ' => 'ok ' , 'message ' => 'well done ' ])),
27
+ ]);
28
+ $ handlerStack = new HandlerStack ($ mock );
26
29
$ request = new Request (
27
30
'GET ' ,
28
31
'https://dummyjson.com/test ' ,
29
32
);
30
- $ client = new Client ();
33
+ $ client = new Client ([ ' handler ' => $ handlerStack ] );
31
34
$ response = $ client ->call ($ request );
32
35
$ contents = $ response ->getBody ()->getContents ();
33
36
$ contents_arr = json_decode ($ contents , true , 512 );
@@ -36,11 +39,15 @@ public function testCallY(): void
36
39
37
40
public function testCallX (): void
38
41
{
42
+ $ mock = new MockHandler ([
43
+ new Response (200 , ['Content-Type ' => 'application/json ' ], json_encode (['status ' => 'ok ' , 'message ' => 'well done ' ])),
44
+ ]);
45
+ $ handlerStack = new HandlerStack ($ mock );
39
46
$ request = new Request (
40
47
'GET ' ,
41
48
'https://dummyjson.com/test ' ,
42
49
);
43
- $ client = new Client ();
50
+ $ client = new Client ([ ' handler ' => $ handlerStack ] );
44
51
$ response = $ client ->call ($ request );
45
52
$ contents = $ response ->getBody ()->getContents ();
46
53
$ contents_arr = json_decode ($ contents , true , 512 );
@@ -75,11 +82,15 @@ public function testCallZ(): void
75
82
76
83
public function testCallEksternal (): void
77
84
{
85
+ $ mock = new MockHandler ([
86
+ new Response (200 , ['Content-Type ' => 'application/json ' ], json_encode (['status ' => 'ok ' , 'message ' => 'well done ' ])),
87
+ ]);
88
+ $ handlerStack = new HandlerStack ($ mock );
78
89
$ request = new Request (
79
90
'GET ' ,
80
91
'https://dummyjson.com/test ' ,
81
92
);
82
- $ client = new Client ();
93
+ $ client = new Client ([ ' handler ' => $ handlerStack ] );
83
94
$ response = $ client
84
95
->call ($ request );
85
96
$ contents = $ response ->getBody ()->getContents ();
@@ -114,6 +125,10 @@ public function testCallMultipartSuccess(): void
114
125
115
126
public function testCallMultipartSuccess2 (): void
116
127
{
128
+ $ mock = new MockHandler ([
129
+ new Response (200 , ['Content-Type ' => 'application/json ' ], json_encode (['id ' => '101 ' , 'status ' => 'OK ' , 'message ' => 'well done ' ])),
130
+ ]);
131
+ $ handlerStack = new HandlerStack ($ mock );
117
132
$ f = fopen ('public/docs/hello.txt ' , 'w ' );
118
133
fwrite ($ f , 'hello world ' );
119
134
fclose ($ f );
@@ -128,7 +143,7 @@ public function testCallMultipartSuccess2(): void
128
143
]
129
144
])
130
145
);
131
- $ client = new Client ();
146
+ $ client = new Client ([ ' handler ' => $ handlerStack ] );
132
147
$ resp = $ client
133
148
->call ($ request );
134
149
$ r = json_decode ($ resp ->getBody ()->getContents ());
0 commit comments