コード例 #1
0
ファイル: DeathByCaptcha.php プロジェクト: cotapreco/captcha
 /**
  * @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;
 }
コード例 #2
0
 /**
  * @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));
 }
コード例 #3
0
 /**
  * @test
  */
 public function createWithPreferences()
 {
     $deathByCaptcha = DeathByCaptchaFactory::createWithPreferences(UsernamePasswordCredentials::fromUsernameAndPassword('foo', 'bar'), PullPreferences::fromPreferences(10, 10));
     $this->assertInstanceOf(DeathByCaptchaInterface::class, $deathByCaptcha);
 }
コード例 #4
0
 /**
  * @param  UsernamePasswordCredentials $credentials
  * @return DeathByCaptchaInterface
  */
 public static function createWithDefaultPreferences(UsernamePasswordCredentials $credentials)
 {
     return self::createWithPreferences($credentials, PullPreferences::fromRecommendedPreferences());
 }
コード例 #5
0
 /**
  * @test
  */
 public function getMaxAttempts()
 {
     $this->assertEquals(5, $this->preferences->getMaxAttempts());
 }