-
-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce fake implementation of signer for tests
This allows us to stop using PHPUnit mocks in every place that needs, making tests more obvious. Signed-off-by: Luís Cobucci <[email protected]>
- Loading branch information
Showing
3 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Lcobucci\JWT\Tests\Signer; | ||
|
||
use Lcobucci\JWT\Signer; | ||
use Lcobucci\JWT\Signer\Key; | ||
|
||
final class FakeSigner implements Signer | ||
{ | ||
/** @param non-empty-string $signature */ | ||
public function __construct(private readonly string $signature) | ||
{ | ||
} | ||
|
||
public function algorithmId(): string | ||
{ | ||
return 'FAKE-' . $this->signature; | ||
} | ||
|
||
public function sign(string $payload, Key $key): string | ||
{ | ||
return $this->signature . '-' . $key->contents(); | ||
} | ||
|
||
public function verify(string $expected, string $payload, Key $key): bool | ||
{ | ||
return $this->signature . '-' . $key->contents() === $expected; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters