3
3
namespace Spinen \ClickUp \Http \Middleware ;
4
4
5
5
use Illuminate \Contracts \Routing \UrlGenerator ;
6
+ use Illuminate \Foundation \Auth \User ;
6
7
use Illuminate \Http \RedirectResponse ;
7
8
use Illuminate \Http \Request ;
8
9
use Illuminate \Routing \Redirector ;
@@ -63,7 +64,7 @@ protected function setUp(): void
63
64
$ this ->request_mock = Mockery::mock (Request::class);
64
65
$ this ->response_mock = Mockery::mock (RedirectResponse::class);
65
66
$ this ->url_generator_mock = Mockery::mock (UrlGenerator::class);
66
- $ this ->user_mock = Mockery::mock (' App\ User' );
67
+ $ this ->user_mock = Mockery::mock (User::class );
67
68
68
69
$ this ->request_mock ->shouldReceive ('user ' )
69
70
->withNoArgs ()
@@ -89,6 +90,7 @@ public function it_calls_next_middleware_if_user_has_a_clickup_token()
89
90
$ this ->assertEquals ($ this ->request_mock , $ request );
90
91
};
91
92
93
+ $ this ->mockUserAttributeMutators ('token ' );
92
94
$ this ->user_mock ->clickup_token = 'token ' ;
93
95
94
96
$ 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
104
106
$ this ->assertTrue (false );
105
107
};
106
108
109
+ $ this ->mockUserAttributeMutators ();
107
110
$ this ->user_mock ->clickup_token = null ;
108
111
109
112
$ this ->clickup_mock ->shouldIgnoreMissing ();
@@ -127,6 +130,7 @@ public function it_sets_intended_url_when_user_does_not_have_a_clickup_token()
127
130
$ this ->assertTrue (false );
128
131
};
129
132
133
+ $ this ->mockUserAttributeMutators ();
130
134
$ this ->user_mock ->clickup_token = null ;
131
135
132
136
$ this ->clickup_mock ->shouldIgnoreMissing ();
@@ -162,6 +166,7 @@ public function it_redirects_user_to_correct_uri_if_it_does_not_have_a_clickup_t
162
166
$ this ->assertTrue (false );
163
167
};
164
168
169
+ $ this ->mockUserAttributeMutators ();
165
170
$ this ->user_mock ->clickup_token = null ;
166
171
167
172
// $this->clickup_mock->shouldIgnoreMissing();
@@ -202,4 +207,22 @@ public function it_redirects_user_to_correct_uri_if_it_does_not_have_a_clickup_t
202
207
203
208
$ this ->filter ->handle ($ this ->request_mock , $ next_middleware );
204
209
}
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
+ }
205
228
}
0 commit comments