4
4
5
5
use ApiClients \Middleware \Json \JsonStream ;
6
6
use ApiClients \Middleware \Json \JsonDecodeMiddleware ;
7
+ use ApiClients \Middleware \Json \Options ;
7
8
use ApiClients \Tools \Json \JsonDecodeService ;
8
9
use ApiClients \Tools \TestUtilities \TestCase ;
9
10
use Clue \React \Buzz \Message \ReadableBodyStream ;
@@ -19,7 +20,7 @@ public function testPost()
19
20
$ loop = Factory::create ();
20
21
$ service = new JsonDecodeService ($ loop );
21
22
$ middleware = new JsonDecodeMiddleware ($ service );
22
- $ response = new Response (200 , [], '[] ' );
23
+ $ response = new Response (200 , [' Content-Type ' => ' application/json ' ], '[] ' );
23
24
24
25
$ body = await (
25
26
$ middleware ->post ($ response , 'abc ' ),
@@ -34,6 +35,78 @@ public function testPost()
34
35
);
35
36
}
36
37
38
+ public function testPostNoContentType ()
39
+ {
40
+ $ loop = Factory::create ();
41
+ $ service = new JsonDecodeService ($ loop );
42
+ $ middleware = new JsonDecodeMiddleware ($ service );
43
+ $ response = new Response (200 , [], '[] ' );
44
+
45
+ self ::assertSame (
46
+ $ response ,
47
+ await (
48
+ $ middleware ->post ($ response , 'abc ' ),
49
+ $ loop
50
+ )
51
+ );
52
+ }
53
+
54
+ public function testPostNoContentTypeCheck ()
55
+ {
56
+ $ loop = Factory::create ();
57
+ $ service = new JsonDecodeService ($ loop );
58
+ $ middleware = new JsonDecodeMiddleware ($ service );
59
+ $ response = new Response (200 , [], '[] ' );
60
+
61
+ $ body = await (
62
+ $ middleware ->post (
63
+ $ response ,
64
+ 'abc ' ,
65
+ [
66
+ JsonDecodeMiddleware::class => [
67
+ Options::NO_CONTENT_TYPE_CHECK => true ,
68
+ ],
69
+ ]
70
+ ),
71
+ $ loop
72
+ )->getBody ();
73
+
74
+ self ::assertInstanceOf (JsonStream::class, $ body );
75
+
76
+ self ::assertSame (
77
+ [],
78
+ $ body ->getJson ()
79
+ );
80
+ }
81
+
82
+ public function testPostCustomTYpe ()
83
+ {
84
+ $ loop = Factory::create ();
85
+ $ service = new JsonDecodeService ($ loop );
86
+ $ middleware = new JsonDecodeMiddleware ($ service );
87
+ $ response = new Response (200 , ['Content-Type ' => 'custom/type ' ], '[] ' );
88
+
89
+ $ body = await (
90
+ $ middleware ->post (
91
+ $ response ,
92
+ 'abc ' ,
93
+ [
94
+ JsonDecodeMiddleware::class => [
95
+ Options::CONTENT_TYPE => 'custom/type ' ,
96
+ ],
97
+ ]
98
+ ),
99
+ $ loop
100
+ )->getBody ();
101
+
102
+ self ::assertInstanceOf (JsonStream::class, $ body );
103
+
104
+ self ::assertSame (
105
+ [],
106
+ $ body ->getJson ()
107
+ );
108
+ }
109
+
37
110
public function testPostNoJson ()
38
111
{
39
112
$ loop = Factory::create ();
0 commit comments