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

Commit 9c289cd

Browse files
committed
Test improved and code restyling (PSR2)
1 parent f0a827b commit 9c289cd

File tree

6 files changed

+235
-31
lines changed

6 files changed

+235
-31
lines changed

tests/ReCaptchaConfigurationTest.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@
1010

1111
namespace Biscolab\ReCaptcha\Tests;
1212

13-
use Biscolab\ReCaptcha\Controllers\ReCaptchaController;
1413
use Biscolab\ReCaptcha\ReCaptchaBuilder;
1514
use Biscolab\ReCaptcha\ReCaptchaBuilderV2;
16-
use Biscolab\ReCaptcha\ReCaptchaBuilderV3;
17-
use Illuminate\Support\Facades\App;
1815

1916
/**
2017
* Class ReCaptchaConfigurationTest
2118
* @package Biscolab\ReCaptcha\Tests
2219
*/
23-
class ReCaptchaConfigurationTest extends TestCase {
20+
class ReCaptchaConfigurationTest extends TestCase
21+
{
2422

2523
/**
2624
* @var ReCaptchaBuilder
@@ -30,7 +28,8 @@ class ReCaptchaConfigurationTest extends TestCase {
3028
/**
3129
* @test
3230
*/
33-
public function testSkipIpWhiteListIsArray() {
31+
public function testSkipIpWhiteListIsArray()
32+
{
3433

3534
$ip_whitelist = $this->recaptcha->getIpWhitelist();
3635
$this->assertTrue(is_array($ip_whitelist));
@@ -40,7 +39,9 @@ public function testSkipIpWhiteListIsArray() {
4039
/**
4140
* @test
4241
*/
43-
public function testCurlTimeoutIsSet() {
42+
public function testCurlTimeoutIsSet()
43+
{
44+
4445
$this->assertEquals(3, $this->recaptcha->getCurlTimeout());
4546
}
4647

@@ -51,7 +52,8 @@ public function testCurlTimeoutIsSet() {
5152
*
5253
* @return void
5354
*/
54-
protected function getEnvironmentSetUp($app) {
55+
protected function getEnvironmentSetUp($app)
56+
{
5557

5658
$app['config']->set('recaptcha.skip_ip', '10.0.0.1,10.0.0.2');
5759
$app['config']->set('recaptcha.curl_timeout', 3);
@@ -60,7 +62,8 @@ protected function getEnvironmentSetUp($app) {
6062
/**
6163
* Setup the test environment.
6264
*/
63-
protected function setUp(): void {
65+
protected function setUp(): void
66+
{
6467

6568
parent::setUp(); // TODO: Change the autogenerated stub
6669

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Copyright (c) 2017 - present
4+
* LaravelGoogleRecaptcha - ReCaptchaHelpersInvisibleTest.phpp
5+
* author: Roberto Belotti - [email protected]
6+
* web : robertobelotti.com, github.com/biscolab
7+
* Initial version created on: 8/8/2019
8+
* MIT license: https://github.com/biscolab/laravel-recaptcha/blob/master/LICENSE
9+
*/
10+
11+
12+
namespace Biscolab\ReCaptcha\Tests;
13+
14+
use Biscolab\ReCaptcha\Facades\ReCaptcha;
15+
use Biscolab\ReCaptcha\ReCaptchaServiceProvider;
16+
17+
class ReCaptchaHelpersInvisibleTest extends TestCase
18+
{
19+
20+
/**
21+
* @test
22+
*/
23+
public function testHtmlScriptTagJsApiCalledByFacade()
24+
{
25+
ReCaptcha::shouldReceive('htmlScriptTagJsApi')
26+
->once()
27+
->with("key");
28+
29+
htmlScriptTagJsApi("key");
30+
31+
}
32+
33+
/**
34+
* @test
35+
*/
36+
public function testHtmlScriptTagJsApiV3CalledByFacade()
37+
{
38+
ReCaptcha::shouldReceive('htmlScriptTagJsApiV3')
39+
->once()
40+
->with([]);
41+
42+
htmlScriptTagJsApiV3([]);
43+
44+
}
45+
46+
/**
47+
* @test
48+
*/
49+
public function testHtmlFormButtonCalledByFacade()
50+
{
51+
ReCaptcha::shouldReceive('htmlFormButton')
52+
->once()
53+
->with("key");
54+
55+
htmlFormButton("key");
56+
57+
}
58+
59+
/**
60+
* @test
61+
* @expectedException \TypeError
62+
*/
63+
public function testHtmlFormSnippetCalledByFacade()
64+
{
65+
ReCaptcha::shouldReceive('htmlFormSnippet')
66+
->once();
67+
68+
htmlFormSnippet();
69+
70+
}
71+
72+
73+
/**
74+
* Define environment setup.
75+
*
76+
* @param \Illuminate\Foundation\Application $app
77+
*
78+
* @return void
79+
*/
80+
protected function getEnvironmentSetUp($app)
81+
{
82+
83+
$app['config']->set('recaptcha.api_site_key', 'api_site_key');
84+
$app['config']->set('recaptcha.api_site_key', 'api_site_key');
85+
$app['config']->set('recaptcha.version', 'invisible');
86+
}
87+
}

tests/ReCaptchaHelpersV2Test.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Copyright (c) 2017 - present
4+
* LaravelGoogleRecaptcha - ReCaptchaHelpersV2Test.php
5+
* author: Roberto Belotti - [email protected]
6+
* web : robertobelotti.com, github.com/biscolab
7+
* Initial version created on: 8/8/2019
8+
* MIT license: https://github.com/biscolab/laravel-recaptcha/blob/master/LICENSE
9+
*/
10+
11+
12+
namespace Biscolab\ReCaptcha\Tests;
13+
14+
use Biscolab\ReCaptcha\Facades\ReCaptcha;
15+
use Biscolab\ReCaptcha\ReCaptchaServiceProvider;
16+
17+
class ReCaptchaHelpersV2Test extends TestCase
18+
{
19+
20+
/**
21+
* @test
22+
*/
23+
public function testHtmlScriptTagJsApiCalledByFacade()
24+
{
25+
ReCaptcha::shouldReceive('htmlScriptTagJsApi')
26+
->once()
27+
->with("key");
28+
29+
htmlScriptTagJsApi("key");
30+
31+
}
32+
33+
/**
34+
* @test
35+
*/
36+
public function testHtmlScriptTagJsApiV3CalledByFacade()
37+
{
38+
ReCaptcha::shouldReceive('htmlScriptTagJsApiV3')
39+
->once()
40+
->with([]);
41+
42+
htmlScriptTagJsApiV3([]);
43+
44+
}
45+
46+
/**
47+
* @test
48+
* @expectedException \TypeError
49+
*/
50+
public function testHtmlFormButtonCalledByFacade()
51+
{
52+
ReCaptcha::shouldReceive('htmlFormButton')
53+
->once()
54+
->with("key");
55+
56+
htmlFormButton("key");
57+
58+
}
59+
60+
/**
61+
* @test
62+
*/
63+
public function testHtmlFormSnippetCalledByFacade()
64+
{
65+
ReCaptcha::shouldReceive('htmlFormSnippet')
66+
->once();
67+
68+
htmlFormSnippet();
69+
70+
}
71+
72+
73+
/**
74+
* Define environment setup.
75+
*
76+
* @param \Illuminate\Foundation\Application $app
77+
*
78+
* @return void
79+
*/
80+
protected function getEnvironmentSetUp($app)
81+
{
82+
83+
$app['config']->set('recaptcha.api_site_key', 'api_site_key');
84+
$app['config']->set('recaptcha.api_site_key', 'api_site_key');
85+
$app['config']->set('recaptcha.version', 'v2');
86+
}
87+
}

tests/ReCaptchaTest.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
* Class ReCaptchaTest
2121
* @package Biscolab\ReCaptcha\Tests
2222
*/
23-
class ReCaptchaTest extends TestCase {
23+
class ReCaptchaTest extends TestCase
24+
{
2425

2526
/**
2627
* @var ReCaptchaBuilderInvisible
@@ -40,7 +41,8 @@ class ReCaptchaTest extends TestCase {
4041
/**
4142
* @tests
4243
*/
43-
public function testHtmlScriptTagJsApiGetHtmlScriptTag() {
44+
public function testHtmlScriptTagJsApiGetHtmlScriptTag()
45+
{
4446

4547
$r = ReCaptcha::htmlScriptTagJsApi();
4648
$this->assertEquals('<script src="https://www.google.com/recaptcha/api.js" async defer></script>', $r);
@@ -49,7 +51,8 @@ public function testHtmlScriptTagJsApiGetHtmlScriptTag() {
4951
/**
5052
* @test
5153
*/
52-
public function testReCaptchaInvisibleHtmlFormButtonDefault() {
54+
public function testReCaptchaInvisibleHtmlFormButtonDefault()
55+
{
5356

5457
$recaptcha = $this->recaptcha_invisible;
5558
$html_button = $recaptcha->htmlFormButton();
@@ -60,7 +63,8 @@ public function testReCaptchaInvisibleHtmlFormButtonDefault() {
6063
/**
6164
* @test
6265
*/
63-
public function testReCaptchaInvisibleHtmlFormButtonCustom() {
66+
public function testReCaptchaInvisibleHtmlFormButtonCustom()
67+
{
6468

6569
$recaptcha = $this->recaptcha_invisible;
6670
$html_button = $recaptcha->htmlFormButton('Custom Text');
@@ -71,7 +75,8 @@ public function testReCaptchaInvisibleHtmlFormButtonCustom() {
7175
/**
7276
* @test
7377
*/
74-
public function testReCaptchaV2HtmlFormSnippet() {
78+
public function testReCaptchaV2HtmlFormSnippet()
79+
{
7580

7681
$recaptcha = $this->recaptcha_v2;
7782
$html_snippet = $recaptcha->htmlFormSnippet();
@@ -82,15 +87,17 @@ public function testReCaptchaV2HtmlFormSnippet() {
8287
* @test
8388
* @expectedException \Error
8489
*/
85-
public function testReCaptchaInvisibleHtmlFormSnippetShouldThrowError() {
90+
public function testReCaptchaInvisibleHtmlFormSnippetShouldThrowError()
91+
{
8692

8793
$this->recaptcha_invisible->htmlFormSnippet();
8894
}
8995

9096
/**
9197
* @test
9298
*/
93-
public function testDefaultCurlTimeout() {
99+
public function testDefaultCurlTimeout()
100+
{
94101

95102
$this->assertEquals($this->recaptcha_invisible->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
96103
$this->assertEquals($this->recaptcha_v2->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
@@ -101,12 +108,17 @@ public function testDefaultCurlTimeout() {
101108
* @test
102109
* @expectedException \Error
103110
*/
104-
public function testReCaptchaV2htmlFormButtonShouldThrowError() {
111+
public function testReCaptchaV2htmlFormButtonShouldThrowError()
112+
{
105113

106114
$this->recaptcha_v2->htmlFormButton();
107115
}
108116

109-
protected function setUp(): void {
117+
/**
118+
* @inheritdoc
119+
*/
120+
protected function setUp(): void
121+
{
110122

111123
parent::setUp(); // TODO: Change the autogenerated stub
112124

0 commit comments

Comments
 (0)