Skip to content

Commit 72d8848

Browse files
committed
test: Write test case that API throw NoOpclient when Resolving OpenFeatureClient fail
Signed-off-by: tmakinde <makindet74@gmail.com>
1 parent 3fd7fd8 commit 72d8848

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/unit/OpenFeatureAPITest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44

55
namespace OpenFeature\Test\unit;
66

7+
use DG\BypassFinals;
8+
use Exception;
79
use Mockery\MockInterface;
810
use OpenFeature\OpenFeatureAPI;
911
use OpenFeature\Test\APITestHelper;
1012
use OpenFeature\Test\TestCase;
1113
use OpenFeature\Test\TestHook;
1214
use OpenFeature\Test\TestProvider;
1315
use OpenFeature\implementation\flags\EvaluationContext;
16+
use OpenFeature\implementation\flags\NoOpClient;
1417
use OpenFeature\implementation\provider\NoOpProvider;
1518
use OpenFeature\interfaces\flags\API;
1619
use OpenFeature\interfaces\hooks\Hook;
@@ -220,4 +223,23 @@ public function testApiWillCreateClientWithProvider(): void
220223
$this->assertEquals($name, $client->getMetadata()->getName());
221224
$this->assertInstanceOf(TestProvider::class, $api->getProvider());
222225
}
226+
227+
/**
228+
* @runInSeparateProcess
229+
* @preserveGlobalState disabled
230+
*/
231+
public function testReturnsNoOpClientWhenClientResolutionFails(): void
232+
{
233+
BypassFinals::enable();
234+
$name = 'test-name';
235+
$version = 'test-version';
236+
/** @var (MockInterface&OpenFeatureAPI) $api @phpstan-ignore-line */
237+
$api = $this->mockery(OpenFeatureAPI::class)->shouldAllowMockingProtectedMethods()->makePartial(); // @phpstan-ignore-line
238+
239+
$api->shouldReceive('resolveClient')->once()
240+
->with($name, $version)
241+
->andThrow(new Exception('Simulated client resolution failure'));
242+
$client = $api->getClient($name, $version);
243+
$this->assertInstanceOf(NoOpClient::class, $client);
244+
}
223245
}

0 commit comments

Comments
 (0)