Skip to content

Commit 5463234

Browse files
committed
add debug logging to for proxy config
Signed-off-by: Benjamin Brahmer <[email protected]>
1 parent 93d4063 commit 5463234

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

lib/Config/FetcherConfig.php

+26-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace OCA\News\Config;
1515

1616
use FeedIo\Adapter\ClientInterface;
17+
use Psr\Log\LoggerInterface;
1718
use \GuzzleHttp\Client;
1819
use OCA\News\AppInfo\Application;
1920
use OCA\News\Fetcher\Client\FeedIoClient;
@@ -72,15 +73,28 @@ class FetcherConfig
7273
* @var int
7374
*/
7475
public const SLEEPY_DURATION = 86400;
76+
77+
/**
78+
* Logger
79+
* @var LoggerInterface
80+
*/
81+
private LoggerInterface $logger;
7582

7683
/**
7784
* FetcherConfig constructor.
7885
*
7986
* @param IAppConfig $config App configuration
8087
* @param IConfig $systemconfig System configuration
88+
* @param IAppManager $appManager App manager
89+
* @param LoggerInterface $logger Logger
8190
*/
82-
public function __construct(IAppConfig $config, IConfig $systemconfig, IAppManager $appManager)
83-
{
91+
public function __construct(
92+
IAppConfig $config,
93+
IConfig $systemconfig,
94+
IAppManager $appManager,
95+
LoggerInterface $logger
96+
) {
97+
$this->logger = $logger;
8498
$this->version = $appManager->getAppVersion(Application::NAME);
8599
$this->client_timeout = $config->getValueInt(
86100
Application::NAME,
@@ -95,8 +109,13 @@ public function __construct(IAppConfig $config, IConfig $systemconfig, IAppManag
95109

96110
$proxy = $systemconfig->getSystemValue('proxy', null);
97111
if (is_null($proxy)) {
112+
$this->logger->debug('No proxy configuration found');
98113
return $this;
99114
}
115+
$this->logger->debug(
116+
'Proxy configuration found: {proxy}',
117+
['proxy' => $proxy]
118+
);
100119

101120
$url = new Net_URL2($proxy);
102121

@@ -108,6 +127,11 @@ public function __construct(IAppConfig $config, IConfig $systemconfig, IAppManag
108127

109128
$this->proxy = $url->getNormalizedURL();
110129

130+
$this->logger->debug(
131+
'Proxy configuration finalized: {proxy}',
132+
['proxy' => $proxy]
133+
);
134+
111135
return $this;
112136
}
113137

tests/Unit/Config/FetcherConfigTest.php

+12-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use OCP\App\IAppManager;
2828
use PHPUnit\Framework\MockObject\MockObject;
2929
use PHPUnit\Framework\TestCase;
30+
use Psr\Log\LoggerInterface;
3031

3132
/**
3233
* Class FetcherConfigTest
@@ -49,6 +50,9 @@ class FetcherConfigTest extends TestCase
4950
/** @var FetcherConfig */
5051
protected $class;
5152

53+
/** @var MockObject|LoggerInterface */
54+
protected $logger;
55+
5256
protected function setUp(): void
5357
{
5458
$this->config = $this->getMockBuilder(IAppConfig::class)
@@ -62,14 +66,19 @@ protected function setUp(): void
6266
$this->appmanager = $this->getMockBuilder(IAppManager::class)
6367
->disableOriginalConstructor()
6468
->getMock();
69+
70+
$this->logger = $this->getMockBuilder(LoggerInterface::class)
71+
->disableOriginalConstructor()
72+
->getMock();
73+
6574
}
6675

6776
/**
6877
* Test a valid call will work
6978
*/
7079
public function testGetClient()
7180
{
72-
$this->class = new FetcherConfig($this->config, $this->sysconfig, $this->appmanager);
81+
$this->class = new FetcherConfig($this->config, $this->sysconfig, $this->appmanager, $this->logger);
7382

7483
$this->assertInstanceOf(FeedIoClient::class, $this->class->getClient());
7584
}
@@ -87,7 +96,7 @@ public function testGetUserAgent()
8796
->method('getAppVersion')
8897
->willReturn('123.45');
8998

90-
$this->class = new FetcherConfig($this->config, $this->sysconfig, $this->appmanager);
99+
$this->class = new FetcherConfig($this->config, $this->sysconfig, $this->appmanager, $this->logger);
91100

92101
$expected = 'NextCloud-News/123.45';
93102
$response = $this->class->getUserAgent();
@@ -107,7 +116,7 @@ public function testGetUserAgentUnknownVersion()
107116
->method('getAppVersion')
108117
->willReturn('1.0');
109118

110-
$this->class = new FetcherConfig($this->config, $this->sysconfig, $this->appmanager);
119+
$this->class = new FetcherConfig($this->config, $this->sysconfig, $this->appmanager, $this->logger);
111120

112121
$expected = 'NextCloud-News/1.0';
113122
$response = $this->class->getUserAgent();

0 commit comments

Comments
 (0)