@@ -87,6 +87,70 @@ public function testNonBufferedGetRequest()
87
87
$ response ->getContent ();
88
88
}
89
89
90
+ public function testBufferSink ()
91
+ {
92
+ $ sink = fopen ('php://temp ' , 'w+ ' );
93
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
94
+ $ response = $ client ->request ('GET ' , 'http://localhost:8057 ' , [
95
+ 'buffer ' => $ sink ,
96
+ 'headers ' => ['Foo ' => 'baR ' ],
97
+ ]);
98
+
99
+ $ body = $ response ->toArray ();
100
+ $ this ->assertSame ('baR ' , $ body ['HTTP_FOO ' ]);
101
+
102
+ rewind ($ sink );
103
+ $ sink = stream_get_contents ($ sink );
104
+ $ this ->assertSame ($ sink , $ response ->getContent ());
105
+ }
106
+
107
+ public function testConditionalBuffering ()
108
+ {
109
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
110
+ $ response = $ client ->request ('GET ' , 'http://localhost:8057 ' );
111
+ $ firstContent = $ response ->getContent ();
112
+ $ secondContent = $ response ->getContent ();
113
+
114
+ $ this ->assertSame ($ firstContent , $ secondContent );
115
+
116
+ $ response = $ client ->request ('GET ' , 'http://localhost:8057 ' , ['buffer ' => function () { return false ; }]);
117
+ $ response ->getContent ();
118
+
119
+ $ this ->expectException (TransportExceptionInterface::class);
120
+ $ response ->getContent ();
121
+ }
122
+
123
+ public function testReentrantBufferCallback ()
124
+ {
125
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
126
+
127
+ $ response = $ client ->request ('GET ' , 'http://localhost:8057 ' , ['buffer ' => function () use (&$ response ) {
128
+ $ response ->cancel ();
129
+
130
+ return true ;
131
+ }]);
132
+
133
+ $ this ->assertSame (200 , $ response ->getStatusCode ());
134
+
135
+ $ this ->expectException (TransportExceptionInterface::class);
136
+ $ response ->getContent ();
137
+ }
138
+
139
+ public function testThrowingBufferCallback ()
140
+ {
141
+ $ client = $ this ->getHttpClient (__FUNCTION__ );
142
+
143
+ $ response = $ client ->request ('GET ' , 'http://localhost:8057 ' , ['buffer ' => function () {
144
+ throw new \Exception ('Boo ' );
145
+ }]);
146
+
147
+ $ this ->assertSame (200 , $ response ->getStatusCode ());
148
+
149
+ $ this ->expectException (TransportExceptionInterface::class);
150
+ $ this ->expectExceptionMessage ('Boo ' );
151
+ $ response ->getContent ();
152
+ }
153
+
90
154
public function testUnsupportedOption ()
91
155
{
92
156
$ client = $ this ->getHttpClient (__FUNCTION__ );
0 commit comments