From 42b6a6d9bc3f2df7eb381199a470a9e27d2b7ab8 Mon Sep 17 00:00:00 2001 From: Vitaly Iskrin Date: Sat, 28 Oct 2023 23:47:22 -0500 Subject: [PATCH] test: remove ignore and mock openssl_random_pseudo_bytes --- app/Services/UserService.php | 3 --- tests/AuthTest.php | 2 +- tests/Support/AuthTestTrait.php | 13 +++++++------ tests/fixtures/AuthTest/forgot_password_email.html | 8 ++++---- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/app/Services/UserService.php b/app/Services/UserService.php index 3e74d3b..e701c09 100755 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -77,9 +77,6 @@ public function restorePassword(string $token, string $password): void ]); } - /** - * @codeCoverageIgnore - */ protected function generateHash(int $length = 32): string { $length /= 2; diff --git a/tests/AuthTest.php b/tests/AuthTest.php index 2850b30..7fe08ed 100644 --- a/tests/AuthTest.php +++ b/tests/AuthTest.php @@ -242,7 +242,7 @@ public function testForgotPassword() { Mail::fake(); - $this->mockUniqueTokenGeneration('some_token'); + $this->mockOpensslRandomPseudoBytes(); $response = $this->json('post', '/auth/forgot-password', [ 'email' => 'fidel.kutch@example.com' diff --git a/tests/Support/AuthTestTrait.php b/tests/Support/AuthTestTrait.php index 0ae8ea7..847ef53 100644 --- a/tests/Support/AuthTestTrait.php +++ b/tests/Support/AuthTestTrait.php @@ -2,18 +2,19 @@ namespace App\Tests\Support; -use App\Services\UserService; +use phpmock\phpunit\PHPMock; use RonasIT\Support\Traits\MockClassTrait; trait AuthTestTrait { - use MockClassTrait; + use MockClassTrait, PHPMock; - public function mockUniqueTokenGeneration($hash) + public function mockOpensslRandomPseudoBytes(): void { - $this->mockClass(UserService::class, [ - ['method' => 'generateHash', 'result' => $hash] - ]); + $mock = $this->getFunctionMock('App\Services', 'openssl_random_pseudo_bytes'); + $mock + ->expects($this->once()) + ->willReturn('5qw6rdsyd4sa65d4zxfc65ds4fc'); } public function decodeJWTToken($token) diff --git a/tests/fixtures/AuthTest/forgot_password_email.html b/tests/fixtures/AuthTest/forgot_password_email.html index a0837c0..d4d871f 100644 --- a/tests/fixtures/AuthTest/forgot_password_email.html +++ b/tests/fixtures/AuthTest/forgot_password_email.html @@ -61,7 +61,7 @@

- Reset Password @@ -85,9 +85,9 @@

If you’re having trouble clicking the "Reset Password" button, copy and paste the URL below into your web browser: - - - http://localhost/enter-new-password/some_token + + + http://localhost/enter-new-password/357177367264737964347361363564347a78666336356473346663