File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -271,6 +271,22 @@ public function __invoke($key = null)
271271 return $ this ->key ($ key );
272272 }
273273
274+ /**
275+ * Converts response to string on current key.
276+ *
277+ * @return string
278+ */
279+ public function __toString ()
280+ {
281+ $ value = $ this ->get ();
282+
283+ if (is_array ($ value ) || is_object ($ value )) {
284+ return json_encode ($ value );
285+ }
286+
287+ return (string ) $ value ;
288+ }
289+
274290 /**
275291 * Constructs full key.
276292 *
Original file line number Diff line number Diff line change @@ -20,6 +20,22 @@ public function setUp()
2020 $ this ->response = $ this ->response ->withHeader ('X-Test ' , 'test ' );
2121 }
2222
23+ /**
24+ * Test casting response to string.
25+ *
26+ * @return void
27+ */
28+ public function testResponseToString ()
29+ {
30+ $ response = $ this ->response ;
31+ $ this ->assertSame ((string ) $ response ('difficulty ' ), '1 ' );
32+ $ this ->assertSame ((string ) $ response ('confirmations ' ), '449162 ' );
33+ $ this ->assertSame (
34+ (string ) $ response ('tx ' ),
35+ json_encode (self ::$ getBlockResponse ['tx ' ])
36+ );
37+ }
38+
2339 /**
2440 * Test response with result.
2541 *
You can’t perform that action at this time.
0 commit comments