|
2 | 2 |
|
3 | 3 | declare(strict_types=1);
|
4 | 4 |
|
5 |
| -namespace PhpLlm\LlmChain\Tests\Chain\ToolBox; |
| 5 | +namespace PhpLlm\LlmChain\Tests\Chain\ToolBox\MetadataFactory; |
6 | 6 |
|
7 | 7 | use PhpLlm\LlmChain\Chain\JsonSchema\DescriptionParser;
|
8 | 8 | use PhpLlm\LlmChain\Chain\JsonSchema\Factory;
|
9 | 9 | use PhpLlm\LlmChain\Chain\ToolBox\Attribute\AsTool;
|
10 | 10 | use PhpLlm\LlmChain\Chain\ToolBox\Exception\ToolConfigurationException;
|
11 | 11 | use PhpLlm\LlmChain\Chain\ToolBox\Metadata;
|
12 |
| -use PhpLlm\LlmChain\Chain\ToolBox\ToolAnalyzer; |
| 12 | +use PhpLlm\LlmChain\Chain\ToolBox\MetadataFactory\ReflectionFactory; |
13 | 13 | use PhpLlm\LlmChain\Tests\Fixture\Tool\ToolMultiple;
|
14 | 14 | use PhpLlm\LlmChain\Tests\Fixture\Tool\ToolRequiredParams;
|
15 | 15 | use PhpLlm\LlmChain\Tests\Fixture\Tool\ToolWrong;
|
|
18 | 18 | use PHPUnit\Framework\Attributes\UsesClass;
|
19 | 19 | use PHPUnit\Framework\TestCase;
|
20 | 20 |
|
21 |
| -#[CoversClass(ToolAnalyzer::class)] |
| 21 | +#[CoversClass(ReflectionFactory::class)] |
22 | 22 | #[UsesClass(AsTool::class)]
|
23 | 23 | #[UsesClass(Metadata::class)]
|
24 | 24 | #[UsesClass(Factory::class)]
|
25 | 25 | #[UsesClass(DescriptionParser::class)]
|
26 | 26 | #[UsesClass(ToolConfigurationException::class)]
|
27 |
| -final class ToolAnalyzerTest extends TestCase |
| 27 | +final class ReflectionFactoryTest extends TestCase |
28 | 28 | {
|
29 |
| - private ToolAnalyzer $toolAnalyzer; |
| 29 | + private ReflectionFactory $factory; |
30 | 30 |
|
31 | 31 | protected function setUp(): void
|
32 | 32 | {
|
33 |
| - $this->toolAnalyzer = new ToolAnalyzer(); |
| 33 | + $this->factory = new ReflectionFactory(); |
| 34 | + } |
| 35 | + |
| 36 | + #[Test] |
| 37 | + public function invalidReferenceNonExistingClass(): void |
| 38 | + { |
| 39 | + $this->expectException(ToolConfigurationException::class); |
| 40 | + iterator_to_array($this->factory->getMetadata('invalid')); |
| 41 | + } |
| 42 | + |
| 43 | + #[Test] |
| 44 | + public function invalidReferenceNonInteger(): void |
| 45 | + { |
| 46 | + $this->expectException(ToolConfigurationException::class); |
| 47 | + iterator_to_array($this->factory->getMetadata(1234)); |
| 48 | + } |
| 49 | + |
| 50 | + #[Test] |
| 51 | + public function invalidReferenceCallable(): void |
| 52 | + { |
| 53 | + $this->expectException(ToolConfigurationException::class); |
| 54 | + iterator_to_array($this->factory->getMetadata(fn () => null)); |
34 | 55 | }
|
35 | 56 |
|
36 | 57 | #[Test]
|
37 | 58 | public function withoutAttribute(): void
|
38 | 59 | {
|
39 | 60 | $this->expectException(ToolConfigurationException::class);
|
40 |
| - iterator_to_array($this->toolAnalyzer->getMetadata(ToolWrong::class)); |
| 61 | + iterator_to_array($this->factory->getMetadata(ToolWrong::class)); |
41 | 62 | }
|
42 | 63 |
|
43 | 64 | #[Test]
|
44 | 65 | public function getDefinition(): void
|
45 | 66 | {
|
46 | 67 | /** @var Metadata[] $metadatas */
|
47 |
| - $metadatas = iterator_to_array($this->toolAnalyzer->getMetadata(ToolRequiredParams::class)); |
| 68 | + $metadatas = iterator_to_array($this->factory->getMetadata(ToolRequiredParams::class)); |
48 | 69 |
|
49 | 70 | self::assertToolConfiguration(
|
50 | 71 | metadata: $metadatas[0],
|
@@ -73,7 +94,7 @@ className: ToolRequiredParams::class,
|
73 | 94 | #[Test]
|
74 | 95 | public function getDefinitionWithMultiple(): void
|
75 | 96 | {
|
76 |
| - $metadatas = iterator_to_array($this->toolAnalyzer->getMetadata(ToolMultiple::class)); |
| 97 | + $metadatas = iterator_to_array($this->factory->getMetadata(ToolMultiple::class)); |
77 | 98 |
|
78 | 99 | self::assertCount(2, $metadatas);
|
79 | 100 |
|
|
0 commit comments