@@ -36,11 +36,19 @@ class GigyaTest extends TestCase
3636 */
3737 private $ certPath ;
3838
39+ /**
40+ * @var EmitterInterface|MockInterface
41+ */
42+ private $ emitter ;
43+
3944 public function setUp ()
4045 {
4146 $ this ->guzzleClient = m::mock ('overload:GuzzleHttp\Client ' );
42- $ this ->factory = m::mock ('Graze\Gigya\Response\ResponseFactoryInterface ' );
43- $ this ->certPath = realpath (__DIR__ . '/../../src/ ' . Gigya::CERTIFICATE_FILE );
47+ $ this ->emitter = m::mock (EmitterInterface::class);
48+ $ this ->guzzleClient ->shouldReceive ('getEmitter ' )
49+ ->andReturn ($ this ->emitter );
50+ $ this ->factory = m::mock ('Graze\Gigya\Response\ResponseFactoryInterface ' );
51+ $ this ->certPath = realpath (__DIR__ . '/../../src/ ' . Gigya::CERTIFICATE_FILE );
4452 }
4553
4654 public function tearDown ()
@@ -63,6 +71,7 @@ public function createClient($key = 'key', $secret = 'secret', $dc = Gigya::DC_E
6371 'uidValidator ' => false ,
6472 'factory ' => $ this ->factory ,
6573 ];
74+
6675 return new Gigya ($ key , $ secret , $ userKey , $ options );
6776 }
6877
@@ -75,23 +84,20 @@ public function createClient($key = 'key', $secret = 'secret', $dc = Gigya::DC_E
7584 */
7685 private function setupSubscribers ($ key , $ secret , $ userKey = null )
7786 {
78- $ emitter = m::mock (EmitterInterface::class);
79- $ this ->guzzleClient ->shouldReceive ('getEmitter ' )
80- ->andReturn ($ emitter );
81- $ emitter ->shouldReceive ('attach ' )
82- ->with (m::type (ValidGigyaResponseSubscriber::class))
83- ->once ();
84- $ emitter ->shouldReceive ('attach ' )
85- ->with (m::on (function (SubscriberInterface $ subscriber ) use ($ key , $ secret , $ userKey ) {
86- if ($ subscriber instanceof GigyaAuthInterface) {
87- static ::assertEquals ($ key , $ subscriber ->getApiKey ());
88- static ::assertEquals ($ secret , $ subscriber ->getSecret ());
89- static ::assertEquals ($ userKey , $ subscriber ->getUserKey ());
90- }
91-
92- return true ;
93- }))
94- ->once ();
87+ $ this ->emitter ->shouldReceive ('attach ' )
88+ ->with (m::type (ValidGigyaResponseSubscriber::class))
89+ ->once ();
90+ $ this ->emitter ->shouldReceive ('attach ' )
91+ ->with (m::on (function (SubscriberInterface $ subscriber ) use ($ key , $ secret , $ userKey ) {
92+ if ($ subscriber instanceof GigyaAuthInterface) {
93+ static ::assertEquals ($ key , $ subscriber ->getApiKey ());
94+ static ::assertEquals ($ secret , $ subscriber ->getSecret ());
95+ static ::assertEquals ($ userKey , $ subscriber ->getUserKey ());
96+ }
97+
98+ return true ;
99+ }))
100+ ->once ();
95101 }
96102
97103 /**
@@ -521,7 +527,7 @@ public function testSettingRequestOptionsDoOverrideTheParams()
521527
522528 $ result = $ client ->accounts ()->getAccountInfo (
523529 ['params ' => 'passedThrough ' ],
524- ['query ' => 'value ' , 'verify ' => false ]
530+ ['query ' => 'value ' , 'verify ' => false ]
525531 );
526532
527533 static ::assertSame ($ gigyaResponse , $ result );
@@ -568,7 +574,7 @@ public function testCallingAChainWillCallThatChain()
568574 );
569575 $ client = $ this ->createClient ();
570576
571- $ result = $ client ->fidm ()->{" saml.idp.getConfig " }(
577+ $ result = $ client ->fidm ()->{' saml.idp.getConfig ' }(
572578 ['secret ' => 'newSecret ' ]
573579 );
574580
@@ -701,6 +707,37 @@ public function testTheValidatorWillOnlyCallAssertWhenItCanValidate()
701707 static ::assertSame ($ response , $ client ->accounts ()->getAccountInfo ());
702708 }
703709
710+ public function testRemoveSubscriberWillDetachFromEmitter ()
711+ {
712+ $ response = $ this ->setupCall (
713+ 'accounts.getAccountInfo ' ,
714+ 'https://accounts.eu1.gigya.com/accounts.getAccountInfo ' ,
715+ [
716+ 'auth ' => 'gigya ' ,
717+ 'verify ' => $ this ->certPath ,
718+ 'query ' => [],
719+ ],
720+ 'key ' ,
721+ 'secret '
722+ );
723+ $ client = $ this ->createClient ();
724+
725+ static ::assertSame ($ response , $ client ->accounts ()->getAccountInfo ());
726+
727+ $ subscriber = m::mock (SubscriberInterface::class);
728+ $ this ->emitter ->shouldReceive ('attach ' )
729+ ->with ($ subscriber )
730+ ->once ();
731+
732+ $ client ->addSubscriber ($ subscriber );
733+
734+ $ this ->emitter ->shouldReceive ('detach ' )
735+ ->with ($ subscriber )
736+ ->once ();
737+
738+ $ client ->removeSubscriber ($ subscriber );
739+ }
740+
704741 public function clientCallDataProvider ()
705742 {
706743 return [
0 commit comments