@@ -82,6 +82,156 @@ public function testResetResponse()
8282 $ this ->assertNull ($ this ->exception ->getRequest ());
8383 }
8484
85+ public function testCannotFetchUri ()
86+ {
87+ $ exception = HttpAdapterException::cannotFetchUri ('uri ' , 'adapter ' , 'error ' );
88+
89+ $ this ->assertInstanceOf ('Http\Adapter\HttpAdapterException ' , $ exception );
90+ $ this ->assertSame (
91+ 'An error occurred when fetching the URI "uri" with the adapter "adapter" ("error"). ' ,
92+ $ exception ->getMessage ()
93+ );
94+ }
95+
96+ public function testCannotLoadCookieJar ()
97+ {
98+ $ exception = HttpAdapterException::cannotLoadCookieJar ('error ' );
99+
100+ $ this ->assertInstanceOf ('Http\Adapter\HttpAdapterException ' , $ exception );
101+ $ this ->assertSame ('An error occurred when loading the cookie jar ("error"). ' , $ exception ->getMessage ());
102+ }
103+
104+ public function testCannotSaveCookieJar ()
105+ {
106+ $ exception = HttpAdapterException::cannotSaveCookieJar ('error ' );
107+
108+ $ this ->assertInstanceOf ('Http\Adapter\HttpAdapterException ' , $ exception );
109+ $ this ->assertSame ('An error occurred when saving the cookie jar ("error"). ' , $ exception ->getMessage ());
110+ }
111+
112+ public function testHttpAdapterDoesNotExist ()
113+ {
114+ $ exception = HttpAdapterException::httpAdapterDoesNotExist ('adapter ' );
115+
116+ $ this ->assertInstanceOf ('Http\Adapter\HttpAdapterException ' , $ exception );
117+ $ this ->assertSame ('The http adapter "adapter" does not exist. ' , $ exception ->getMessage ());
118+ }
119+
120+ public function testHttpAdapterIsNotUsable ()
121+ {
122+ $ exception = HttpAdapterException::httpAdapterIsNotUsable ('adapter ' );
123+
124+ $ this ->assertInstanceOf ('Http\Adapter\HttpAdapterException ' , $ exception );
125+ $ this ->assertSame ('The http adapter "adapter" is not usable. ' , $ exception ->getMessage ());
126+ }
127+
128+ public function testHttpAdaptersAreNotUsable ()
129+ {
130+ $ exception = HttpAdapterException::httpAdaptersAreNotUsable ();
131+
132+ $ this ->assertInstanceOf ('Http\Adapter\HttpAdapterException ' , $ exception );
133+ $ this ->assertSame ('No http adapters are usable. ' , $ exception ->getMessage ());
134+ }
135+
136+ public function testHttpAdapterMustImplementInterface ()
137+ {
138+ $ exception = HttpAdapterException::httpAdapterMustImplementInterface ('class ' );
139+
140+ $ this ->assertInstanceOf ('Http\Adapter\HttpAdapterException ' , $ exception );
141+ $ this ->assertSame (
142+ 'The class "class" must implement "Ivory\HttpAdapter\HttpAdapterInterface". ' ,
143+ $ exception ->getMessage ()
144+ );
145+ }
146+
147+ public function testDoesNotSupportSubAdapter ()
148+ {
149+ $ exception = HttpAdapterException::doesNotSupportSubAdapter ('adapter ' , 'subAdapter ' );
150+
151+ $ this ->assertInstanceOf ('Http\Adapter\HttpAdapterException ' , $ exception );
152+ $ this ->assertSame (
153+ 'The adapter "adapter" does not support the sub-adapter "subAdapter". ' ,
154+ $ exception ->getMessage ()
155+ );
156+ }
157+
158+ public function testExtensionIsNotLoaded ()
159+ {
160+ $ exception = HttpAdapterException::extensionIsNotLoaded ('extension ' , 'adapter ' );
161+
162+ $ this ->assertInstanceOf ('Http\Adapter\HttpAdapterException ' , $ exception );
163+ $ this ->assertSame (
164+ 'The adapter "adapter" expects the PHP extension "extension" to be loaded. ' ,
165+ $ exception ->getMessage ()
166+ );
167+ }
168+
169+ public function testMaxRedirectsExceeded ()
170+ {
171+ $ exception = HttpAdapterException::maxRedirectsExceeded ('uri ' , 5 , 'adapter ' );
172+
173+ $ this ->assertInstanceOf ('Http\Adapter\HttpAdapterException ' , $ exception );
174+ $ this ->assertSame (
175+ 'An error occurred when fetching the URI "uri" with the adapter "adapter" ("Max redirects exceeded (5)"). ' ,
176+ $ exception ->getMessage ()
177+ );
178+ }
179+
180+ public function testRequestIsNotValidWithObject ()
181+ {
182+ $ exception = HttpAdapterException::requestIsNotValid (new \stdClass ());
183+
184+ $ this ->assertInstanceOf ('Http\Adapter\HttpAdapterException ' , $ exception );
185+ $ this ->assertSame (
186+ 'The request must be a string, an array or implement "Psr\Http\Message\RequestInterface" ("stdClass" given). ' ,
187+ $ exception ->getMessage ()
188+ );
189+ }
190+
191+ public function testRequestIsNotValidWithScalar ()
192+ {
193+ $ exception = HttpAdapterException::requestIsNotValid (true );
194+
195+ $ this ->assertInstanceOf ('Http\Adapter\HttpAdapterException ' , $ exception );
196+ $ this ->assertSame (
197+ 'The request must be a string, an array or implement "Psr\Http\Message\RequestInterface" ("boolean" given). ' ,
198+ $ exception ->getMessage ()
199+ );
200+ }
201+
202+ public function testStreamIsNotValidWithObject ()
203+ {
204+ $ exception = HttpAdapterException::streamIsNotValid (new \stdClass (), 'wrapper ' , 'expected ' );
205+
206+ $ this ->assertInstanceOf ('Http\Adapter\HttpAdapterException ' , $ exception );
207+ $ this ->assertSame (
208+ 'The stream "wrapper" only accepts a "expected" (current: "stdClass"). ' ,
209+ $ exception ->getMessage ()
210+ );
211+ }
212+
213+ public function testStreamIsNotValidWithScalar ()
214+ {
215+ $ exception = HttpAdapterException::streamIsNotValid (true , 'wrapper ' , 'expected ' );
216+
217+ $ this ->assertInstanceOf ('Http\Adapter\HttpAdapterException ' , $ exception );
218+ $ this ->assertSame (
219+ 'The stream "wrapper" only accepts a "expected" (current: "boolean"). ' ,
220+ $ exception ->getMessage ()
221+ );
222+ }
223+
224+ public function testTimeoutExceeded ()
225+ {
226+ $ exception = HttpAdapterException::timeoutExceeded ('uri ' , 1.1 , 'adapter ' );
227+
228+ $ this ->assertInstanceOf ('Http\Adapter\HttpAdapterException ' , $ exception );
229+ $ this ->assertSame (
230+ 'An error occurred when fetching the URI "uri" with the adapter "adapter" ("Timeout exceeded (1.10)"). ' ,
231+ $ exception ->getMessage ()
232+ );
233+ }
234+
85235 /**
86236 * Creates a request mock
87237 *
0 commit comments