4
4
5
5
use Http \Client \Common \Plugin ;
6
6
use Http \Client \Common \Plugin \AddPathPlugin ;
7
- use Http \Client \Common \PluginClient ;
8
- use Http \Client \HttpClient ;
7
+ use Http \Client \Promise \HttpFulfilledPromise ;
9
8
use Nyholm \Psr7 \Request ;
10
9
use Nyholm \Psr7 \Response ;
11
10
use Nyholm \Psr7 \Uri ;
@@ -24,7 +23,7 @@ class AddPathPluginTest extends TestCase
24
23
*/
25
24
private $ first ;
26
25
27
- protected function setUp ()
26
+ protected function setUp (): void
28
27
{
29
28
$ this ->first = function () {};
30
29
$ this ->plugin = new AddPathPlugin (new Uri ('/api ' ));
@@ -34,16 +33,18 @@ public function testRewriteSameUrl()
34
33
{
35
34
$ verify = function (RequestInterface $ request ) {
36
35
$ this ->assertEquals ('https://example.com/api/foo ' , $ request ->getUri ()->__toString ());
36
+
37
+ return new HttpFulfilledPromise (new Response ());
37
38
};
38
39
39
- $ request = new Request ('GET ' , 'https://example.com/foo ' , ['Content-Type ' => 'text/html ' ]);
40
+ $ request = new Request ('GET ' , 'https://example.com/foo ' , ['Content-Type ' => 'text/html ' ]);
40
41
$ this ->plugin ->handleRequest ($ request , $ verify , $ this ->first );
41
42
42
43
// Make a second call with the same $request object
43
44
$ this ->plugin ->handleRequest ($ request , $ verify , $ this ->first );
44
45
45
46
// Make a new call with a new object but same URL
46
- $ request = new Request ('GET ' , 'https://example.com/foo ' , ['Content-Type ' => 'text/plain ' ]);
47
+ $ request = new Request ('GET ' , 'https://example.com/foo ' , ['Content-Type ' => 'text/plain ' ]);
47
48
$ this ->plugin ->handleRequest ($ request , $ verify , $ this ->first );
48
49
}
49
50
@@ -56,7 +57,11 @@ public function testRewriteCallingThePluginTwice()
56
57
// Run the plugin again with the modified request
57
58
$ this ->plugin ->handleRequest ($ request , function (RequestInterface $ request ) {
58
59
$ this ->assertEquals ('https://example.com/api/foo ' , $ request ->getUri ()->__toString ());
60
+
61
+ return new HttpFulfilledPromise (new Response ());
59
62
}, $ this ->first );
63
+
64
+ return new HttpFulfilledPromise (new Response ());
60
65
}, $ this ->first );
61
66
}
62
67
@@ -65,18 +70,24 @@ public function testRewriteWithDifferentUrl()
65
70
$ request = new Request ('GET ' , 'https://example.com/foo ' );
66
71
$ this ->plugin ->handleRequest ($ request , function (RequestInterface $ request ) {
67
72
$ this ->assertEquals ('https://example.com/api/foo ' , $ request ->getUri ()->__toString ());
73
+
74
+ return new HttpFulfilledPromise (new Response ());
68
75
}, $ this ->first );
69
76
70
77
$ request = new Request ('GET ' , 'https://example.com/bar ' );
71
78
$ this ->plugin ->handleRequest ($ request , function (RequestInterface $ request ) {
72
79
$ this ->assertEquals ('https://example.com/api/bar ' , $ request ->getUri ()->__toString ());
80
+
81
+ return new HttpFulfilledPromise (new Response ());
73
82
}, $ this ->first );
74
83
}
75
84
76
85
public function testRewriteWhenPathIsIncluded ()
77
86
{
78
87
$ verify = function (RequestInterface $ request ) {
79
88
$ this ->assertEquals ('https://example.com/api/foo ' , $ request ->getUri ()->__toString ());
89
+
90
+ return new HttpFulfilledPromise (new Response ());
80
91
};
81
92
82
93
$ request = new Request ('GET ' , 'https://example.com/api/foo ' );
0 commit comments