function it_logs_in_after_responses_that_required_login_and_retries_the_request(SiteConfig $siteConfig, Factory $authenticatorFactory, CompleteEvent $completeEvent, Authenticator $authenticator, ClientInterface $guzzle)
 {
     $siteConfig->requiresLogin()->willReturn(true);
     $authenticatorFactory->buildFromSiteConfig($siteConfig)->willReturn($authenticator);
     $authenticator->isLoginRequired(Argument::type('string'))->willReturn(true);
     $authenticator->login($guzzle)->shouldBeCalled();
     $completeEvent->retry()->shouldBeCalled();
     $this->loginIfRequested($completeEvent);
 }
 public function loginIfRequested(CompleteEvent $event)
 {
     if (($config = $this->buildSiteConfig($event->getRequest())) === false) {
         return;
     }
     if (!$config->requiresLogin()) {
         return;
     }
     $authenticator = $this->authenticatorFactory->buildFromSiteConfig($config);
     if ($authenticator->isLoginRequired($event->getResponse()->getBody())) {
         $client = $event->getClient();
         $emitter = $client->getEmitter();
         $emitter->detach($this);
         $authenticator->login($client);
         $emitter->attach($this);
         $event->retry();
     }
 }