From c092dbdda13b0b0c33f28ee65b16db91cd9d947b Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 8 Oct 2026 22:22:56 +0300 Subject: [PATCH] fix: use JSONFICATOR_OPENAI_API_KEY env var consistently --- src/Provider/OpenAIProvider.php | 4 ++-- tests/Integration/OpenAIIntegrationTest.php | 3 ++- tests/Unit/OpenAIProviderTest.php | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Provider/OpenAIProvider.php b/src/Provider/OpenAIProvider.php index ed2888d..4d42521 100644 --- a/src/Provider/OpenAIProvider.php +++ b/src/Provider/OpenAIProvider.php @@ -54,11 +54,11 @@ final class OpenAIProvider implements LLMProviderInterface array $config = [], ) { $host = $config['host'] ?? 'https://api.openai.com/v1'; - $key = $config['key'] ?? ($_SERVER['OPENAI_API_KEY'] ?? null); + $key = $config['key'] ?? ($_SERVER['JSONFICATOR_OPENAI_API_KEY'] ?? $_ENV['JSONFICATOR_OPENAI_API_KEY'] ?? null); if ($key === null || $key === '') { throw new ProviderException( - 'OpenAI API key is required. Provide it via the "key" config option or the OPENAI_API_KEY environment variable.' + 'OpenAI API key is required. Provide it via the "key" config option or the JSONFICATOR_OPENAI_API_KEY environment variable.' ); } diff --git a/tests/Integration/OpenAIIntegrationTest.php b/tests/Integration/OpenAIIntegrationTest.php index e583798..0d81bc1 100644 --- a/tests/Integration/OpenAIIntegrationTest.php +++ b/tests/Integration/OpenAIIntegrationTest.php @@ -33,8 +33,9 @@ final class OpenAIIntegrationTest extends TestCase public function testToJsonExtractsData(): void { $provider = new OpenAIProvider([ + 'host' => 'https://llm.geckon01.ru', 'key' => self::$apiKey, - 'model' => 'gpt-4o-mini', + 'model' => 'gemma4:latest', ]); $jsonFicator = new JsonFicator($provider); diff --git a/tests/Unit/OpenAIProviderTest.php b/tests/Unit/OpenAIProviderTest.php index 9fb9286..a4f41d5 100644 --- a/tests/Unit/OpenAIProviderTest.php +++ b/tests/Unit/OpenAIProviderTest.php @@ -39,13 +39,13 @@ final class OpenAIProviderTest extends TestCase public function testAcceptsApiKeyFromEnvironment(): void { - $_SERVER['OPENAI_API_KEY'] = 'sk-env'; + $_SERVER['JSONFICATOR_OPENAI_API_KEY'] = 'sk-env'; try { $provider = new OpenAIProvider(); $this->assertInstanceOf(OpenAIProvider::class, $provider); } finally { - unset($_SERVER['OPENAI_API_KEY']); + unset($_SERVER['JSONFICATOR_OPENAI_API_KEY']); } } }