Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit e764815

Browse files
committed
Fix tests
1 parent 964793a commit e764815

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

tests/AdldapTest.php

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Adldap\Connections\Manager;
77
use Adldap\Connections\Provider;
88
use Adldap\Contracts\AdldapInterface;
9+
use Adldap\Contracts\Connections\ConnectionInterface;
910
use Adldap\Laravel\Facades\Adldap;
1011
use Adldap\Laravel\Tests\Models\User as EloquentUser;
1112
use Adldap\Models\User;
@@ -59,8 +60,12 @@ public function test_auth_passes()
5960
$mockedBuilder = $this->mock(Builder::class);
6061
$mockedSearch = $this->mock(Factory::class);
6162
$mockedAuth = $this->mock(Guard::class);
63+
$mockedConnection = $this->mock(ConnectionInterface::class);
64+
65+
$mockedConnection->shouldReceive('isBound')->once()->andReturn(true);
6266

6367
$mockedBuilder->shouldReceive('getSchema')->once()->andReturn(Schema::get());
68+
$mockedBuilder->shouldReceive('getConnection')->once()->andReturn($mockedConnection);
6469

6570
$adUser = (new User([], $mockedBuilder))->setRawAttributes([
6671
'samaccountname' => ['jdoe'],
@@ -115,8 +120,12 @@ public function test_auth_fails()
115120
$mockedBuilder = $this->mock(Builder::class);
116121
$mockedSearch = $this->mock(Factory::class);
117122
$mockedAuth = $this->mock(Guard::class);
123+
$mockedConnection = $this->mock(ConnectionInterface::class);
124+
125+
$mockedConnection->shouldReceive('isBound')->once()->andReturn(true);
118126

119127
$mockedBuilder->shouldReceive('getSchema')->once()->andReturn(Schema::get());
128+
$mockedBuilder->shouldReceive('getConnection')->once()->andReturn($mockedConnection);
120129

121130
$adUser = (new User([], $mockedBuilder))->setRawAttributes([
122131
'samaccountname' => ['jdoe'],
@@ -147,6 +156,9 @@ public function test_auth_fails_when_user_not_found()
147156
$mockedProvider = $this->mock(Provider::class);
148157
$mockedBuilder = $this->mock(Builder::class);
149158
$mockedSearch = $this->mock(Factory::class);
159+
$mockedConnection = $this->mock(ConnectionInterface::class);
160+
161+
$mockedConnection->shouldReceive('isBound')->once()->andReturn(true);
150162

151163
$manager = new Manager();
152164

@@ -158,6 +170,7 @@ public function test_auth_fails_when_user_not_found()
158170
$mockedProvider->shouldReceive('getSchema')->andReturn(Schema::get());
159171

160172
$mockedSearch->shouldReceive('select')->once()->andReturn($mockedBuilder);
173+
$mockedBuilder->shouldReceive('getConnection')->once()->andReturn($mockedConnection);
161174
$mockedBuilder->shouldReceive('whereEquals')->once()->andReturn($mockedBuilder);
162175
$mockedBuilder->shouldReceive('first')->once()->andReturn(null);
163176

@@ -168,7 +181,14 @@ public function test_credentials_key_does_not_exist()
168181
{
169182
$mockedProvider = $this->mock(Provider::class);
170183
$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);
172192

173193
$manager = new Manager();
174194

@@ -205,15 +225,20 @@ public function test_config_login_fallback()
205225

206226
$mockedProvider = $this->mock(Provider::class);
207227
$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);
211236

212237
$manager = new Manager();
213238

214239
$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());
217242

218243
Adldap::shouldReceive('getManager')->andReturn($manager);
219244

0 commit comments

Comments
 (0)