File tree Expand file tree Collapse file tree 4 files changed +52
-2
lines changed
Expand file tree Collapse file tree 4 files changed +52
-2
lines changed Original file line number Diff line number Diff line change 11<?php
22namespace Authwave ;
33
4+ use Gt \Http \Uri ;
5+ use Psr \Http \Message \UriInterface ;
6+
47class Authenticator {
8+ private Cipher $ cipher ;
9+ private string $ hostname ;
10+
11+ public function __construct (Token $ token , string $ hostname ) {
12+ $ this ->cipher = $ token ->generateCipher ();
13+ $ this ->hostname = $ hostname ;
14+ }
515
16+ public function getAuthUri ():UriInterface {
17+ return (new Uri ())
18+ ->withScheme ("https " )
19+ ->withHost ($ this ->hostname );
20+ }
621}
Original file line number Diff line number Diff line change 1+ <?php
2+ namespace Authwave ;
3+
4+ class Cipher {
5+
6+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ namespace Authwave ;
3+
4+ class Token {
5+ private string $ key ;
6+ private string $ tokenValue ;
7+
8+ public function __construct (string $ key ) {
9+ $ this ->key = $ key ;
10+ $ this ->tokenValue = random_bytes (16 );
11+ }
12+
13+ public function generateCipher ():Cipher {
14+
15+ }
16+ }
Original file line number Diff line number Diff line change 11<?php
22namespace Authwave \Test ;
33
4+ use Authwave \Authenticator ;
5+ use Authwave \Cipher ;
6+ use Authwave \Token ;
47use PHPUnit \Framework \TestCase ;
58
69class AuthenticatorTest extends TestCase {
7- public function testOnePlusOne () {
8- self ::assertEquals (2 , 1 + 1 );
10+ public function testGetAuthUriHostname () {
11+ $ cipher = self ::createMock (Cipher::class);
12+ $ token = self ::createMock (Token::class);
13+ $ token ->method ("generateCipher " )
14+ ->willReturn ($ cipher );
15+
16+ $ sut = new Authenticator ($ token , "example.com " );
17+ $ authUri = $ sut ->getAuthUri ();
18+ self ::assertStringStartsWith (
19+ "https://example.com " ,
20+ $ authUri
21+ );
922 }
1023}
You can’t perform that action at this time.
0 commit comments