diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 6372b467..4d4e83c2 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -31,6 +31,9 @@ jobs: - name: Code Style PHP run: vendor/bin/php-cs-fixer fix --dry-run + - name: Rector + run: vendor/bin/rector + - name: PHPStan run: vendor/bin/phpstan analyse diff --git a/Makefile b/Makefile index 823a36e4..e095021e 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ qa: vendor/bin/php-cs-fixer fix vendor/bin/phpstan vendor/bin/phpunit + vendor/bin/rector qa-lowest: composer update --prefer-lowest diff --git a/composer.json b/composer.json index 0b18e6b2..025a65bf 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "phpstan/phpstan": "^1.12", "phpunit/phpunit": "^11.3", "probots-io/pinecone-php": "^1.0", + "rector/rector": "^1.2", "symfony/clock": "^6.4 || ^7.1", "symfony/console": "^6.4 || ^7.1", "symfony/css-selector": "^6.4 || ^7.1", diff --git a/rector.php b/rector.php new file mode 100644 index 00000000..a2c158ea --- /dev/null +++ b/rector.php @@ -0,0 +1,24 @@ +withPaths([ + __DIR__.'/examples', + __DIR__.'/src', + __DIR__.'/tests', + ]) + ->withPhpSets(php82: true) + ->withSets([ + PHPUnitSetList::PHPUNIT_110, + PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES, + ]) + ->withImportNames(importNames: true, importShortClasses: false) + ->withSkip([ + ClosureToArrowFunctionRector::class, + ]) + ->withTypeCoverageLevel(0); diff --git a/src/Anthropic/Model/Claude.php b/src/Anthropic/Model/Claude.php index 4d456f1d..ccd4fffa 100644 --- a/src/Anthropic/Model/Claude.php +++ b/src/Anthropic/Model/Claude.php @@ -11,7 +11,7 @@ use PhpLlm\LlmChain\Response\Choice; use PhpLlm\LlmChain\Response\Response; -final class Claude implements LanguageModel +final readonly class Claude implements LanguageModel { public function __construct( private ClaudeRuntime $runtime, diff --git a/src/Anthropic/Runtime/Anthropic.php b/src/Anthropic/Runtime/Anthropic.php index e14cb364..afea6444 100644 --- a/src/Anthropic/Runtime/Anthropic.php +++ b/src/Anthropic/Runtime/Anthropic.php @@ -7,7 +7,7 @@ use PhpLlm\LlmChain\Anthropic\ClaudeRuntime; use Symfony\Contracts\HttpClient\HttpClientInterface; -final class Anthropic implements ClaudeRuntime +final readonly class Anthropic implements ClaudeRuntime { public function __construct( private HttpClientInterface $httpClient, diff --git a/src/DocumentEmbedder.php b/src/DocumentEmbedder.php index 8dd4c1db..b7ff38a9 100644 --- a/src/DocumentEmbedder.php +++ b/src/DocumentEmbedder.php @@ -7,7 +7,7 @@ use PhpLlm\LlmChain\Document\Document; use PhpLlm\LlmChain\Store\StoreInterface; -final class DocumentEmbedder +final readonly class DocumentEmbedder { public function __construct( private EmbeddingModel $embeddings, diff --git a/src/OpenAI/Model/Embeddings.php b/src/OpenAI/Model/Embeddings.php index 584829fb..0677aaf3 100644 --- a/src/OpenAI/Model/Embeddings.php +++ b/src/OpenAI/Model/Embeddings.php @@ -9,7 +9,7 @@ use PhpLlm\LlmChain\OpenAI\Model\Embeddings\Version; use PhpLlm\LlmChain\OpenAI\Runtime; -final class Embeddings implements EmbeddingModel +final readonly class Embeddings implements EmbeddingModel { public function __construct( private Runtime $runtime, diff --git a/src/OpenAI/Model/Gpt.php b/src/OpenAI/Model/Gpt.php index 890e309e..85596dd1 100644 --- a/src/OpenAI/Model/Gpt.php +++ b/src/OpenAI/Model/Gpt.php @@ -12,7 +12,7 @@ use PhpLlm\LlmChain\Response\Response; use PhpLlm\LlmChain\Response\ToolCall; -final class Gpt implements LanguageModel +final readonly class Gpt implements LanguageModel { public function __construct( private Runtime $runtime, diff --git a/src/OpenAI/Runtime/Azure.php b/src/OpenAI/Runtime/Azure.php index 6e5225b9..7422111f 100644 --- a/src/OpenAI/Runtime/Azure.php +++ b/src/OpenAI/Runtime/Azure.php @@ -11,11 +11,11 @@ final class Azure extends AbstractRuntime implements Runtime { public function __construct( - private HttpClientInterface $httpClient, - private string $baseUrl, - private string $deployment, - private string $apiVersion, - private string $key, + private readonly HttpClientInterface $httpClient, + private readonly string $baseUrl, + private readonly string $deployment, + private readonly string $apiVersion, + private readonly string $key, ) { } diff --git a/src/OpenAI/Runtime/OpenAI.php b/src/OpenAI/Runtime/OpenAI.php index 897c6141..e37955da 100644 --- a/src/OpenAI/Runtime/OpenAI.php +++ b/src/OpenAI/Runtime/OpenAI.php @@ -11,8 +11,8 @@ final class OpenAI extends AbstractRuntime implements Runtime { public function __construct( - private HttpClientInterface $httpClient, - private string $apiKey, + private readonly HttpClientInterface $httpClient, + private readonly string $apiKey, ) { } diff --git a/src/Store/Azure/SearchStore.php b/src/Store/Azure/SearchStore.php index 2a727c5a..425ec49a 100644 --- a/src/Store/Azure/SearchStore.php +++ b/src/Store/Azure/SearchStore.php @@ -11,14 +11,14 @@ use Symfony\Component\Uid\Uuid; use Symfony\Contracts\HttpClient\HttpClientInterface; -final class SearchStore implements VectorStoreInterface +final readonly class SearchStore implements VectorStoreInterface { public function __construct( - private readonly HttpClientInterface $httpClient, - private readonly string $endpointUrl, - private readonly string $apiKey, - private readonly string $indexName, - private readonly string $apiVersion, + private HttpClientInterface $httpClient, + private string $endpointUrl, + private string $apiKey, + private string $indexName, + private string $apiVersion, ) { } diff --git a/src/Store/ChromaDb/Store.php b/src/Store/ChromaDb/Store.php index 106efedd..1f62f355 100644 --- a/src/Store/ChromaDb/Store.php +++ b/src/Store/ChromaDb/Store.php @@ -12,7 +12,7 @@ use Psr\Log\LoggerInterface; use Symfony\Component\Uid\Uuid; -final class Store implements VectorStoreInterface +final readonly class Store implements VectorStoreInterface { public function __construct( private Client $client, diff --git a/src/StructuredOutput/SchemaFactory.php b/src/StructuredOutput/SchemaFactory.php index af2550d1..c8a2cbc9 100644 --- a/src/StructuredOutput/SchemaFactory.php +++ b/src/StructuredOutput/SchemaFactory.php @@ -9,10 +9,10 @@ use Symfony\Component\PropertyInfo\PropertyInfoExtractor; use Symfony\Component\PropertyInfo\Type; -final class SchemaFactory +final readonly class SchemaFactory { public function __construct( - private readonly PropertyInfoExtractor $propertyInfo, + private PropertyInfoExtractor $propertyInfo, ) { } diff --git a/src/ToolBox/AsTool.php b/src/ToolBox/AsTool.php index a978488e..ad1199a8 100644 --- a/src/ToolBox/AsTool.php +++ b/src/ToolBox/AsTool.php @@ -5,12 +5,12 @@ namespace PhpLlm\LlmChain\ToolBox; #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)] -final class AsTool +final readonly class AsTool { public function __construct( - public readonly string $name, - public readonly string $description, - public readonly string $method = '__invoke', + public string $name, + public string $description, + public string $method = '__invoke', ) { } } diff --git a/src/ToolBox/Metadata.php b/src/ToolBox/Metadata.php index d6c94d2e..a4884f6b 100644 --- a/src/ToolBox/Metadata.php +++ b/src/ToolBox/Metadata.php @@ -7,17 +7,17 @@ /** * @phpstan-import-type ParameterDefinition from ParameterAnalyzer */ -final class Metadata implements \JsonSerializable +final readonly class Metadata implements \JsonSerializable { /** * @param ParameterDefinition|null $parameters */ public function __construct( - public readonly string $className, - public readonly string $name, - public readonly string $description, - public readonly string $method, - public readonly ?array $parameters, + public string $className, + public string $name, + public string $description, + public string $method, + public ?array $parameters, ) { } diff --git a/src/ToolBox/Tool/Clock.php b/src/ToolBox/Tool/Clock.php index f1afc325..8703e83c 100644 --- a/src/ToolBox/Tool/Clock.php +++ b/src/ToolBox/Tool/Clock.php @@ -8,7 +8,7 @@ use Symfony\Component\Clock\ClockInterface; #[AsTool('clock', description: 'Provides the current date and time.')] -final class Clock +final readonly class Clock { public function __construct( private ClockInterface $clock, diff --git a/src/ToolBox/Tool/SerpApi.php b/src/ToolBox/Tool/SerpApi.php index 79f11dde..b0033ce8 100644 --- a/src/ToolBox/Tool/SerpApi.php +++ b/src/ToolBox/Tool/SerpApi.php @@ -8,7 +8,7 @@ use Symfony\Contracts\HttpClient\HttpClientInterface; #[AsTool(name: 'serpapi', description: 'search for information on the internet')] -final class SerpApi +final readonly class SerpApi { public function __construct( private HttpClientInterface $httpClient, diff --git a/src/ToolBox/Tool/Wikipedia.php b/src/ToolBox/Tool/Wikipedia.php index dbcb58cd..3c971364 100644 --- a/src/ToolBox/Tool/Wikipedia.php +++ b/src/ToolBox/Tool/Wikipedia.php @@ -9,7 +9,7 @@ #[AsTool('wikipedia_search', description: 'Searches Wikipedia for a given query', method: 'search')] #[AsTool('wikipedia_article', description: 'Retrieves a Wikipedia article by its title', method: 'getArticle')] -final class Wikipedia +final readonly class Wikipedia { public function __construct( private HttpClientInterface $httpClient, diff --git a/src/ToolBox/ToolAnalyzer.php b/src/ToolBox/ToolAnalyzer.php index ca4bf025..31679208 100644 --- a/src/ToolBox/ToolAnalyzer.php +++ b/src/ToolBox/ToolAnalyzer.php @@ -6,10 +6,10 @@ use PhpLlm\LlmChain\Exception\InvalidToolImplementation; -final class ToolAnalyzer +final readonly class ToolAnalyzer { public function __construct( - private readonly ParameterAnalyzer $parameterAnalyzer = new ParameterAnalyzer(), + private ParameterAnalyzer $parameterAnalyzer = new ParameterAnalyzer(), ) { } diff --git a/tests/Message/MessageBagTest.php b/tests/Message/MessageBagTest.php index 50dddaa0..4e7cd3fc 100644 --- a/tests/Message/MessageBagTest.php +++ b/tests/Message/MessageBagTest.php @@ -8,6 +8,7 @@ use PhpLlm\LlmChain\Message\MessageBag; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Small; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; @@ -16,7 +17,8 @@ #[Small] final class MessageBagTest extends TestCase { - public function testGetSystemMessage(): void + #[Test] + public function getSystemMessage(): void { $messageBag = new MessageBag( Message::forSystem('My amazing system prompt.'), @@ -29,7 +31,8 @@ public function testGetSystemMessage(): void self::assertSame('My amazing system prompt.', $systemMessage->content); } - public function testGetSystemMessageWithoutSystemMessage(): void + #[Test] + public function getSystemMessageWithoutSystemMessage(): void { $messageBag = new MessageBag( Message::ofAssistant('It is time to sleep.'), @@ -39,7 +42,8 @@ public function testGetSystemMessageWithoutSystemMessage(): void self::assertNull($messageBag->getSystemMessage()); } - public function testWith(): void + #[Test] + public function with(): void { $messageBag = new MessageBag( Message::forSystem('My amazing system prompt.'), @@ -55,7 +59,8 @@ public function testWith(): void self::assertSame('It is time to wake up.', $newMessageBag[3]->content); } - public function testWithoutSystemMessage(): void + #[Test] + public function withoutSystemMessage(): void { $messageBag = new MessageBag( Message::forSystem('My amazing system prompt.'), @@ -70,7 +75,8 @@ public function testWithoutSystemMessage(): void self::assertSame('It is time to sleep.', $newMessageBag[0]->content); } - public function testPrepend(): void + #[Test] + public function prepend(): void { $messageBag = new MessageBag( Message::ofAssistant('It is time to sleep.'), @@ -85,7 +91,8 @@ public function testPrepend(): void self::assertSame('My amazing system prompt.', $newMessageBag[0]->content); } - public function testJsonSerialize(): void + #[Test] + public function jsonSerialize(): void { $messageBag = new MessageBag( Message::forSystem('My amazing system prompt.'), diff --git a/tests/Message/MessageTest.php b/tests/Message/MessageTest.php index 0ec7479a..3e27b3fd 100644 --- a/tests/Message/MessageTest.php +++ b/tests/Message/MessageTest.php @@ -9,6 +9,7 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Small; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; @@ -17,7 +18,8 @@ #[Small] final class MessageTest extends TestCase { - public function testCreateSystemMessage(): void + #[Test] + public function createSystemMessage(): void { $message = Message::forSystem('My amazing system prompt.'); @@ -29,7 +31,8 @@ public function testCreateSystemMessage(): void self::assertFalse($message->hasToolCalls()); } - public function testCreateAssistantMessage(): void + #[Test] + public function createAssistantMessage(): void { $message = Message::ofAssistant('It is time to sleep.'); @@ -41,7 +44,8 @@ public function testCreateAssistantMessage(): void self::assertFalse($message->hasToolCalls()); } - public function testCreateAssistantMessageWithToolCalls(): void + #[Test] + public function createAssistantMessageWithToolCalls(): void { $toolCalls = [ new ToolCall('call_123456', 'my_tool', ['foo' => 'bar']), @@ -57,7 +61,8 @@ public function testCreateAssistantMessageWithToolCalls(): void self::assertTrue($message->hasToolCalls()); } - public function testCreateUserMessage(): void + #[Test] + public function createUserMessage(): void { $message = Message::ofUser('Hi, my name is John.'); @@ -69,7 +74,8 @@ public function testCreateUserMessage(): void self::assertFalse($message->hasToolCalls()); } - public function testCreateToolCallMessage(): void + #[Test] + public function createToolCallMessage(): void { $toolCall = new ToolCall('call_123456', 'my_tool', ['foo' => 'bar']); $message = Message::ofToolCall($toolCall, 'Foo bar.'); @@ -84,7 +90,8 @@ public function testCreateToolCallMessage(): void } #[DataProvider('provideJsonScenarios')] - public function testJsonSerialize(Message $message, array $expected): void + #[Test] + public function jsonSerialize(Message $message, array $expected): void { self::assertSame($expected, $message->jsonSerialize()); } diff --git a/tests/Response/ChoiceTest.php b/tests/Response/ChoiceTest.php index 2e9a249c..1cb20181 100644 --- a/tests/Response/ChoiceTest.php +++ b/tests/Response/ChoiceTest.php @@ -8,6 +8,7 @@ use PhpLlm\LlmChain\Response\ToolCall; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Small; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; @@ -16,7 +17,8 @@ #[Small] final class ChoiceTest extends TestCase { - public function testChoiceEmpty(): void + #[Test] + public function choiceEmpty(): void { $choice = new Choice(); self::assertFalse($choice->hasContent()); @@ -25,7 +27,8 @@ public function testChoiceEmpty(): void self::assertCount(0, $choice->getToolCalls()); } - public function testChoiceWithContent(): void + #[Test] + public function choiceWithContent(): void { $choice = new Choice('content'); self::assertTrue($choice->hasContent()); @@ -34,7 +37,8 @@ public function testChoiceWithContent(): void self::assertCount(0, $choice->getToolCalls()); } - public function testChoiceWithToolCall(): void + #[Test] + public function choiceWithToolCall(): void { $choice = new Choice(null, [new ToolCall('name', 'arguments')]); self::assertFalse($choice->hasContent()); @@ -43,7 +47,8 @@ public function testChoiceWithToolCall(): void self::assertCount(1, $choice->getToolCalls()); } - public function testChoiceWithContentAndToolCall(): void + #[Test] + public function choiceWithContentAndToolCall(): void { $choice = new Choice('content', [new ToolCall('name', 'arguments')]); self::assertTrue($choice->hasContent()); diff --git a/tests/Response/ResponseTest.php b/tests/Response/ResponseTest.php index 23d27759..e5eaf50f 100644 --- a/tests/Response/ResponseTest.php +++ b/tests/Response/ResponseTest.php @@ -9,6 +9,7 @@ use PhpLlm\LlmChain\Response\ToolCall; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Small; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; @@ -18,7 +19,8 @@ #[Small] final class ResponseTest extends TestCase { - public function testGetChoices(): void + #[Test] + public function getChoices(): void { $response = new Response( new Choice('content', [new ToolCall('call_123456', 'name', ['foo' => 'bar'])]), @@ -28,7 +30,8 @@ public function testGetChoices(): void self::assertCount(2, $response->getChoices()); } - public function testConstructorThrowsException(): void + #[Test] + public function constructorThrowsException(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Response must have at least one choice'); @@ -36,7 +39,8 @@ public function testConstructorThrowsException(): void $response = new Response(); } - public function testGetContent(): void + #[Test] + public function getContent(): void { $response = new Response( new Choice('content', [new ToolCall('call_123456', 'name', ['foo' => 'bar'])]), @@ -45,7 +49,8 @@ public function testGetContent(): void self::assertSame('content', $response->getContent()); } - public function testGetContentThrowsException(): void + #[Test] + public function getContentThrowsException(): void { $response = new Response( new Choice('content', [new ToolCall('call_123456', 'name', ['foo' => 'bar'])]), @@ -58,7 +63,8 @@ public function testGetContentThrowsException(): void $response->getContent(); } - public function testGetToolCalls(): void + #[Test] + public function getToolCalls(): void { $response = new Response( new Choice('content', [new ToolCall('call_123456', 'name', ['foo' => 'bar'])]), @@ -67,7 +73,8 @@ public function testGetToolCalls(): void self::assertCount(1, $response->getToolCalls()); } - public function testGetToolCallsThrowsException(): void + #[Test] + public function getToolCallsThrowsException(): void { $response = new Response( new Choice('content', [new ToolCall('call_123456', 'name', ['foo' => 'bar'])]), @@ -80,7 +87,8 @@ public function testGetToolCallsThrowsException(): void $response->getToolCalls(); } - public function testHasToolCalls(): void + #[Test] + public function hasToolCalls(): void { $response = new Response( new Choice('content', [new ToolCall('call_123456', 'name', ['foo' => 'bar'])]), @@ -89,7 +97,8 @@ public function testHasToolCalls(): void self::assertTrue($response->hasToolCalls()); } - public function testHasToolCallsReturnsFalse(): void + #[Test] + public function hasToolCallsReturnsFalse(): void { $response = new Response(new Choice('content')); diff --git a/tests/Response/ToolCallTest.php b/tests/Response/ToolCallTest.php index a64fb7d5..7254b0d7 100644 --- a/tests/Response/ToolCallTest.php +++ b/tests/Response/ToolCallTest.php @@ -7,13 +7,15 @@ use PhpLlm\LlmChain\Response\ToolCall; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Small; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; #[CoversClass(ToolCall::class)] #[Small] final class ToolCallTest extends TestCase { - public function testToolCall(): void + #[Test] + public function toolCall(): void { $toolCall = new ToolCall('id', 'name', ['foo' => 'bar']); self::assertSame('id', $toolCall->id); @@ -21,7 +23,8 @@ public function testToolCall(): void self::assertSame(['foo' => 'bar'], $toolCall->arguments); } - public function testToolCallJsonSerialize(): void + #[Test] + public function toolCallJsonSerialize(): void { $toolCall = new ToolCall('id', 'name', ['foo' => 'bar']); self::assertSame( diff --git a/tests/StructuredOutput/SchemaFactoryTest.php b/tests/StructuredOutput/SchemaFactoryTest.php index 19864264..78f65788 100644 --- a/tests/StructuredOutput/SchemaFactoryTest.php +++ b/tests/StructuredOutput/SchemaFactoryTest.php @@ -9,6 +9,7 @@ use PhpLlm\LlmChain\Tests\StructuredOutput\Data\Step; use PhpLlm\LlmChain\Tests\StructuredOutput\Data\User; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; #[CoversClass(SchemaFactory::class)] @@ -21,7 +22,8 @@ protected function setUp(): void $this->schemaFactory = SchemaFactory::create(); } - public function testBuildSchemaForUserClass(): void + #[Test] + public function buildSchemaForUserClass(): void { $expected = [ 'title' => 'User', @@ -44,7 +46,8 @@ public function testBuildSchemaForUserClass(): void self::assertSame($expected, $actual); } - public function testBuildSchemaForMathReasoningClass(): void + #[Test] + public function buildSchemaForMathReasoningClass(): void { $expected = [ 'title' => 'MathReasoning', @@ -74,7 +77,8 @@ public function testBuildSchemaForMathReasoningClass(): void self::assertSame($expected, $actual); } - public function testBuildSchemaForStepClass(): void + #[Test] + public function buildSchemaForStepClass(): void { $expected = [ 'title' => 'Step', diff --git a/tests/ToolBox/ParameterAnalyzerTest.php b/tests/ToolBox/ParameterAnalyzerTest.php index f49215f2..7d5f1766 100644 --- a/tests/ToolBox/ParameterAnalyzerTest.php +++ b/tests/ToolBox/ParameterAnalyzerTest.php @@ -11,6 +11,7 @@ use PhpLlm\LlmChain\ToolBox\Metadata; use PhpLlm\LlmChain\ToolBox\ParameterAnalyzer; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; @@ -27,7 +28,8 @@ protected function setUp(): void $this->analyzer = new ParameterAnalyzer(); } - public function testDetectParameterDefinitionRequired(): void + #[Test] + public function detectParameterDefinitionRequired(): void { $actual = $this->analyzer->getDefinition(ToolRequiredParams::class, 'bar'); $expected = [ @@ -51,7 +53,8 @@ public function testDetectParameterDefinitionRequired(): void self::assertSame($expected, $actual); } - public function testDetectParameterDefinitionOptional(): void + #[Test] + public function detectParameterDefinitionOptional(): void { $actual = $this->analyzer->getDefinition(ToolOptionalParam::class, 'bar'); $expected = [ @@ -74,7 +77,8 @@ public function testDetectParameterDefinitionOptional(): void self::assertSame($expected, $actual); } - public function testDetectParameterDefinitionNone(): void + #[Test] + public function detectParameterDefinitionNone(): void { $actual = $this->analyzer->getDefinition(ToolNoParams::class, '__invoke'); diff --git a/tests/ToolBox/ToolAnalyzerTest.php b/tests/ToolBox/ToolAnalyzerTest.php index eba9fb02..914fc45a 100644 --- a/tests/ToolBox/ToolAnalyzerTest.php +++ b/tests/ToolBox/ToolAnalyzerTest.php @@ -13,6 +13,7 @@ use PhpLlm\LlmChain\ToolBox\ParameterAnalyzer; use PhpLlm\LlmChain\ToolBox\ToolAnalyzer; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; @@ -30,13 +31,15 @@ protected function setUp(): void $this->toolAnalyzer = new ToolAnalyzer(new ParameterAnalyzer()); } - public function testWithoutAttribute(): void + #[Test] + public function withoutAttribute(): void { $this->expectException(InvalidToolImplementation::class); iterator_to_array($this->toolAnalyzer->getMetadata(ToolWrong::class)); } - public function testGetDefinition(): void + #[Test] + public function getDefinition(): void { /** @var Metadata[] $actual */ $actual = iterator_to_array($this->toolAnalyzer->getMetadata(ToolRequiredParams::class)); @@ -49,7 +52,8 @@ public function testGetDefinition(): void self::assertIsArray($actual[0]->parameters); } - public function testGetDefinitionWithMultiple(): void + #[Test] + public function getDefinitionWithMultiple(): void { $actual = iterator_to_array($this->toolAnalyzer->getMetadata(ToolMultiple::class)); diff --git a/tests/ToolBox/ToolBoxTest.php b/tests/ToolBox/ToolBoxTest.php index 38c904e6..cb6b610d 100644 --- a/tests/ToolBox/ToolBoxTest.php +++ b/tests/ToolBox/ToolBoxTest.php @@ -14,6 +14,7 @@ use PhpLlm\LlmChain\ToolBox\ToolAnalyzer; use PhpLlm\LlmChain\ToolBox\ToolBox; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; @@ -37,6 +38,7 @@ protected function setUp(): void ]); } + #[Test] public function testToolsMap(): void { $actual = $this->toolBox->getMap(); @@ -100,7 +102,8 @@ public function testToolsMap(): void self::assertSame(json_encode($expected), json_encode($actual)); } - public function testExecute(): void + #[Test] + public function execute(): void { $actual = $this->toolBox->execute(new ToolCall('call_1234', 'tool_required_params', ['text' => 'Hello', 'number' => 3])); $expected = 'Hello says "3".';