diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 7d9c982f..81f69343 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -14,9 +14,13 @@ jobs: matrix: os: [ubuntu-latest] php: [8.1, 8.0, 7.4, 7.3] - laravel: [8.*, 7.*, 6.*, 5.8.*] + laravel: [9.*, 8.*, 7.*, 6.*, 5.8.*] dependency-version: [prefer-stable] include: + - laravel: 9.* + testbench: 7.* + - laravel: 8.* + testbench: 6.* - laravel: 8.* testbench: 6.* - laravel: 7.* @@ -26,6 +30,10 @@ jobs: - laravel: 5.8.* testbench: 3.8.* exclude: + - laravel: 9.* + php: 7.4 + - laravel: 9.* + php: 7.3 - laravel: 7.* php: 8.1 - laravel: 6.* diff --git a/composer.json b/composer.json index d012e2c8..d5bda036 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,12 @@ { "name": "directorytree/ldaprecord-laravel", "description": "LDAP Authentication & Management for Laravel.", - "keywords": ["ldaprecord", "adldap2", "ldap", "laravel"], + "keywords": [ + "ldaprecord", + "adldap2", + "ldap", + "laravel" + ], "license": "MIT", "type": "project", "require": { @@ -9,16 +14,18 @@ "ext-ldap": "*", "ramsey/uuid": "*", "directorytree/ldaprecord": "^2.4.4", - "illuminate/support": "^5.6|^6.0|^7.0|^8.0" + "illuminate/support": "^5.6|^6.0|^7.0|^8.0|^9.0" }, "require-dev": { - "mockery/mockery": "~1.0", - "phpunit/phpunit": "~7.0|~8.0|~9.0", - "orchestra/testbench": "~3.7|~4.0|~5.0|~6.0", + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^7.0|^8.0|^9.0", + "orchestra/testbench": "^3.7|^4.0|^5.0|^6.0|^7.0", "spatie/ray": "^1.28" }, "archive": { - "exclude": ["/tests"] + "exclude": [ + "/tests" + ] }, "autoload": { "psr-4": { diff --git a/tests/Feature/Emulator/EmulatedAuthenticationTest.php b/tests/Feature/Emulator/EmulatedAuthenticationTest.php index 1dcdbb9d..5f0d8601 100644 --- a/tests/Feature/Emulator/EmulatedAuthenticationTest.php +++ b/tests/Feature/Emulator/EmulatedAuthenticationTest.php @@ -4,6 +4,7 @@ use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Event; use LdapRecord\Laravel\Events\Auth\Binding; use LdapRecord\Laravel\Events\Auth\Bound; use LdapRecord\Laravel\Events\Auth\DiscoveredWithCredentials; @@ -21,16 +22,7 @@ class EmulatedAuthenticationTest extends DatabaseTestCase public function test_plain_ldap_authentication_passes() { - $this->expectsEvents([ - Binding::class, - Bound::class, - DiscoveredWithCredentials::class, - ])->doesntExpectEvents([ - Importing::class, - Imported::class, - Synchronizing::class, - Synchronized::class, - ]); + Event::fake(); $fake = DirectoryEmulator::setup(); @@ -54,20 +46,20 @@ public function test_plain_ldap_authentication_passes() $this->assertTrue($user->is($model)); $this->assertEquals($user->mail[0], $model->mail[0]); $this->assertEquals($user->getDn(), $model->getDn()); + + Event::assertDispatched(Binding::class); + Event::assertDispatched(Bound::class); + Event::assertDispatched(DiscoveredWithCredentials::class); + + Event::assertNotDispatched(Importing::class); + Event::assertNotDispatched(Imported::class); + Event::assertNotDispatched(Synchronizing::class); + Event::assertNotDispatched(Synchronized::class); } public function test_plain_ldap_authentication_fails() { - $this->expectsEvents([ - Binding::class, - DiscoveredWithCredentials::class, - ])->doesntExpectEvents([ - Bound::class, - Importing::class, - Imported::class, - Synchronizing::class, - Synchronized::class, - ]); + Event::fake(); DirectoryEmulator::setup()->shouldBeConnected(); @@ -79,5 +71,14 @@ public function test_plain_ldap_authentication_fails() ]); $this->assertFalse(Auth::attempt(['mail' => $user->mail[0], 'password' => 'secret'])); + + Event::assertDispatched(Binding::class); + Event::assertDispatched(DiscoveredWithCredentials::class); + + Event::assertNotDispatched(Bound::class); + Event::assertNotDispatched(Importing::class); + Event::assertNotDispatched(Imported::class); + Event::assertNotDispatched(Synchronizing::class); + Event::assertNotDispatched(Synchronized::class); } } diff --git a/tests/Feature/Emulator/EmulatedDatabaseAuthenticationTest.php b/tests/Feature/Emulator/EmulatedDatabaseAuthenticationTest.php index e7106f4e..1bb2afdf 100644 --- a/tests/Feature/Emulator/EmulatedDatabaseAuthenticationTest.php +++ b/tests/Feature/Emulator/EmulatedDatabaseAuthenticationTest.php @@ -6,6 +6,7 @@ use Illuminate\Foundation\Auth\User; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Hash; use LdapRecord\Laravel\Auth\AuthenticatesWithLdap; use LdapRecord\Laravel\Auth\HasLdapUser; @@ -30,17 +31,7 @@ class EmulatedDatabaseAuthenticationTest extends DatabaseTestCase public function test_database_sync_authentication_passes() { - $this->expectsEvents([ - DiscoveredWithCredentials::class, - Importing::class, - Imported::class, - Saved::class, - Synchronizing::class, - Synchronized::class, - Binding::class, - Bound::class, - Completed::class, - ]); + Event::fake(); $fake = DirectoryEmulator::setup(); @@ -70,20 +61,21 @@ public function test_database_sync_authentication_passes() $this->assertEquals($user->mail[0], $model->email); $this->assertEquals($user->getConvertedGuid(), $model->guid); $this->assertFalse(Auth::attempt(['mail' => 'invalid', 'password' => 'secret'])); + + Event::assertDispatched(DiscoveredWithCredentials::class); + Event::assertDispatched(Importing::class); + Event::assertDispatched(Imported::class); + Event::assertDispatched(Saved::class); + Event::assertDispatched(Synchronizing::class); + Event::assertDispatched(Synchronized::class); + Event::assertDispatched(Binding::class); + Event::assertDispatched(Bound::class); + Event::assertDispatched(Completed::class); } public function test_database_sync_authentication_fails() { - $this->expectsEvents([ - Binding::class, - Importing::class, - Synchronizing::class, - Synchronized::class, - DiscoveredWithCredentials::class, - ])->doesntExpectEvents([ - Bound::class, - Imported::class, - ]); + Event::fake(); DirectoryEmulator::setup(); @@ -97,6 +89,15 @@ public function test_database_sync_authentication_fails() ]); $this->assertFalse(Auth::attempt(['mail' => $user->mail[0], 'password' => 'secret'])); + + Event::assertDispatched(Binding::class); + Event::assertDispatched(Importing::class); + Event::assertDispatched(Synchronizing::class); + Event::assertDispatched(Synchronized::class); + Event::assertDispatched(DiscoveredWithCredentials::class); + + Event::assertNotDispatched(Bound::class); + Event::assertNotDispatched(Imported::class); } public function test_database_sync_fails_without_object_guid() @@ -120,15 +121,7 @@ public function test_database_sync_fails_without_object_guid() public function test_database_authentication_fallback_works_when_enabled_and_exception_is_thrown() { - $this->doesntExpectEvents([ - Binding::class, - Bound::class, - DiscoveredWithCredentials::class, - Importing::class, - Imported::class, - Synchronizing::class, - Synchronized::class, - ]); + Event::fake(); DirectoryEmulator::setup(); @@ -158,19 +151,19 @@ public function test_database_authentication_fallback_works_when_enabled_and_exc 'password' => 'secret', ], ])); + + Event::assertNotDispatched(Binding::class); + Event::assertNotDispatched(Bound::class); + Event::assertNotDispatched(DiscoveredWithCredentials::class); + Event::assertNotDispatched(Importing::class); + Event::assertNotDispatched(Imported::class); + Event::assertNotDispatched(Synchronizing::class); + Event::assertNotDispatched(Synchronized::class); } public function test_database_authentication_fallback_works_when_enabled_and_null_is_returned() { - $this->doesntExpectEvents([ - Binding::class, - Bound::class, - DiscoveredWithCredentials::class, - Importing::class, - Imported::class, - Synchronizing::class, - Synchronized::class, - ]); + Event::fake(); DirectoryEmulator::setup(); @@ -200,6 +193,14 @@ public function test_database_authentication_fallback_works_when_enabled_and_nul 'password' => 'secret', ], ])); + + Event::assertNotDispatched(Binding::class); + Event::assertNotDispatched(Bound::class); + Event::assertNotDispatched(DiscoveredWithCredentials::class); + Event::assertNotDispatched(Importing::class); + Event::assertNotDispatched(Imported::class); + Event::assertNotDispatched(Synchronizing::class); + Event::assertNotDispatched(Synchronized::class); } public function test_database_authentication_fallback_is_not_performed_when_fallback_credentials_are_not_defined() diff --git a/tests/Feature/Emulator/EmulatedImportTest.php b/tests/Feature/Emulator/EmulatedImportTest.php index a2ddd288..50572da7 100644 --- a/tests/Feature/Emulator/EmulatedImportTest.php +++ b/tests/Feature/Emulator/EmulatedImportTest.php @@ -66,12 +66,14 @@ public function test_import_fails_when_required_attributes_are_missing() { User::create(['cn' => $this->faker->name]); - $this->expectsEvents(ImportFailed::class); + Event::fake(); $this->artisan('ldap:import', [ 'provider' => 'ldap-database', '--no-interaction', ])->assertExitCode(0); + + Event::assertDispatched(ImportFailed::class); } public function test_disabled_users_are_soft_deleted_when_flag_is_set() @@ -90,6 +92,7 @@ public function test_disabled_users_are_soft_deleted_when_flag_is_set() ])->assertExitCode(0); $created = TestUserModelStub::withTrashed()->first(); + $this->assertTrue($created->trashed()); } diff --git a/tests/Feature/Emulator/EmulatedWindowsAuthenticateTest.php b/tests/Feature/Emulator/EmulatedWindowsAuthenticateTest.php index 7ce13553..55b8950d 100644 --- a/tests/Feature/Emulator/EmulatedWindowsAuthenticateTest.php +++ b/tests/Feature/Emulator/EmulatedWindowsAuthenticateTest.php @@ -4,6 +4,7 @@ use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Event; use LdapRecord\Laravel\Events\Auth\Binding; use LdapRecord\Laravel\Events\Auth\Bound; use LdapRecord\Laravel\Events\Auth\CompletedWithWindows; @@ -40,16 +41,7 @@ protected function tearDown(): void public function test_windows_authenticated_user_is_signed_in() { - $this->expectsEvents([ - Importing::class, - Imported::class, - Synchronizing::class, - Synchronized::class, - Binding::class, - Bound::class, - Saved::class, - CompletedWithWindows::class, - ]); + Event::fake(); DirectoryEmulator::setup(); @@ -74,20 +66,20 @@ public function test_windows_authenticated_user_is_signed_in() $this->assertTrue(auth()->check()); $this->assertEquals($user->getConvertedGuid(), auth()->user()->guid); }); + + Event::assertDispatched(Importing::class); + Event::assertDispatched(Imported::class); + Event::assertDispatched(Synchronizing::class); + Event::assertDispatched(Synchronized::class); + Event::assertDispatched(Binding::class); + Event::assertDispatched(Bound::class); + Event::assertDispatched(Saved::class); + Event::assertDispatched(CompletedWithWindows::class); } public function test_kerberos_authenticated_user_is_signed_in() { - $this->expectsEvents([ - Importing::class, - Imported::class, - Synchronizing::class, - Synchronized::class, - Binding::class, - Bound::class, - Saved::class, - CompletedWithWindows::class, - ]); + Event::fake(); DirectoryEmulator::setup(); @@ -122,5 +114,14 @@ public function test_kerberos_authenticated_user_is_signed_in() $this->assertTrue(auth()->check()); $this->assertEquals($user->getConvertedGuid(), auth()->user()->guid); }); + + Event::assertDispatched(Importing::class); + Event::assertDispatched(Imported::class); + Event::assertDispatched(Synchronizing::class); + Event::assertDispatched(Synchronized::class); + Event::assertDispatched(Binding::class); + Event::assertDispatched(Bound::class); + Event::assertDispatched(Saved::class); + Event::assertDispatched(CompletedWithWindows::class); } } diff --git a/tests/Feature/LdapUserSynchronizerTest.php b/tests/Feature/LdapUserSynchronizerTest.php index bff647c4..fb77bae1 100644 --- a/tests/Feature/LdapUserSynchronizerTest.php +++ b/tests/Feature/LdapUserSynchronizerTest.php @@ -2,6 +2,7 @@ namespace LdapRecord\Laravel\Tests\Feature; +use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Hash; use LdapRecord\Laravel\Events\Import\Importing; use LdapRecord\Laravel\Events\Import\Synchronized; @@ -35,7 +36,7 @@ public function test_config_can_be_set() public function test_new_ldap_user_has_guid_and_domain_set() { - $this->expectsEvents([Importing::class, Synchronizing::class, Synchronized::class]); + Event::fake(); $ldapModel = $this->getMockLdapModel(); @@ -43,6 +44,10 @@ public function test_new_ldap_user_has_guid_and_domain_set() $model = $synchronizer->run($ldapModel); + Event::assertDispatched(Importing::class); + Event::assertDispatched(Synchronizing::class); + Event::assertDispatched(Synchronized::class); + $this->assertInstanceOf(TestUserModelStub::class, $model); $this->assertEquals('guid', $model->getLdapGuid()); $this->assertEquals('default', $model->getLdapDomain()); @@ -51,7 +56,7 @@ public function test_new_ldap_user_has_guid_and_domain_set() public function test_new_ldap_user_has_attributes_synchronized() { - $this->expectsEvents([Importing::class, Synchronizing::class, Synchronized::class]); + Event::fake(); $ldapModel = $this->getMockLdapModel(['cn' => 'john', 'mail' => 'test@email.com']); @@ -60,6 +65,11 @@ public function test_new_ldap_user_has_attributes_synchronized() $synchronizer = new UserSynchronizer(TestUserModelStub::class, $attributesToSynchronize); $model = $synchronizer->run($ldapModel); + + Event::assertDispatched(Importing::class); + Event::assertDispatched(Synchronizing::class); + Event::assertDispatched(Synchronized::class); + $this->assertInstanceOf(TestUserModelStub::class, $model); $this->assertEquals('guid', $model->getLdapGuid()); $this->assertEquals('default', $model->getLdapDomain()); @@ -70,7 +80,7 @@ public function test_new_ldap_user_has_attributes_synchronized() public function test_new_ldap_user_has_attributes_synchronized_via_handler() { - $this->expectsEvents([Importing::class, Synchronizing::class, Synchronized::class]); + Event::fake(); $ldapModel = $this->getMockLdapModel(['cn' => 'john', 'mail' => 'test@email.com']); @@ -79,6 +89,11 @@ public function test_new_ldap_user_has_attributes_synchronized_via_handler() ]); $model = $synchronizer->run($ldapModel); + + Event::assertDispatched(Importing::class); + Event::assertDispatched(Synchronizing::class); + Event::assertDispatched(Synchronized::class); + $this->assertInstanceOf(TestUserModelStub::class, $model); $this->assertEquals('guid', $model->getLdapGuid()); $this->assertEquals('default', $model->getLdapDomain()); @@ -91,7 +106,7 @@ public function test_new_ldap_user_has_attributes_synchronized_via_handler() public function test_ldap_sync_attributes_can_be_string() { - $this->expectsEvents([Importing::class, Synchronizing::class, Synchronized::class]); + Event::fake(); $ldapModel = $this->getMockLdapModel(['cn' => 'john', 'mail' => 'test@email.com']); @@ -101,6 +116,10 @@ public function test_ldap_sync_attributes_can_be_string() $model = $synchronizer->run($ldapModel); + Event::assertDispatched(Importing::class); + Event::assertDispatched(Synchronizing::class); + Event::assertDispatched(Synchronized::class); + $this->assertInstanceOf(TestUserModelStub::class, $model); $this->assertEquals('guid', $model->getLdapGuid()); $this->assertEquals('default', $model->getLdapDomain()); @@ -113,7 +132,7 @@ public function test_ldap_sync_attributes_can_be_string() public function test_password_is_synchronized_when_enabled() { - $this->expectsEvents([Importing::class, Synchronizing::class, Synchronized::class]); + Event::fake(); $ldapModel = $this->getMockLdapModel(); @@ -126,13 +145,17 @@ public function test_password_is_synchronized_when_enabled() $model = $synchronizer->run($ldapModel, ['password' => $password]); + Event::assertDispatched(Importing::class); + Event::assertDispatched(Synchronizing::class); + Event::assertDispatched(Synchronized::class); + $this->assertInstanceOf(TestUserModelStub::class, $model); $this->assertTrue(Hash::check($password, $model->password)); } public function test_password_is_not_updated_when_sync_is_disabled_and_password_is_already_set() { - $this->expectsEvents([Synchronizing::class, Synchronized::class])->doesntExpectEvents([Importing::class]); + Event::fake(); $ldapModel = $this->getMockLdapModel(['']); @@ -151,15 +174,20 @@ public function test_password_is_not_updated_when_sync_is_disabled_and_password_ $this->assertEquals('initial', $model->password); $imported = $synchronizer->run($ldapModel); + $imported->save(); + Event::assertNotDispatched(Importing::class); + Event::assertDispatched(Synchronizing::class); + Event::assertDispatched(Synchronized::class); + $this->assertTrue($model->is($imported)); $this->assertEquals('initial', $imported->password); } public function test_user_is_not_updated_when_the_same_hashed_password_already_exists() { - $this->expectsEvents([Synchronizing::class, Synchronized::class])->doesntExpectEvents([Importing::class]); + Event::fake(); $ldapModel = $this->getMockLdapModel(); @@ -182,8 +210,13 @@ public function test_user_is_not_updated_when_the_same_hashed_password_already_e $this->assertEquals($hashedPassword, $model->password); $imported = $synchronizer->run($ldapModel, ['password' => 'secret']); + $imported->save(); + Event::assertNotDispatched(Importing::class); + Event::assertDispatched(Synchronizing::class); + Event::assertDispatched(Synchronized::class); + $this->assertTrue($imported->is($model)); $this->assertTrue(Hash::check('secret', $model->password)); $this->assertEquals($initialUpdateTimestamp, $model->fresh()->updated_at); diff --git a/tests/Feature/WindowsAuthMiddlewareTest.php b/tests/Feature/WindowsAuthMiddlewareTest.php index 3f65c525..7dfeac12 100644 --- a/tests/Feature/WindowsAuthMiddlewareTest.php +++ b/tests/Feature/WindowsAuthMiddlewareTest.php @@ -4,6 +4,7 @@ use Exception; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Event; use InvalidArgumentException; use LdapRecord\Laravel\Auth\NoDatabaseUserProvider; use LdapRecord\Laravel\Auth\Rule; @@ -43,28 +44,22 @@ protected function tearDown(): void public function test_request_continues_if_user_is_not_set_in_the_server_params() { - $this->doesntExpectEvents([ - Importing::class, - Imported::class, - Synchronizing::class, - Synchronized::class, - CompletedWithWindows::class, - ]); + Event::fake(); app(WindowsAuthenticate::class)->handle(new Request, function () { $this->assertTrue(true); }); + + Event::assertNotDispatched(Importing::class); + Event::assertNotDispatched(Imported::class); + Event::assertNotDispatched(Synchronizing::class); + Event::assertNotDispatched(Synchronized::class); + Event::assertNotDispatched(CompletedWithWindows::class); } public function test_request_continues_if_user_is_already_logged_in() { - $this->doesntExpectEvents([ - Importing::class, - Imported::class, - Synchronizing::class, - Synchronized::class, - CompletedWithWindows::class, - ]); + Event::fake(); auth()->login($this->createTestUser([ 'name' => 'Steve Bauman', @@ -75,17 +70,17 @@ public function test_request_continues_if_user_is_already_logged_in() app(WindowsAuthenticate::class)->handle(new Request, function () { $this->assertTrue(true); }); + + Event::assertNotDispatched(Importing::class); + Event::assertNotDispatched(Imported::class); + Event::assertNotDispatched(Synchronizing::class); + Event::assertNotDispatched(Synchronized::class); + Event::assertNotDispatched(CompletedWithWindows::class); } public function test_request_continues_if_ldap_user_cannot_be_located() { - $this->doesntExpectEvents([ - Importing::class, - Imported::class, - Synchronizing::class, - Synchronized::class, - CompletedWithWindows::class, - ]); + Event::fake(); $this->setupDatabaseUserProvider([ 'database' => [ @@ -109,19 +104,19 @@ public function test_request_continues_if_ldap_user_cannot_be_located() $this->assertTrue(true); $this->assertFalse(auth()->check()); }); + + Event::assertNotDispatched(Importing::class); + Event::assertNotDispatched(Imported::class); + Event::assertNotDispatched(Synchronizing::class); + Event::assertNotDispatched(Synchronized::class); + Event::assertNotDispatched(CompletedWithWindows::class); } public function test_authenticates_with_database_user_provider() { WindowsAuthenticate::rememberAuthenticatedUsers(); - $this->expectsEvents([ - Importing::class, - Imported::class, - Synchronizing::class, - Synchronized::class, - CompletedWithWindows::class, - ]); + Event::fake(); $this->setupDatabaseUserProvider([ 'database' => [ @@ -161,18 +156,17 @@ public function test_authenticates_with_database_user_provider() $this->assertSame(auth()->user(), $model); $this->assertNotEmpty(auth()->user()->getRememberToken()); }); + + Event::assertDispatched(Importing::class); + Event::assertDispatched(Imported::class); + Event::assertDispatched(Synchronizing::class); + Event::assertDispatched(Synchronized::class); + Event::assertDispatched(CompletedWithWindows::class); } public function test_authenticates_with_plain_user_provider() { - $this->expectsEvents([CompletedWithWindows::class]); - - $this->doesntExpectEvents([ - Importing::class, - Imported::class, - Synchronizing::class, - Synchronized::class, - ]); + Event::fake(); $this->setupPlainUserProvider(); @@ -199,6 +193,13 @@ public function test_authenticates_with_plain_user_provider() app(WindowsAuthenticate::class)->handle($request, function () use ($user) { $this->assertSame(auth()->user(), $user); }); + + Event::assertDispatched(CompletedWithWindows::class); + + Event::assertNotDispatched(Importing::class); + Event::assertNotDispatched(Imported::class); + Event::assertNotDispatched(Synchronizing::class); + Event::assertNotDispatched(Synchronized::class); } public function test_server_key_can_be_set() diff --git a/tests/Unit/LdapUserAuthenticatorTest.php b/tests/Unit/LdapUserAuthenticatorTest.php index d323f326..29b807b4 100644 --- a/tests/Unit/LdapUserAuthenticatorTest.php +++ b/tests/Unit/LdapUserAuthenticatorTest.php @@ -3,6 +3,7 @@ namespace LdapRecord\Laravel\Tests\Unit; use Illuminate\Database\Eloquent\Model as EloquentModel; +use Illuminate\Support\Facades\Event; use LdapRecord\Auth\Guard; use LdapRecord\Connection; use LdapRecord\Laravel\Auth\Rule; @@ -34,14 +35,13 @@ public function test_attempt_passes() $auth = new LdapUserAuthenticator; - $this->expectsEvents([ - Binding::class, - Bound::class, - ])->doesntExpectEvents([ - BindFailed::class, - ]); + Event::fake(); $this->assertTrue($auth->attempt($model, 'password')); + + Event::assertDispatched(Binding::class); + Event::assertDispatched(Bound::class); + Event::assertNotDispatched(BindFailed::class); } public function test_attempt_failed() @@ -61,14 +61,13 @@ public function test_attempt_failed() $auth = new LdapUserAuthenticator; - $this->expectsEvents([ - Binding::class, - BindFailed::class, - ])->doesntExpectEvents([ - Bound::class, - ]); + Event::fake(); $this->assertFalse($auth->attempt($model, 'password')); + + Event::assertDispatched(Binding::class); + Event::assertDispatched(BindFailed::class); + Event::assertNotDispatched(Bound::class); } public function test_auth_fails_due_to_rules() @@ -88,15 +87,14 @@ public function test_auth_fails_due_to_rules() $auth = new LdapUserAuthenticator([TestFailingLdapAuthRule::class]); - $this->expectsEvents([ - Binding::class, - Rejected::class, - ])->doesntExpectEvents([ - Bound::class, - BindFailed::class, - ]); + Event::fake(); $this->assertFalse($auth->attempt($model, 'password')); + + Event::assertDispatched(Binding::class); + Event::assertDispatched(Rejected::class); + Event::assertNotDispatched(Bound::class); + Event::assertNotDispatched(BindFailed::class); } public function test_eloquent_model_can_be_set() @@ -118,15 +116,14 @@ public function test_eloquent_model_can_be_set() $auth->setEloquentModel(new TestLdapUserAuthenticatedModelStub); - $this->expectsEvents([ - Binding::class, - Bound::class, - ])->doesntExpectEvents([ - Rejected::class, - BindFailed::class, - ]); + Event::fake(); $this->assertTrue($auth->attempt($model, 'password')); + + Event::assertDispatched(Binding::class); + Event::assertDispatched(Bound::class); + Event::assertNotDispatched(Rejected::class); + Event::assertNotDispatched(BindFailed::class); } protected function getAuthenticatingModelMock($dn)