6
6
use Adldap \Connections \Manager ;
7
7
use Adldap \Connections \Provider ;
8
8
use Adldap \Contracts \AdldapInterface ;
9
+ use Adldap \Contracts \Connections \ConnectionInterface ;
9
10
use Adldap \Laravel \Facades \Adldap ;
10
11
use Adldap \Laravel \Tests \Models \User as EloquentUser ;
11
12
use Adldap \Models \User ;
@@ -59,8 +60,12 @@ public function test_auth_passes()
59
60
$ mockedBuilder = $ this ->mock (Builder::class);
60
61
$ mockedSearch = $ this ->mock (Factory::class);
61
62
$ mockedAuth = $ this ->mock (Guard::class);
63
+ $ mockedConnection = $ this ->mock (ConnectionInterface::class);
64
+
65
+ $ mockedConnection ->shouldReceive ('isBound ' )->once ()->andReturn (true );
62
66
63
67
$ mockedBuilder ->shouldReceive ('getSchema ' )->once ()->andReturn (Schema::get ());
68
+ $ mockedBuilder ->shouldReceive ('getConnection ' )->once ()->andReturn ($ mockedConnection );
64
69
65
70
$ adUser = (new User ([], $ mockedBuilder ))->setRawAttributes ([
66
71
'samaccountname ' => ['jdoe ' ],
@@ -115,8 +120,12 @@ public function test_auth_fails()
115
120
$ mockedBuilder = $ this ->mock (Builder::class);
116
121
$ mockedSearch = $ this ->mock (Factory::class);
117
122
$ mockedAuth = $ this ->mock (Guard::class);
123
+ $ mockedConnection = $ this ->mock (ConnectionInterface::class);
124
+
125
+ $ mockedConnection ->shouldReceive ('isBound ' )->once ()->andReturn (true );
118
126
119
127
$ mockedBuilder ->shouldReceive ('getSchema ' )->once ()->andReturn (Schema::get ());
128
+ $ mockedBuilder ->shouldReceive ('getConnection ' )->once ()->andReturn ($ mockedConnection );
120
129
121
130
$ adUser = (new User ([], $ mockedBuilder ))->setRawAttributes ([
122
131
'samaccountname ' => ['jdoe ' ],
@@ -147,6 +156,9 @@ public function test_auth_fails_when_user_not_found()
147
156
$ mockedProvider = $ this ->mock (Provider::class);
148
157
$ mockedBuilder = $ this ->mock (Builder::class);
149
158
$ mockedSearch = $ this ->mock (Factory::class);
159
+ $ mockedConnection = $ this ->mock (ConnectionInterface::class);
160
+
161
+ $ mockedConnection ->shouldReceive ('isBound ' )->once ()->andReturn (true );
150
162
151
163
$ manager = new Manager ();
152
164
@@ -158,6 +170,7 @@ public function test_auth_fails_when_user_not_found()
158
170
$ mockedProvider ->shouldReceive ('getSchema ' )->andReturn (Schema::get ());
159
171
160
172
$ mockedSearch ->shouldReceive ('select ' )->once ()->andReturn ($ mockedBuilder );
173
+ $ mockedBuilder ->shouldReceive ('getConnection ' )->once ()->andReturn ($ mockedConnection );
161
174
$ mockedBuilder ->shouldReceive ('whereEquals ' )->once ()->andReturn ($ mockedBuilder );
162
175
$ mockedBuilder ->shouldReceive ('first ' )->once ()->andReturn (null );
163
176
@@ -168,7 +181,14 @@ public function test_credentials_key_does_not_exist()
168
181
{
169
182
$ mockedProvider = $ this ->mock (Provider::class);
170
183
$ mockedSearch = $ this ->mock (Factory::class);
171
- $ mockedSearch ->shouldReceive ('select ' )->once ()->andReturn ($ mockedSearch );
184
+ $ mockedBuilder = $ this ->mock (Builder::class);
185
+ $ mockedConnection = $ this ->mock (ConnectionInterface::class);
186
+
187
+ $ mockedConnection ->shouldReceive ('isBound ' )->once ()->andReturn (true );
188
+
189
+ $ mockedBuilder ->shouldReceive ('getConnection ' )->once ()->andReturn ($ mockedConnection );
190
+
191
+ $ mockedSearch ->shouldReceive ('select ' )->once ()->andReturn ($ mockedBuilder );
172
192
173
193
$ manager = new Manager ();
174
194
@@ -205,15 +225,20 @@ public function test_config_login_fallback()
205
225
206
226
$ mockedProvider = $ this ->mock (Provider::class);
207
227
$ mockedSearch = $ this ->mock (Factory::class);
208
- $ mockedSearch ->shouldReceive ('select ' )->andReturn ($ mockedSearch );
209
- $ mockedSearch ->shouldReceive ('whereEquals ' )->andReturn ($ mockedSearch );
210
- $ mockedSearch ->shouldReceive ('first ' )->andReturn (null );
228
+ $ mockedConnection = $ this ->mock (ConnectionInterface::class);
229
+
230
+ $ mockedConnection ->shouldReceive ('isBound ' )->twice ()->andReturn (true );
231
+
232
+ $ mockedSearch ->shouldReceive ('select ' )->twice ()->andReturn ($ mockedSearch );
233
+ $ mockedSearch ->shouldReceive ('getConnection ' )->twice ()->andReturn ($ mockedConnection );
234
+ $ mockedSearch ->shouldReceive ('whereEquals ' )->twice ()->andReturn ($ mockedSearch );
235
+ $ mockedSearch ->shouldReceive ('first ' )->twice ()->andReturn (null );
211
236
212
237
$ manager = new Manager ();
213
238
214
239
$ manager ->add ('default ' , $ mockedProvider );
215
- $ mockedProvider ->shouldReceive ('search ' )->andReturn ($ mockedSearch );
216
- $ mockedProvider ->shouldReceive ('getSchema ' )->andReturn (Schema::get ());
240
+ $ mockedProvider ->shouldReceive ('search ' )->twice ()-> andReturn ($ mockedSearch );
241
+ $ mockedProvider ->shouldReceive ('getSchema ' )->twice ()-> andReturn (Schema::get ());
217
242
218
243
Adldap::shouldReceive ('getManager ' )->andReturn ($ manager );
219
244
0 commit comments