|
4 | 4 |
|
5 | 5 | namespace OpenFeature\Test\unit; |
6 | 6 |
|
| 7 | +use DG\BypassFinals; |
| 8 | +use Exception; |
7 | 9 | use Mockery\MockInterface; |
8 | 10 | use OpenFeature\OpenFeatureAPI; |
9 | 11 | use OpenFeature\Test\APITestHelper; |
10 | 12 | use OpenFeature\Test\TestCase; |
11 | 13 | use OpenFeature\Test\TestHook; |
12 | 14 | use OpenFeature\Test\TestProvider; |
13 | 15 | use OpenFeature\implementation\flags\EvaluationContext; |
| 16 | +use OpenFeature\implementation\flags\NoOpClient; |
14 | 17 | use OpenFeature\implementation\provider\NoOpProvider; |
15 | 18 | use OpenFeature\interfaces\flags\API; |
16 | 19 | use OpenFeature\interfaces\hooks\Hook; |
@@ -220,4 +223,23 @@ public function testApiWillCreateClientWithProvider(): void |
220 | 223 | $this->assertEquals($name, $client->getMetadata()->getName()); |
221 | 224 | $this->assertInstanceOf(TestProvider::class, $api->getProvider()); |
222 | 225 | } |
| 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 | + } |
223 | 245 | } |
0 commit comments