Beispiel #1
0
 /**
  * @param  string $captchaId
  * @return false|DeathByCaptchaCaptchaSolution
  */
 private function pullSolutionFor($captchaId)
 {
     $maxAttempts = $this->pullPreferences->getMaxAttempts();
     while ($maxAttempts--) {
         /* @var Response $response */
         $response = $this->httpClient->get('/api/captcha/' . $captchaId, ['query' => ['username' => $this->credentials->getUsername(), 'password' => $this->credentials->getPassword()]]);
         $json = $response->json();
         if (!empty($json['text'])) {
             return new DeathByCaptchaCaptchaSolution($json['text'], $captchaId);
         }
         sleep($this->pullPreferences->getInterval());
     }
     return false;
 }
 /**
  * @test
  */
 public function pullSolutionForReturnsFalse()
 {
     $mock = new Mock([new Response(200, [], Stream::factory(json_encode(['captcha' => uniqid('', true), 'text' => '']))), new Response(200, [], Stream::factory(json_encode(['captcha' => uniqid('', true), 'text' => '']))), new Response(200, [], Stream::factory(json_encode(['captcha' => uniqid('', true), 'text' => ''])))]);
     $httpClient = new Client();
     $httpClient->getEmitter()->attach($mock);
     $deathByCaptcha = new DeathByCaptcha($this->credentials, PullPreferences::fromPreferences(0, 1), $httpClient);
     $this->assertFalse($deathByCaptcha->requestSolutionForCaptcha($this->captcha));
 }
 /**
  * @test
  */
 public function createWithPreferences()
 {
     $deathByCaptcha = DeathByCaptchaFactory::createWithPreferences(UsernamePasswordCredentials::fromUsernameAndPassword('foo', 'bar'), PullPreferences::fromPreferences(10, 10));
     $this->assertInstanceOf(DeathByCaptchaInterface::class, $deathByCaptcha);
 }
 /**
  * @param  UsernamePasswordCredentials $credentials
  * @return DeathByCaptchaInterface
  */
 public static function createWithDefaultPreferences(UsernamePasswordCredentials $credentials)
 {
     return self::createWithPreferences($credentials, PullPreferences::fromRecommendedPreferences());
 }
 /**
  * @test
  */
 public function getMaxAttempts()
 {
     $this->assertEquals(5, $this->preferences->getMaxAttempts());
 }