DirectoryTree / LdapRecord-Laravel

Multi-domain LDAP Authentication & Management for Laravel.
https://ldaprecord.com/docs/laravel/v3
MIT License
483 stars 51 forks source link

[Bug] logging.channel => null breaks tests using DirectoryEmulator #637

Closed spawnia closed 4 months ago

spawnia commented 4 months ago

Environment:

Describe the bug: I have created a repository to reproduce this bug: https://github.com/mll-lab/ldap-record-directory-emulator-bug.

Starting from a fresh Laravel installation in https://github.com/mll-lab/ldap-record-directory-emulator-bug/commit/9d68715c5dac33a24d221d40cc5a843dee6c97ca, I installed Version 3.2 of this package in https://github.com/mll-lab/ldap-record-directory-emulator-bug/commit/bbaf019a87a4d2ea04d43dddc3289c6ecf98a84c. At this point, running tests works fine.

The test is set up like this:

<?php

use App\Ldap\User;
use LdapRecord\Laravel\Testing\DirectoryEmulator;
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
use Tests\TestCase;

class LdapTest extends TestCase
{
    #[DoesNotPerformAssertions]
    public function test_directory_emulator(): void
    {
        DirectoryEmulator::setup();

        $user = new User();
        $user->foo = 'foo';
        $user->save();
    }
}

However, setting logging.channel to null in config/ldap.php (https://github.com/mll-lab/ldap-record-directory-emulator-bug/commit/a1a66b7013967432f111fdee7f657c78d7cdc52a) causes the following issue when running tests:

bfranke@MLLNB61:~/projects/ldap-record-directory-emulator-bug (master)$ vendor/bin/phpunit
PHPUnit 10.5.11 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.3-1+ubuntu20.04.1+deb.sury.org+1
Configuration: /home/bfranke/projects/ldap-record-directory-emulator-bug/phpunit.xml

..E                                                                 3 / 3 (100%)

Time: 00:00.088, Memory: 28.00 MB

There was 1 error:

1) LdapTest::test_directory_emulator
Illuminate\Contracts\Container\BindingResolutionException: Target class [config] does not exist.

/home/bfranke/projects/ldap-record-directory-emulator-bug/vendor/laravel/framework/src/Illuminate/Container/Container.php:914
/home/bfranke/projects/ldap-record-directory-emulator-bug/vendor/laravel/framework/src/Illuminate/Container/Container.php:795
/home/bfranke/projects/ldap-record-directory-emulator-bug/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:957
/home/bfranke/projects/ldap-record-directory-emulator-bug/vendor/laravel/framework/src/Illuminate/Container/Container.php:731
/home/bfranke/projects/ldap-record-directory-emulator-bug/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:942
/home/bfranke/projects/ldap-record-directory-emulator-bug/vendor/laravel/framework/src/Illuminate/Container/Container.php:1454
/home/bfranke/projects/ldap-record-directory-emulator-bug/vendor/laravel/framework/src/Illuminate/Log/LogManager.php:560
/home/bfranke/projects/ldap-record-directory-emulator-bug/vendor/laravel/framework/src/Illuminate/Log/LogManager.php:611
/home/bfranke/projects/ldap-record-directory-emulator-bug/vendor/laravel/framework/src/Illuminate/Log/LogManager.php:124
/home/bfranke/projects/ldap-record-directory-emulator-bug/vendor/laravel/framework/src/Illuminate/Log/LogManager.php:722
/home/bfranke/projects/ldap-record-directory-emulator-bug/vendor/directorytree/ldaprecord/src/Events/Logger.php:86
/home/bfranke/projects/ldap-record-directory-emulator-bug/vendor/directorytree/ldaprecord/src/Events/Logger.php:37
/home/bfranke/projects/ldap-record-directory-emulator-bug/vendor/directorytree/ldaprecord/src/ConnectionManager.php:167
/home/bfranke/projects/ldap-record-directory-emulator-bug/vendor/directorytree/ldaprecord/src/Events/Dispatcher.php:197
/home/bfranke/projects/ldap-record-directory-emulator-bug/vendor/directorytree/ldaprecord/src/Events/Dispatcher.php:103
/home/bfranke/projects/ldap-record-directory-emulator-bug/vendor/directorytree/ldaprecord/src/Events/Dispatcher.php:84
/home/bfranke/projects/ldap-record-directory-emulator-bug/vendor/directorytree/ldaprecord/src/Models/Concerns/HasEvents.php:63
/home/bfranke/projects/ldap-record-directory-emulator-bug/vendor/directorytree/ldaprecord/src/Models/Concerns/HasEvents.php:55
/home/bfranke/projects/ldap-record-directory-emulator-bug/vendor/directorytree/ldaprecord/src/Models/Concerns/HasEvents.php:44
/home/bfranke/projects/ldap-record-directory-emulator-bug/vendor/directorytree/ldaprecord/src/Models/Model.php:929
/home/bfranke/projects/ldap-record-directory-emulator-bug/tests/Feature/LdapTest.php:17
/home/bfranke/projects/ldap-record-directory-emulator-bug/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:61

Weirdly. the issue goes away when running just the LdapTest:

bfranke@MLLNB61:~/projects/ldap-record-directory-emulator-bug (master)$ vendor/bin/phpunit --filter LdapTest
PHPUnit 10.5.11 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.3-1+ubuntu20.04.1+deb.sury.org+1
Configuration: /home/bfranke/projects/ldap-record-directory-emulator-bug/phpunit.xml

.                                                                   1 / 1 (100%)

Time: 00:00.126, Memory: 28.00 MB

OK (1 test, 0 assertions)

The issue goes away with https://github.com/mll-lab/ldap-record-directory-emulator-bug/commit/a20ca8a27324bc75b2d40c173dfacc3d72f764a6 which uses the change proposed in https://github.com/DirectoryTree/LdapRecord-Laravel/pull/636.

spawnia commented 4 months ago

Thanks for the quick release in https://github.com/DirectoryTree/LdapRecord-Laravel/releases/tag/v3.2.2 @stevebauman.