Skip to content
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
3 changes: 3 additions & 0 deletions src/LaunchDarkly/LDClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,9 @@ public function allFlagsState(LDContext $context, array $options = []): FeatureF
} catch (UnrecoverableHTTPStatusException $e) {
$this->handleUnrecoverableError();
return new FeatureFlagsState(false);
} catch (\Throwable $e) {
Util::logExceptionAtErrorLevel($this->_logger, $e, "Unable to retrieve flags for allFlagsState");
return new FeatureFlagsState(false);
}
if ($flags === null) {
return new FeatureFlagsState(false);
Expand Down
41 changes: 41 additions & 0 deletions tests/LDClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,47 @@ public function testAllFlagsClientSideVisiblityDoesNotAffectPrereqKeyList()
$this->assertEquals($expectedState, $state->jsonSerialize());
}

public function allFlagsStateRequesterExceptions(): array
{
return [
'unexpected exception' => [new \RuntimeException('store unavailable')],
'PHP error' => [new \Error('requester failed')],
];
}

/** @dataProvider allFlagsStateRequesterExceptions */
public function testAllFlagsStateReturnsInvalidStateWhenRequesterThrows(\Throwable $exception): void
{
$requester = $this->createMock(MockFeatureRequester::class);
$requester->method('getAllFeatures')->willThrowException($exception);
$logger = $this->createMock(LoggerInterface::class);
$logger->expects($this->once())
->method('error')
->with($this->stringContains($exception->getMessage()), ['exception' => $exception]);
$client = $this->makeClient(['feature_requester' => $requester, 'logger' => $logger]);

$state = $client->allFlagsState(LDContext::create('userkey'));

$this->assertFalse($state->isValid());
$this->assertEquals([], $state->toValuesMap());
$this->assertFalse($client->isOffline());
}

/** @dataProvider unrecoverableHTTPStatuses */
public function testAllFlagsStateUnrecoverableHTTPErrorTakesClientOffline(int $status): void
{
$requester = $this->createMock(MockFeatureRequester::class);
$requester->expects($this->once())
->method('getAllFeatures')
->willThrowException(new UnrecoverableHTTPStatusException($status));
$client = $this->makeClient(['feature_requester' => $requester]);
$context = LDContext::create('userkey');

$this->assertFalse($client->allFlagsState($context)->isValid());
$this->assertTrue($client->isOffline());
$this->assertFalse($client->allFlagsState($context)->isValid());
}

public function testIdentifySendsEvent()
{
$ep = new MockEventProcessor();
Expand Down
Loading