File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 16
16
use Nexmo \Client \Factory \MapFactory ;
17
17
use Nexmo \Client \Response \Response ;
18
18
use Nexmo \Client \Signature ;
19
+ use Nexmo \Entity \EntityInterface ;
20
+ use Nexmo \Verify \Verification ;
19
21
use Psr \Http \Message \RequestInterface ;
20
22
use Zend \Diactoros \Uri ;
21
23
@@ -233,6 +235,28 @@ public function send(\Psr\Http\Message\RequestInterface $request)
233
235
return $ response ;
234
236
}
235
237
238
+ public function serialize (EntityInterface $ entity )
239
+ {
240
+ if ($ entity instanceof Verification){
241
+ return $ this ->verify ()->serialize ($ entity );
242
+ }
243
+
244
+ throw new \RuntimeException ('unknown class ` ' . get_class ($ entity ) . '`` ' );
245
+ }
246
+
247
+ public function unserialize ($ entity )
248
+ {
249
+ if (is_string ($ entity )){
250
+ $ entity = unserialize ($ entity );
251
+ }
252
+
253
+ if ($ entity instanceof Verification){
254
+ return $ this ->verify ()->unserialize ($ entity );
255
+ }
256
+
257
+ throw new \RuntimeException ('unknown class ` ' . get_class ($ entity ) . '`` ' );
258
+ }
259
+
236
260
public function __call ($ name , $ args )
237
261
{
238
262
if (!$ this ->factory ->hasApi ($ name )){
Original file line number Diff line number Diff line change 15
15
use Nexmo \Client \Credentials \Basic ;
16
16
use Nexmo \Client \Credentials \OAuth ;
17
17
use Nexmo \Client \Signature ;
18
+ use Nexmo \Verify \Verification ;
18
19
use Zend \Diactoros \Request ;
19
20
use Zend \Diactoros \Response ;
20
21
@@ -269,6 +270,25 @@ public function testUserAgentString()
269
270
$ this ->assertEquals ($ expected , $ agent );
270
271
}
271
272
273
+ public function testSerializationProxiesVerify ()
274
+ {
275
+ $ verify = $ this ->prophesize ('Nexmo\Verify\Client ' );
276
+ $ factory = $ this ->prophesize ('Nexmo\Client\Factory\FactoryInterface ' );
277
+
278
+ $ factory ->hasApi ('verify ' )->willReturn (true );
279
+ $ factory ->getApi ('verify ' )->willReturn ($ verify ->reveal ());
280
+
281
+ $ client = new Client ($ this ->basic );
282
+ $ client ->setFactory ($ factory ->reveal ());
283
+
284
+ $ verification = new Verification ('15554441212 ' , 'test app ' );
285
+ $ verify ->serialize ($ verification )->willReturn ('string data ' )->shouldBeCalled ();
286
+ $ verify ->unserialize ($ verification )->willReturn ($ verification )->shouldBeCalled ();
287
+
288
+ $ this ->assertEquals ('string data ' , $ client ->serialize ($ verification ));
289
+ $ this ->assertEquals ($ verification , $ client ->unserialize (serialize ($ verification )));
290
+ }
291
+
272
292
/**
273
293
* Allow tests to check that the API client is correctly forming the HTTP request before sending it to the HTTP
274
294
* client.
You can’t perform that action at this time.
0 commit comments