33namespace Spinen \ClickUp \Http \Middleware ;
44
55use Illuminate \Contracts \Routing \UrlGenerator ;
6+ use Illuminate \Foundation \Auth \User ;
67use Illuminate \Http \RedirectResponse ;
78use Illuminate \Http \Request ;
89use Illuminate \Routing \Redirector ;
@@ -63,7 +64,7 @@ protected function setUp(): void
6364 $ this ->request_mock = Mockery::mock (Request::class);
6465 $ this ->response_mock = Mockery::mock (RedirectResponse::class);
6566 $ this ->url_generator_mock = Mockery::mock (UrlGenerator::class);
66- $ this ->user_mock = Mockery::mock (' App\ User' );
67+ $ this ->user_mock = Mockery::mock (User::class );
6768
6869 $ this ->request_mock ->shouldReceive ('user ' )
6970 ->withNoArgs ()
@@ -89,6 +90,7 @@ public function it_calls_next_middleware_if_user_has_a_clickup_token()
8990 $ this ->assertEquals ($ this ->request_mock , $ request );
9091 };
9192
93+ $ this ->mockUserAttributeMutators ('token ' );
9294 $ this ->user_mock ->clickup_token = 'token ' ;
9395
9496 $ this ->filter ->handle ($ this ->request_mock , $ next_middleware );
@@ -104,6 +106,7 @@ public function it_does_not_call_next_middleware_if_user_does_not_have_a_clickup
104106 $ this ->assertTrue (false );
105107 };
106108
109+ $ this ->mockUserAttributeMutators ();
107110 $ this ->user_mock ->clickup_token = null ;
108111
109112 $ this ->clickup_mock ->shouldIgnoreMissing ();
@@ -127,6 +130,7 @@ public function it_sets_intended_url_when_user_does_not_have_a_clickup_token()
127130 $ this ->assertTrue (false );
128131 };
129132
133+ $ this ->mockUserAttributeMutators ();
130134 $ this ->user_mock ->clickup_token = null ;
131135
132136 $ this ->clickup_mock ->shouldIgnoreMissing ();
@@ -162,6 +166,7 @@ public function it_redirects_user_to_correct_uri_if_it_does_not_have_a_clickup_t
162166 $ this ->assertTrue (false );
163167 };
164168
169+ $ this ->mockUserAttributeMutators ();
165170 $ this ->user_mock ->clickup_token = null ;
166171
167172// $this->clickup_mock->shouldIgnoreMissing();
@@ -202,4 +207,22 @@ public function it_redirects_user_to_correct_uri_if_it_does_not_have_a_clickup_t
202207
203208 $ this ->filter ->handle ($ this ->request_mock , $ next_middleware );
204209 }
210+
211+ /**
212+ * Mock out the models setAttribute and getAttribute mutators with the given token
213+ *
214+ * @param string|null $token
215+ */
216+ protected function mockUserAttributeMutators ($ token = null ): void
217+ {
218+ $ this ->user_mock ->shouldReceive ('setAttribute ' )
219+ ->with ('clickup_token ' , $ token )
220+ ->once ()
221+ ->andReturn ($ this ->user_mock );
222+
223+ $ this ->user_mock ->shouldReceive ('getAttribute ' )
224+ ->with ('clickup_token ' )
225+ ->once ()
226+ ->andReturn ($ token );
227+ }
205228}
0 commit comments