From 9d7ca1c430b66f016626eb689a0cbd59cf2551bd Mon Sep 17 00:00:00 2001 From: eparusov Date: Fri, 20 Dec 2024 09:03:59 +0300 Subject: [PATCH] #145: Mock class not assert arguments with the empty arg list --- tests/AuthTest.php | 6 +++--- tests/Support/AuthTestTrait.php | 8 ++++++-- tests/UserTest.php | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/AuthTest.php b/tests/AuthTest.php index f39f6cf..f84b74f 100644 --- a/tests/AuthTest.php +++ b/tests/AuthTest.php @@ -102,7 +102,7 @@ public function testLoginAsAuthorizedUser() public function testRegisterAuthorizedUser() { - $this->mockBcryptHasher(); + $this->mockBcryptHasher('666999'); $data = $this->getJsonFixture('new_user.json'); @@ -115,7 +115,7 @@ public function testRegisterAuthorizedUser() public function testRegisterFromGuestUser() { - $this->mockBcryptHasher(); + $this->mockBcryptHasher('666999'); $data = $this->getJsonFixture('new_user.json'); @@ -290,7 +290,7 @@ public function testForgotPasswordThrottled() public function testRestorePassword() { - $this->mockBcryptHasher(); + $this->mockBcryptHasher('new_password'); $data = $this->getJsonFixture('restore_password.json'); diff --git a/tests/Support/AuthTestTrait.php b/tests/Support/AuthTestTrait.php index 8716321..b0e6ddd 100644 --- a/tests/Support/AuthTestTrait.php +++ b/tests/Support/AuthTestTrait.php @@ -9,21 +9,25 @@ trait AuthTestTrait { use MockTrait; - public function mockOpensslRandomPseudoBytes(): void + public function mockOpensslRandomPseudoBytes(string $password): void { + //hash_hmac('sha256', $password, 'b"DÉV&´G"áËa\x1Ae&õš,Ü\x16½\x1A\x15‘\x07CM—ºSVxÅ\x16"'); + $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"'], 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', ), ]); diff --git a/tests/UserTest.php b/tests/UserTest.php index 36fc4de..16316f4 100644 --- a/tests/UserTest.php +++ b/tests/UserTest.php @@ -28,7 +28,7 @@ public function setUp(): void public function testCreate() { - $this->mockBcryptHasher(); + $this->mockBcryptHasher('123123'); $data = $this->getJsonFixture('create_user.json');