55use Illuminate \Contracts \Auth \Authenticatable ;
66use Illuminate \Contracts \Validation \Factory ;
77use Illuminate \Http \Request ;
8+ use Illuminate \Support \Facades \Hash ;
89use Laravel \Passport \Client ;
910use Laravel \Passport \ClientRepository ;
1011use Laravel \Passport \Http \Controllers \ClientController ;
@@ -41,6 +42,9 @@ public function test_all_the_clients_for_the_current_user_can_be_retrieved()
4142
4243 public function test_clients_can_be_stored ()
4344 {
45+ Hash::expects ('isHashed ' )->once ()->with ('secret ' )->andReturn (false );
46+ Hash::expects ('make ' )->once ()->with ('secret ' )->andReturn ('hashed_secret ' );
47+
4448 $ clients = m::mock (ClientRepository::class);
4549 $ user = m::mock (Authenticatable::class);
4650 $ user ->shouldReceive ('getAuthIdentifier ' )->andReturn (1 );
@@ -51,7 +55,11 @@ public function test_clients_can_be_stored()
5155 $ clients ->shouldReceive ('createAuthorizationCodeGrantClient ' )
5256 ->once ()
5357 ->with ('client name ' , ['http://localhost ' ], true , $ user )
54- ->andReturn ($ client = new Client (['name ' => 'client ' ]));
58+ ->andReturn ($ client = new Client ([
59+ 'name ' => 'client name ' ,
60+ 'redirect ' => 'http://localhost ' ,
61+ 'secret ' => 'secret ' ,
62+ ]));
5563
5664 $ redirectRule = m::mock (RedirectRule::class);
5765
@@ -70,10 +78,13 @@ public function test_clients_can_be_stored()
7078 $ clients , $ validator , $ redirectRule
7179 );
7280
73- $ this ->assertEquals ([
74- 'name ' => $ client ->name ,
75- 'plainSecret ' => $ client ->plainSecret ,
76- ], $ controller ->store ($ request ));
81+ $ this ->assertEquals ($ client , $ controller ->store ($ request ));
82+ $ this ->assertSame ('hashed_secret ' , $ client ->secret );
83+ $ this ->assertSame ([
84+ 'name ' => 'client name ' ,
85+ 'redirect ' => 'http://localhost ' ,
86+ 'plain_secret ' => 'secret ' ,
87+ ], $ client ->toArray ());
7788 }
7889
7990 public function test_public_clients_can_be_stored ()
@@ -92,7 +103,11 @@ public function test_public_clients_can_be_stored()
92103 $ clients ->shouldReceive ('createAuthorizationCodeGrantClient ' )
93104 ->once ()
94105 ->with ('client name ' , ['http://localhost ' ], false , $ user )
95- ->andReturn ($ client = new Client (['name ' => 'client ' ]));
106+ ->andReturn ($ client = new Client ([
107+ 'name ' => 'client name ' ,
108+ 'redirect ' => 'http://localhost ' ,
109+ 'secret ' => null ,
110+ ]));
96111
97112 $ redirectRule = m::mock (RedirectRule::class);
98113
@@ -112,10 +127,12 @@ public function test_public_clients_can_be_stored()
112127 $ clients , $ validator , $ redirectRule
113128 );
114129
115- $ this ->assertEquals ([
116- 'name ' => $ client ->name ,
117- 'plainSecret ' => $ client ->plainSecret ,
118- ], $ controller ->store ($ request ));
130+ $ this ->assertEquals ($ client , $ controller ->store ($ request ));
131+ $ this ->assertNull ($ client ->secret );
132+ $ this ->assertSame ([
133+ 'name ' => 'client name ' ,
134+ 'redirect ' => 'http://localhost ' ,
135+ ], $ client ->toArray ());
119136 }
120137
121138 public function test_clients_can_be_updated ()
0 commit comments