mirror of
https://github.com/nextcloud/server.git
synced 2026-04-15 22:11:17 -04:00
fix: Use proper DI for LDAP class
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
cc365554c6
commit
60c86848e4
3 changed files with 15 additions and 13 deletions
|
|
@ -53,11 +53,7 @@ class Application extends App implements IBootstrap {
|
|||
}
|
||||
|
||||
public function register(IRegistrationContext $context): void {
|
||||
$context->registerService(ILDAPWrapper::class, function (ContainerInterface $c) {
|
||||
return new LDAP(
|
||||
$c->get(IConfig::class)->getSystemValueString('ldap_log_file')
|
||||
);
|
||||
});
|
||||
$context->registerServiceAlias(ILDAPWrapper::class, LDAP::class);
|
||||
|
||||
$context->registerNotifierService(Notifier::class);
|
||||
|
||||
|
|
|
|||
|
|
@ -18,23 +18,21 @@ use Psr\Log\LoggerInterface;
|
|||
|
||||
class LDAP implements ILDAPWrapper {
|
||||
protected array $curArgs = [];
|
||||
protected LoggerInterface $logger;
|
||||
protected IConfig $config;
|
||||
|
||||
private ?LdapDataCollector $dataCollector = null;
|
||||
|
||||
protected string $logFile = '';
|
||||
|
||||
public function __construct(
|
||||
protected string $logFile = '',
|
||||
IProfiler $profiler,
|
||||
protected IConfig $config,
|
||||
protected LoggerInterface $logger,
|
||||
) {
|
||||
/** @var IProfiler $profiler */
|
||||
$profiler = Server::get(IProfiler::class);
|
||||
if ($profiler->isEnabled()) {
|
||||
$this->dataCollector = new LdapDataCollector();
|
||||
$profiler->add($this->dataCollector);
|
||||
}
|
||||
|
||||
$this->logger = Server::get(LoggerInterface::class);
|
||||
$this->config = Server::get(IConfig::class);
|
||||
$this->logFile = $this->config->getSystemValueString('ldap_log_file');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -8,7 +8,10 @@ declare(strict_types=1);
|
|||
namespace OCA\User_LDAP\Tests;
|
||||
|
||||
use OCA\User_LDAP\LDAP;
|
||||
use OCP\IConfig;
|
||||
use OCP\Profiler\IProfiler;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Test\TestCase;
|
||||
|
||||
class LDAPTest extends TestCase {
|
||||
|
|
@ -18,6 +21,11 @@ class LDAPTest extends TestCase {
|
|||
parent::setUp();
|
||||
$this->ldap = $this->getMockBuilder(LDAP::class)
|
||||
->onlyMethods(['invokeLDAPMethod'])
|
||||
->setConstructorArgs([
|
||||
$this->createMock(IProfiler::class),
|
||||
$this->createMock(IConfig::class),
|
||||
$this->createMock(LoggerInterface::class),
|
||||
])
|
||||
->getMock();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue