diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php index 5f00864..67fee2f 100644 --- a/src/Resources/config/services.php +++ b/src/Resources/config/services.php @@ -6,6 +6,7 @@ use OpenAI; use OpenAI\Client; +use OpenAI\Contracts\ClientContract; use OpenAI\Factory; use Symfony\Component\HttpClient\Psr18Client; @@ -22,5 +23,6 @@ ->set(Client::class) ->factory([service(Factory::class), 'make']) + ->alias(ClientContract::class, Client::class) ->alias('openai', Client::class); }; diff --git a/tests/DependencyInjection/OpenAIExtensionTest.php b/tests/DependencyInjection/OpenAIExtensionTest.php index 1138a03..6514b13 100644 --- a/tests/DependencyInjection/OpenAIExtensionTest.php +++ b/tests/DependencyInjection/OpenAIExtensionTest.php @@ -5,6 +5,7 @@ namespace OpenAI\Symfony\Tests\DependencyInjection; use OpenAI\Client; +use OpenAI\Contracts\ClientContract; use OpenAI\Symfony\DependencyInjection\OpenAIExtension; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -13,7 +14,7 @@ final class OpenAIExtensionTest extends TestCase { - public function testService(): void + public function test_service(): void { // Using a mock to test the service configuration $httpClient = new MockHttpClient(function (string $method, string $url, array $options = []) { @@ -45,5 +46,7 @@ public function testService(): void $response = $openai->files()->delete('file.txt'); self::assertSame('file.txt', $response->id); + + self::assertSame($openai, $container->get(ClientContract::class), 'Alias for the ClientContract interface'); } }