markTestSkipped('JSONFICATOR_OPENAI_API_KEY environment variable is not set.'); } } public function testToJsonExtractsData(): void { $provider = new OpenAIProvider([ 'host' => self::$host, 'key' => self::$apiKey, 'model' => self::$model, ]); $jsonFicator = new JsonFicator($provider); $result = $jsonFicator->toJson('Brake pads for Nissan Leaf +799999999', [ 'carBrand' => 'string?', 'carModel' => 'string?', 'phoneNumber' => 'string?', ]); $data = $result->toArray(); $this->assertArrayHasKey('carBrand', $data); $this->assertArrayHasKey('carModel', $data); $this->assertArrayHasKey('phoneNumber', $data); // Brand should be detected (Nissan). $this->assertNotNull($data['carBrand']); $this->assertIsString($data['carBrand']); } public function testToJsonDoesNotInventValues(): void { $provider = new OpenAIProvider([ 'host' => self::$host, 'key' => self::$apiKey, 'model' => self::$model, ]); $jsonFicator = new JsonFicator($provider); $result = $jsonFicator->toJson('Brake pads for Nissan Leaf', [ 'brand' => 'string', 'model' => 'string', 'year' => 'int?', 'phone' => 'string?', ]); $data = $result->toArray(); $this->assertSame('Nissan', $data['brand']); $this->assertSame('Leaf', $data['model']); // Year and phone are not present in the text and are nullable. $this->assertNull($data['year']); $this->assertNull($data['phone']); } }