Skip to content

Commit

Permalink
Merge pull request #63 from RonasIT/mock-user-service-generate-hash
Browse files Browse the repository at this point in the history
test: remove ignore and mock openssl_random_pseudo_bytes
  • Loading branch information
DenTray authored Nov 6, 2023
2 parents bff3037 + 42b6a6d commit 542d2ae
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
3 changes: 0 additions & 3 deletions app/Services/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ public function restorePassword(string $token, string $password): void
]);
}

/**
* @codeCoverageIgnore
*/
protected function generateHash(int $length = 32): string
{
$length /= 2;
Expand Down
2 changes: 1 addition & 1 deletion tests/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public function testForgotPassword()
{
Mail::fake();

$this->mockUniqueTokenGeneration('some_token');
$this->mockOpensslRandomPseudoBytes();

$response = $this->json('post', '/auth/forgot-password', [
'email' => '[email protected]'
Expand Down
13 changes: 7 additions & 6 deletions tests/Support/AuthTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions tests/fixtures/AuthTest/forgot_password_email.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ <h1 style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; c
style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box;">
<tr>
<td style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box;">
<a href="http://localhost/enter-new-password/some_token"
<a href="http://localhost/enter-new-password/357177367264737964347361363564347a78666336356473346663"
class="button button-blue" target="_blank"
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
Password</a>
Expand All @@ -85,9 +85,9 @@ <h1 style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; c
<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;">
If you’re having trouble clicking the "Reset Password" button, copy and paste the URL
below into your web browser:
<a href="http://localhost/enter-new-password/some_token" style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; color: #3869D4;"></a>
<a href="http://localhost/enter-new-password/some_token" style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; color: #3869D4;">
http://localhost/enter-new-password/some_token
<a href="http://localhost/enter-new-password/357177367264737964347361363564347a78666336356473346663" style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; color: #3869D4;"></a>
<a href="http://localhost/enter-new-password/357177367264737964347361363564347a78666336356473346663" style="font-family: Avenir, Helvetica, sans-serif; box-sizing: border-box; color: #3869D4;">
http://localhost/enter-new-password/357177367264737964347361363564347a78666336356473346663
</a>
</p>
</td>
Expand Down

0 comments on commit 542d2ae

Please sign in to comment.