diff --git a/lib/Config/FetcherConfig.php b/lib/Config/FetcherConfig.php index 7a8fa494f..0b52fb7a6 100644 --- a/lib/Config/FetcherConfig.php +++ b/lib/Config/FetcherConfig.php @@ -14,6 +14,7 @@ namespace OCA\News\Config; use FeedIo\Adapter\ClientInterface; +use Psr\Log\LoggerInterface; use \GuzzleHttp\Client; use OCA\News\AppInfo\Application; use OCA\News\Fetcher\Client\FeedIoClient; @@ -72,15 +73,28 @@ class FetcherConfig * @var int */ public const SLEEPY_DURATION = 86400; + + /** + * Logger + * @var LoggerInterface + */ + private LoggerInterface $logger; /** * FetcherConfig constructor. * * @param IAppConfig $config App configuration * @param IConfig $systemconfig System configuration + * @param IAppManager $appManager App manager + * @param LoggerInterface $logger Logger */ - public function __construct(IAppConfig $config, IConfig $systemconfig, IAppManager $appManager) - { + public function __construct( + IAppConfig $config, + IConfig $systemconfig, + IAppManager $appManager, + LoggerInterface $logger + ) { + $this->logger = $logger; $this->version = $appManager->getAppVersion(Application::NAME); $this->client_timeout = $config->getValueInt( Application::NAME, @@ -95,8 +109,13 @@ public function __construct(IAppConfig $config, IConfig $systemconfig, IAppManag $proxy = $systemconfig->getSystemValue('proxy', null); if (is_null($proxy)) { + $this->logger->debug('No proxy configuration found'); return $this; } + $this->logger->debug( + 'Proxy configuration found: {proxy}', + ['proxy' => $proxy] + ); $url = new Net_URL2($proxy); @@ -108,6 +127,11 @@ public function __construct(IAppConfig $config, IConfig $systemconfig, IAppManag $this->proxy = $url->getNormalizedURL(); + $this->logger->debug( + 'Proxy configuration finalized: {proxy}', + ['proxy' => $proxy] + ); + return $this; } diff --git a/tests/Unit/Config/FetcherConfigTest.php b/tests/Unit/Config/FetcherConfigTest.php index 0b6f70e3b..5b1075de4 100644 --- a/tests/Unit/Config/FetcherConfigTest.php +++ b/tests/Unit/Config/FetcherConfigTest.php @@ -27,6 +27,7 @@ use OCP\App\IAppManager; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use Psr\Log\LoggerInterface; /** * Class FetcherConfigTest @@ -49,6 +50,9 @@ class FetcherConfigTest extends TestCase /** @var FetcherConfig */ protected $class; + /** @var MockObject|LoggerInterface */ + protected $logger; + protected function setUp(): void { $this->config = $this->getMockBuilder(IAppConfig::class) @@ -62,6 +66,11 @@ protected function setUp(): void $this->appmanager = $this->getMockBuilder(IAppManager::class) ->disableOriginalConstructor() ->getMock(); + + $this->logger = $this->getMockBuilder(LoggerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + } /** @@ -69,7 +78,7 @@ protected function setUp(): void */ public function testGetClient() { - $this->class = new FetcherConfig($this->config, $this->sysconfig, $this->appmanager); + $this->class = new FetcherConfig($this->config, $this->sysconfig, $this->appmanager, $this->logger); $this->assertInstanceOf(FeedIoClient::class, $this->class->getClient()); } @@ -87,7 +96,7 @@ public function testGetUserAgent() ->method('getAppVersion') ->willReturn('123.45'); - $this->class = new FetcherConfig($this->config, $this->sysconfig, $this->appmanager); + $this->class = new FetcherConfig($this->config, $this->sysconfig, $this->appmanager, $this->logger); $expected = 'NextCloud-News/123.45'; $response = $this->class->getUserAgent(); @@ -107,7 +116,7 @@ public function testGetUserAgentUnknownVersion() ->method('getAppVersion') ->willReturn('1.0'); - $this->class = new FetcherConfig($this->config, $this->sysconfig, $this->appmanager); + $this->class = new FetcherConfig($this->config, $this->sysconfig, $this->appmanager, $this->logger); $expected = 'NextCloud-News/1.0'; $response = $this->class->getUserAgent();