Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#167: Implement BaseResource class in helpers #112

Merged
merged 6 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions app/Http/Resources/BaseJsonResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use RonasIT\Support\BaseResource;

class BaseJsonResource extends JsonResource
class BaseJsonResource extends BaseResource
{
public static $wrap = null;
}
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions tests/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function testLoginAsAuthorizedUser()

public function testRegisterAuthorizedUser()
{
$this->mockBcryptHasher();
$this->mockBcryptHasher('666999');

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

Expand All @@ -115,7 +115,7 @@ public function testRegisterAuthorizedUser()

public function testRegisterFromGuestUser()
{
$this->mockBcryptHasher();
$this->mockBcryptHasher('666999');

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

Expand Down Expand Up @@ -247,7 +247,7 @@ public function testForgotPassword()
{
Mail::fake();

$this->mockOpensslRandomPseudoBytes();
$this->mockOpensslRandomPseudoBytes('123123');

$response = $this->json('post', '/auth/forgot-password', [
'email' => '[email protected]',
Expand Down Expand Up @@ -290,7 +290,7 @@ public function testForgotPasswordThrottled()

public function testRestorePassword()
{
$this->mockBcryptHasher();
$this->mockBcryptHasher('new_password');

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

Expand Down
6 changes: 4 additions & 2 deletions tests/Support/AuthTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@ trait AuthTestTrait
{
use MockTrait;

public function mockOpensslRandomPseudoBytes(): void
public function mockOpensslRandomPseudoBytes(string $password): void
{
$this->mockNativeFunction('Illuminate\Auth\Passwords', [
$this->functionCall(
name: 'hash_hmac',
arguments: ['sha256', $password, 'b"DÉV&´G"áËa\x1Ae&õš,Ü\x16½\x1A\x15‘\x07CM—ºSVxÅ\x16"'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as I can see - the last arg is the app key, let's just fill app key with the simple value (e.g. app_key)

result: '5qw6rdsyd4sa65d4zxfc65ds4fc',
),
]);
}

public function mockBcryptHasher(): void
public function mockBcryptHasher(string $password): void
{
$this->mockNativeFunction('Illuminate\Hashing', [
$this->functionCall(
name: 'password_hash',
arguments: [$password, PASSWORD_DEFAULT, ['cost' => 12]],
result: '$2y$12$p9Bub8AaSl7EHfoGMgaXReK7Cs50kjHswxzNPTB5B4mcoRWfHnv7u',
),
]);
Expand Down
2 changes: 1 addition & 1 deletion tests/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function setUp(): void

public function testCreate()
{
$this->mockBcryptHasher();
$this->mockBcryptHasher('123123');

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

Expand Down
Loading