Skip to content

Commit 2458fc8

Browse files
authored
Merge pull request #112 from RonasIT/167-implement-base-resource-class
#167: Implement BaseResource class in helpers
2 parents 4b3e9e9 + 574c9b5 commit 2458fc8

File tree

6 files changed

+24
-18
lines changed

6 files changed

+24
-18
lines changed

app/Http/Resources/BaseJsonResource.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
namespace App\Http\Resources;
44

5-
use Illuminate\Http\Resources\Json\JsonResource;
5+
use RonasIT\Support\BaseResource;
66

7-
class BaseJsonResource extends JsonResource
7+
class BaseJsonResource extends BaseResource
88
{
9-
public static $wrap = null;
109
}

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/AuthTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function testLoginAsAuthorizedUser()
102102

103103
public function testRegisterAuthorizedUser()
104104
{
105-
$this->mockBcryptHasher();
105+
$this->mockBcryptHasher('666999');
106106

107107
$data = $this->getJsonFixture('new_user.json');
108108

@@ -115,7 +115,7 @@ public function testRegisterAuthorizedUser()
115115

116116
public function testRegisterFromGuestUser()
117117
{
118-
$this->mockBcryptHasher();
118+
$this->mockBcryptHasher('666999');
119119

120120
$data = $this->getJsonFixture('new_user.json');
121121

@@ -290,7 +290,7 @@ public function testForgotPasswordThrottled()
290290

291291
public function testRestorePassword()
292292
{
293-
$this->mockBcryptHasher();
293+
$this->mockBcryptHasher('new_password');
294294

295295
$data = $this->getJsonFixture('restore_password.json');
296296

tests/Support/AuthTestTrait.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Tests\Support;
44

55
use App\Services\UserService;
6+
use Illuminate\Support\Str;
67
use RonasIT\Support\Traits\MockTrait;
78

89
trait AuthTestTrait
@@ -11,19 +12,25 @@ trait AuthTestTrait
1112

1213
public function mockOpensslRandomPseudoBytes(): void
1314
{
15+
config(['app.key' => 'some_app_key']);
16+
17+
Str::createRandomStringsUsing(fn () => 'value');
18+
1419
$this->mockNativeFunction('Illuminate\Auth\Passwords', [
1520
$this->functionCall(
1621
name: 'hash_hmac',
17-
result: '5qw6rdsyd4sa65d4zxfc65ds4fc',
22+
arguments: ['sha256', 'value', 'some_app_key'],
23+
result: 'some_reset_password_token',
1824
),
1925
]);
2026
}
2127

22-
public function mockBcryptHasher(): void
28+
public function mockBcryptHasher(string $password): void
2329
{
2430
$this->mockNativeFunction('Illuminate\Hashing', [
2531
$this->functionCall(
2632
name: 'password_hash',
33+
arguments: [$password, PASSWORD_DEFAULT, ['cost' => 12]],
2734
result: '$2y$12$p9Bub8AaSl7EHfoGMgaXReK7Cs50kjHswxzNPTB5B4mcoRWfHnv7u',
2835
),
2936
]);

tests/UserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function setUp(): void
2828

2929
public function testCreate()
3030
{
31-
$this->mockBcryptHasher();
31+
$this->mockBcryptHasher('123123');
3232

3333
$data = $this->getJsonFixture('create_user.json');
3434

tests/fixtures/AuthTest/forgot_password_email.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ <h1 style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; c
6161
style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box;">
6262
<tr>
6363
<td style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box;">
64-
<a href="http://localhost/enter-new-password/5qw6rdsyd4sa65d4zxfc65ds4fc"
64+
<a href="http://localhost/enter-new-password/some_reset_password_token"
6565
class="button button-blue" target="_blank"
6666
style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; border-radius: 3px; box-shadow: 0 2px 3px rgba(0, 0, 0, 0.16); color: #FFF; display: inline-block; text-decoration: none; -webkit-text-size-adjust: none; background-color: #3097D1; border-top: 10px solid #3097D1; border-right: 18px solid #3097D1; border-bottom: 10px solid #3097D1; border-left: 18px solid #3097D1;">Reset
6767
Password</a>
@@ -85,8 +85,8 @@ <h1 style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; c
8585
<p style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; color: #74787E; line-height: 1.5em; margin-top: 0; text-align: left; font-size: 12px;">
8686
If you’re having trouble clicking the "Reset Password" button, copy and paste the URL
8787
below into your web browser:
88-
<a href="http://localhost/enter-new-password/5qw6rdsyd4sa65d4zxfc65ds4fc" style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; color: #3869D4;">
89-
http://localhost/enter-new-password/5qw6rdsyd4sa65d4zxfc65ds4fc
88+
<a href="http://localhost/enter-new-password/some_reset_password_token" style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; color: #3869D4;">
89+
http://localhost/enter-new-password/some_reset_password_token
9090
</a>
9191
</p>
9292
</td>

0 commit comments

Comments
 (0)