Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 67 additions & 22 deletions tests/Chain/StructuredOutput/ResponseFormatFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,33 +19,76 @@
final class ResponseFormatFactoryTest extends TestCase
{
#[Test]
public function create(): void
#[DataProvider('createProvider')]
/**
* @param array<mixed> $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

Check failure on line 32 in tests/Chain/StructuredOutput/ResponseFormatFactoryTest.php

View workflow job for this annotation

GitHub Actions / qa

Method PhpLlm\LlmChain\Tests\Chain\StructuredOutput\ResponseFormatFactoryTest::createProvider() return type has no value type specified in iterable type 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,
];
}
}
20 changes: 20 additions & 0 deletions tests/Fixture/StructuredOutput/UserWithAtParamAnnotation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace PhpLlm\LlmChain\Tests\Fixture\StructuredOutput;

final class UserWithAtParamAnnotation
{
public function __construct(
public int $id,
/**
* @param string The name of the user in lowercase
*/
public string $name,
public \DateTimeInterface $createdAt,
public bool $isActive,
public ?int $age = null,
) {
}
}
Loading