diff --git a/tests/Chain/StructuredOutput/ResponseFormatFactoryTest.php b/tests/Chain/StructuredOutput/ResponseFormatFactoryTest.php index 51825b52..4941d349 100644 --- a/tests/Chain/StructuredOutput/ResponseFormatFactoryTest.php +++ b/tests/Chain/StructuredOutput/ResponseFormatFactoryTest.php @@ -7,7 +7,9 @@ use PhpLlm\LlmChain\Chain\StructuredOutput\ResponseFormatFactory; use PhpLlm\LlmChain\Chain\StructuredOutput\SchemaFactory; use PhpLlm\LlmChain\Tests\Fixture\StructuredOutput\User; +use PhpLlm\LlmChain\Tests\Fixture\StructuredOutput\UserWithAtParamAnnotation; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; @@ -17,33 +19,76 @@ final class ResponseFormatFactoryTest extends TestCase { #[Test] - public function create(): void + #[DataProvider('createProvider')] + /** + * @param array $expected + * @param class-string $class + */ + public function create(array $expected, string $class): void { - self::assertSame([ - 'type' => 'json_schema', - 'json_schema' => [ - 'name' => 'User', - 'schema' => [ - 'title' => 'User', - 'type' => 'object', - 'properties' => [ - 'id' => ['type' => 'integer'], - 'name' => [ - 'type' => 'string', - 'description' => 'The name of the user in lowercase', + self::assertSame($expected, (new ResponseFormatFactory())->create($class)); + } + + public static function createProvider(): iterable + { + yield [ + [ + 'type' => 'json_schema', + 'json_schema' => [ + 'name' => 'User', + 'schema' => [ + 'title' => 'User', + 'type' => 'object', + 'properties' => [ + 'id' => ['type' => 'integer'], + 'name' => [ + 'type' => 'string', + 'description' => 'The name of the user in lowercase', + ], + 'createdAt' => [ + 'type' => 'string', + 'format' => 'date-time', + ], + 'isActive' => ['type' => 'boolean'], + 'age' => ['type' => ['integer', 'null']], ], - 'createdAt' => [ - 'type' => 'string', - 'format' => 'date-time', + 'required' => ['id', 'name', 'createdAt', 'isActive'], + 'additionalProperties' => false, + ], + 'strict' => true, + ], + ], + User::class, + ]; + + yield [ + [ + 'type' => 'json_schema', + 'json_schema' => [ + 'name' => 'User', + 'schema' => [ + 'title' => 'User', + 'type' => 'object', + 'properties' => [ + 'id' => ['type' => 'integer'], + 'name' => [ + 'type' => 'string', + 'description' => 'The name of the user in lowercase', + ], + 'createdAt' => [ + 'type' => 'string', + 'format' => 'date-time', + ], + 'isActive' => ['type' => 'boolean'], + 'age' => ['type' => ['integer', 'null']], ], - 'isActive' => ['type' => 'boolean'], - 'age' => ['type' => ['integer', 'null']], + 'required' => ['id', 'name', 'createdAt', 'isActive'], + 'additionalProperties' => false, ], - 'required' => ['id', 'name', 'createdAt', 'isActive'], - 'additionalProperties' => false, + 'strict' => true, ], - 'strict' => true, ], - ], (new ResponseFormatFactory())->create(User::class)); + UserWithAtParamAnnotation::class, + ]; } } diff --git a/tests/Fixture/StructuredOutput/UserWithAtParamAnnotation.php b/tests/Fixture/StructuredOutput/UserWithAtParamAnnotation.php new file mode 100644 index 00000000..7937a54e --- /dev/null +++ b/tests/Fixture/StructuredOutput/UserWithAtParamAnnotation.php @@ -0,0 +1,20 @@ +