Skip to content

refact: Revise ADF log more actionable #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ protected function fetchDatafile()
try {
$response = $this->httpClient->get($this->_url, $options);
} catch (Exception $exception) {
$this->_logger->log(Logger::ERROR, 'Unexpected response when trying to fetch datafile, status code: ' . $exception->getCode());
$this->_logger->log(Logger::ERROR, 'Unexpected response when trying to fetch datafile, status code: ' . $exception->getCode(). '. ' .
'Please check your SDK key and/or datafile access token.');
return null;
}

Expand Down Expand Up @@ -220,7 +221,8 @@ protected function fetchDatafile()
}

// Failed to retrieve datafile from Url.
$this->_logger->log(Logger::ERROR, 'Unexpected response when trying to fetch datafile, status code: ' . $status);
$this->_logger->log(Logger::ERROR, 'Unexpected response when trying to fetch datafile, status code: ' . $status . '. ' .
'Please check your SDK key and/or datafile access token.');
return null;
}

Expand Down
70 changes: 68 additions & 2 deletions tests/ProjectConfigManagerTests/HTTPProjectConfigManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,73 @@ public function testGetConfigReturnsProvidedDatafileWhenHttpClientReturnsInvalid
->getMock();

$mock = new MockHandler([
new Response(307, [], 'Invalid Datafile')
new Response(200, [], 'Invalid Datafile')
]);

$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);

$httpClient = new \ReflectionProperty(HTTPProjectConfigManager::class, 'httpClient');
$httpClient->setAccessible(true);
$httpClient->setValue($configManagerMock, $client);

$configManagerMock->fetch();

$config = DatafileProjectConfig::createProjectConfigFromDatafile(
DATAFILE,
false,
$this->loggerMock,
$this->errorHandlerMock
);

$this->assertEquals($config, $configManagerMock->getConfig());
}

public function testGetConfigReturnsProvidedDatafileWhenHttpClientReturnsUnhandledStatusCode()
{
$configManagerMock = $this->getMockBuilder(HTTPProjectConfigManager::class)
->setConstructorArgs(array(null, $this->url, null, false, DATAFILE, false,
$this->loggerMock, $this->errorHandlerMock))
->setMethods(array('handleResponse'))
->getMock();

$mock = new MockHandler([
new Response(307, [], '')
]);

$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);

$httpClient = new \ReflectionProperty(HTTPProjectConfigManager::class, 'httpClient');
$httpClient->setAccessible(true);
$httpClient->setValue($configManagerMock, $client);

$this->loggerMock->expects($this->once())
->method('log')
->with(Logger::ERROR, sprintf("Unexpected response when trying to fetch datafile, status code: 307. Please check your SDK key and/or datafile access token."));

$configManagerMock->fetch();

$config = DatafileProjectConfig::createProjectConfigFromDatafile(
DATAFILE,
false,
$this->loggerMock,
$this->errorHandlerMock
);

$this->assertEquals($config, $configManagerMock->getConfig());
}

public function testGetConfigReturnsProvidedDatafileWhenHttpClientThrows403Error()
{
$configManagerMock = $this->getMockBuilder(HTTPProjectConfigManager::class)
->setConstructorArgs(array(null, $this->url, null, false, DATAFILE, false,
$this->loggerMock, $this->errorHandlerMock))
->setMethods(array('handleResponse'))
->getMock();

$mock = new MockHandler([
new Response(403, [], '')
]);

$handler = HandlerStack::create($mock);
Expand All @@ -214,7 +280,7 @@ public function testGetConfigReturnsProvidedDatafileWhenHttpClientReturnsInvalid

$this->loggerMock->expects($this->once())
->method('log')
->with(Logger::ERROR, sprintf("Unexpected response when trying to fetch datafile, status code: 307"));
->with(Logger::ERROR, sprintf("Unexpected response when trying to fetch datafile, status code: 403. Please check your SDK key and/or datafile access token."));

$configManagerMock->fetch();

Expand Down