Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Commit 3b033d0

Browse files
committed
Merge branch 'feature/curl_timeout' into develop
2 parents 3d5d630 + 4b0288d commit 3b033d0

7 files changed

+60
-22
lines changed

src/ReCaptchaBuilder.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,15 @@ public function setApiSecretKey(string $api_secret_key): ReCaptchaBuilder {
115115
}
116116

117117
/**
118-
* @param int $curl_timeout
118+
* @param int|null $curl_timeout
119119
*
120120
* @return ReCaptchaBuilder
121121
*/
122-
public function setCurlTimeout(int $curl_timeout): ReCaptchaBuilder {
122+
public function setCurlTimeout(?int $curl_timeout = null): ReCaptchaBuilder {
123123

124+
if($curl_timeout === null) {
125+
$curl_timeout = config('recaptcha.curl_timeout', ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
126+
}
124127
$this->curl_timeout = $curl_timeout;
125128

126129
return $this;

src/ReCaptchaBuilderInvisible.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ class ReCaptchaBuilderInvisible extends ReCaptchaBuilder {
1919
/**
2020
* ReCaptchaBuilderInvisible constructor.
2121
*
22-
* @param string $api_site_key
23-
* @param string $api_secret_key
24-
* @param int $curl_timeout
22+
* @param string $api_site_key
23+
* @param string $api_secret_key
24+
* @param int|null $curl_timeout
2525
*/
26-
public function __construct(string $api_site_key, string $api_secret_key, int $curl_timeout) {
26+
public function __construct(string $api_site_key, string $api_secret_key, ?int $curl_timeout = null) {
2727

2828
parent::__construct($api_site_key, $api_secret_key, 'invisible', $curl_timeout);
2929
}

src/ReCaptchaBuilderV2.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ class ReCaptchaBuilderV2 extends ReCaptchaBuilder {
1919
/**
2020
* ReCaptchaBuilderV2 constructor.
2121
*
22-
* @param string $api_site_key
23-
* @param string $api_secret_key
24-
* @param int $curl_timeout
22+
* @param string $api_site_key
23+
* @param string $api_secret_key
24+
* @param int|null $curl_timeout
2525
*/
26-
public function __construct(string $api_site_key, string $api_secret_key, int $curl_timeout) {
26+
public function __construct(string $api_site_key, string $api_secret_key, ?int $curl_timeout = null) {
2727

2828
parent::__construct($api_site_key, $api_secret_key, 'v2', $curl_timeout);
2929
}

src/ReCaptchaBuilderV3.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ class ReCaptchaBuilderV3 extends ReCaptchaBuilder {
1919
/**
2020
* ReCaptchaBuilderV3 constructor.
2121
*
22-
* @param string $api_site_key
23-
* @param string $api_secret_key
24-
* @param int $curl_timeout
22+
* @param string $api_site_key
23+
* @param string $api_secret_key
24+
* @param int|null $curl_timeout
2525
*/
26-
public function __construct(string $api_site_key, string $api_secret_key, int $curl_timeout) {
26+
public function __construct(string $api_site_key, string $api_secret_key, ?int $curl_timeout = null) {
2727

2828
parent::__construct($api_site_key, $api_secret_key, 'v3', $curl_timeout);
2929
}

tests/ReCaptchaConfigurationTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testSkipIpWhiteListIsArray() {
4141
* @test
4242
*/
4343
public function testCurlTimeoutIsSet() {
44-
$this->assertEquals($this->recaptcha->getCurlTimeout(), 3);
44+
$this->assertEquals(3, $this->recaptcha->getCurlTimeout());
4545
}
4646

4747
/**
@@ -54,6 +54,7 @@ public function testCurlTimeoutIsSet() {
5454
protected function getEnvironmentSetUp($app) {
5555

5656
$app['config']->set('recaptcha.skip_ip', '10.0.0.1,10.0.0.2');
57+
$app['config']->set('recaptcha.curl_timeout', 3);
5758
}
5859

5960
/**
@@ -63,6 +64,6 @@ protected function setUp(): void {
6364

6465
parent::setUp(); // TODO: Change the autogenerated stub
6566

66-
$this->recaptcha = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key', 3);
67+
$this->recaptcha = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key');
6768
}
6869
}

tests/ReCaptchaTest.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,31 @@
1111
namespace Biscolab\ReCaptcha\Tests;
1212

1313
use Biscolab\ReCaptcha\Facades\ReCaptcha;
14+
use Biscolab\ReCaptcha\ReCaptchaBuilder;
1415
use Biscolab\ReCaptcha\ReCaptchaBuilderInvisible;
1516
use Biscolab\ReCaptcha\ReCaptchaBuilderV2;
17+
use Biscolab\ReCaptcha\ReCaptchaBuilderV3;
1618

1719
/**
1820
* Class ReCaptchaTest
1921
* @package Biscolab\ReCaptcha\Tests
2022
*/
2123
class ReCaptchaTest extends TestCase {
2224

25+
/**
26+
* @var ReCaptchaBuilderInvisible
27+
*/
2328
protected $recaptcha_invisible = null;
2429

25-
protected $recaptcha_v2 = null;
30+
/**
31+
* @var ReCaptchaBuilderV2
32+
*/
33+
protected $recaptcha_v2 = null;
34+
35+
/**
36+
* @var ReCaptchaBuilderV3
37+
*/
38+
protected $recaptcha_v3 = null;
2639

2740
/**
2841
* @tests
@@ -40,7 +53,8 @@ public function testReCaptchaInvisibleHtmlFormButtonDefault() {
4053

4154
$recaptcha = $this->recaptcha_invisible;
4255
$html_button = $recaptcha->htmlFormButton();
43-
$this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Submit</button>', $html_button);
56+
$this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Submit</button>',
57+
$html_button);
4458
}
4559

4660
/**
@@ -50,7 +64,8 @@ public function testReCaptchaInvisibleHtmlFormButtonCustom() {
5064

5165
$recaptcha = $this->recaptcha_invisible;
5266
$html_button = $recaptcha->htmlFormButton('Custom Text');
53-
$this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Custom Text</button>', $html_button);
67+
$this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Custom Text</button>',
68+
$html_button);
5469
}
5570

5671
/**
@@ -72,6 +87,16 @@ public function testReCaptchaInvisibleHtmlFormSnippetShouldThrowError() {
7287
$this->recaptcha_invisible->htmlFormSnippet();
7388
}
7489

90+
/**
91+
* @test
92+
*/
93+
public function testDefaultCurlTimeout() {
94+
95+
$this->assertEquals($this->recaptcha_invisible->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
96+
$this->assertEquals($this->recaptcha_v2->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
97+
$this->assertEquals($this->recaptcha_v3->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
98+
}
99+
75100
/**
76101
* @test
77102
* @expectedException \Error
@@ -85,8 +110,9 @@ protected function setUp(): void {
85110

86111
parent::setUp(); // TODO: Change the autogenerated stub
87112

88-
$this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key', 3);
89-
$this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key', 3);
113+
$this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key');
114+
$this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key');
115+
$this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key');
90116

91117
}
92118
}

tests/ReCaptchaV3Test.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ public function testValidateController() {
8787
$this->assertArrayHasKey("error-codes", $return);
8888
}
8989

90+
/**
91+
* @test
92+
*/
93+
public function testCurlTimeoutIsSet() {
94+
$this->assertEquals($this->recaptcha_v3->getCurlTimeout(), 3);
95+
}
96+
9097
/**
9198
* Define environment setup.
9299
*
@@ -97,6 +104,7 @@ public function testValidateController() {
97104
protected function getEnvironmentSetUp($app) {
98105

99106
$app['config']->set('recaptcha.version', 'v3');
107+
$app['config']->set('recaptcha.curl_timeout', 3);
100108
}
101109

102110
/**
@@ -106,7 +114,7 @@ protected function setUp(): void {
106114

107115
parent::setUp(); // TODO: Change the autogenerated stub
108116

109-
$this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key', 3);
117+
$this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key');
110118

111119
}
112120
}

0 commit comments

Comments
 (0)