File tree 2 files changed +32
-0
lines changed
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)
271
271
return $ this ->key ($ key );
272
272
}
273
273
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
+
274
290
/**
275
291
* Constructs full key.
276
292
*
Original file line number Diff line number Diff line change @@ -20,6 +20,22 @@ public function setUp()
20
20
$ this ->response = $ this ->response ->withHeader ('X-Test ' , 'test ' );
21
21
}
22
22
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
+
23
39
/**
24
40
* Test response with result.
25
41
*
You can’t perform that action at this time.
0 commit comments