Skip to content

Commit

Permalink
add debug logging to for proxy config
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Brahmer <[email protected]>
  • Loading branch information
Grotax committed Jan 5, 2025
1 parent 87322cb commit df01931
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
28 changes: 26 additions & 2 deletions lib/Config/FetcherConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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);

Expand All @@ -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;
}

Expand Down
15 changes: 12 additions & 3 deletions tests/Unit/Config/FetcherConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OCP\App\IAppManager;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;

/**
* Class FetcherConfigTest
Expand All @@ -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)
Expand All @@ -62,14 +66,19 @@ protected function setUp(): void
$this->appmanager = $this->getMockBuilder(IAppManager::class)
->disableOriginalConstructor()
->getMock();

$this->logger = $this->getMockBuilder(LoggerInterface::class)
->disableOriginalConstructor()
->getMock();

}

/**
* Test a valid call will work
*/
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());
}
Expand All @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit df01931

Please sign in to comment.