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 1616use Nexmo \Client \Factory \MapFactory ;
1717use Nexmo \Client \Response \Response ;
1818use Nexmo \Client \Signature ;
19+ use Nexmo \Entity \EntityInterface ;
20+ use Nexmo \Verify \Verification ;
1921use Psr \Http \Message \RequestInterface ;
2022use Zend \Diactoros \Uri ;
2123
@@ -233,6 +235,28 @@ public function send(\Psr\Http\Message\RequestInterface $request)
233235 return $ response ;
234236 }
235237
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+
236260 public function __call ($ name , $ args )
237261 {
238262 if (!$ this ->factory ->hasApi ($ name )){
Original file line number Diff line number Diff line change 1515use Nexmo \Client \Credentials \Basic ;
1616use Nexmo \Client \Credentials \OAuth ;
1717use Nexmo \Client \Signature ;
18+ use Nexmo \Verify \Verification ;
1819use Zend \Diactoros \Request ;
1920use Zend \Diactoros \Response ;
2021
@@ -269,6 +270,25 @@ public function testUserAgentString()
269270 $ this ->assertEquals ($ expected , $ agent );
270271 }
271272
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+
272292 /**
273293 * Allow tests to check that the API client is correctly forming the HTTP request before sending it to the HTTP
274294 * client.
You can’t perform that action at this time.
0 commit comments