-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpLlm\LlmChain\Tests\Response; | ||
|
||
use PhpLlm\LlmChain\Exception\InvalidArgumentException; | ||
use PhpLlm\LlmChain\Response\Choice; | ||
use PhpLlm\LlmChain\Response\ChoiceResponse; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\Small; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\Attributes\UsesClass; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(ChoiceResponse::class)] | ||
#[UsesClass(Choice::class)] | ||
#[Small] | ||
final class ChoiceResponseTest extends TestCase | ||
{ | ||
#[Test] | ||
public function choiceResponseCreation(): void | ||
{ | ||
$choice1 = new Choice('choice1'); | ||
$choice2 = new Choice(null); | ||
$choice3 = new Choice('choice3'); | ||
$response = new ChoiceResponse($choice1, $choice2, $choice3); | ||
|
||
self::assertCount(3, $response->getContent()); | ||
self::assertSame('choice1', $response->getContent()[0]->getContent()); | ||
self::assertNull($response->getContent()[1]->getContent()); | ||
self::assertSame('choice3', $response->getContent()[2]->getContent()); | ||
} | ||
|
||
#[Test] | ||
public function choiceResponseWithNoChoices(): void | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage('Response must have at least one choice.'); | ||
|
||
new ChoiceResponse(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpLlm\LlmChain\Tests\Response; | ||
|
||
use PhpLlm\LlmChain\Response\StreamResponse; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\Small; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(StreamResponse::class)] | ||
#[Small] | ||
final class StreamResponseTest extends TestCase | ||
{ | ||
#[Test] | ||
public function getContent(): void | ||
{ | ||
$generator = (function () { | ||
yield 'data1'; | ||
yield 'data2'; | ||
})(); | ||
|
||
$response = new StreamResponse($generator); | ||
self::assertInstanceOf(\Generator::class, $response->getContent()); | ||
|
||
$content = iterator_to_array($response->getContent()); | ||
|
||
self::assertCount(2, $content); | ||
self::assertSame('data1', $content[0]); | ||
self::assertSame('data2', $content[1]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpLlm\LlmChain\Tests\Response; | ||
|
||
use PhpLlm\LlmChain\Response\StructuredResponse; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\Small; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(StructuredResponse::class)] | ||
#[Small] | ||
final class StructuredResponseTest extends TestCase | ||
{ | ||
#[Test] | ||
public function getContentWithArray(): void | ||
{ | ||
$response = new StructuredResponse($expected = ['foo' => 'bar', 'baz' => ['qux']]); | ||
self::assertSame($expected, $response->getContent()); | ||
} | ||
|
||
#[Test] | ||
public function getContentWithObject(): void | ||
{ | ||
$response = new StructuredResponse($expected = (object) ['foo' => 'bar', 'baz' => ['qux']]); | ||
self::assertSame($expected, $response->getContent()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpLlm\LlmChain\Tests\Response; | ||
|
||
use PhpLlm\LlmChain\Response\TextResponse; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\Small; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(TextResponse::class)] | ||
#[Small] | ||
final class TextResponseTest extends TestCase | ||
{ | ||
#[Test] | ||
public function getContent(): void | ||
{ | ||
$response = new TextResponse($expected = 'foo'); | ||
self::assertSame($expected, $response->getContent()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpLlm\LlmChain\Tests\Response; | ||
|
||
use PhpLlm\LlmChain\Exception\InvalidArgumentException; | ||
use PhpLlm\LlmChain\Response\ToolCall; | ||
use PhpLlm\LlmChain\Response\ToolCallResponse; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\Small; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\Attributes\UsesClass; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(ToolCallResponse::class)] | ||
#[UsesClass(ToolCall::class)] | ||
#[Small] | ||
final class TollCallResponseTest extends TestCase | ||
{ | ||
#[Test] | ||
public function throwsIfNoToolCall(): void | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage('Response must have at least one tool call.'); | ||
|
||
new ToolCallResponse(); | ||
} | ||
|
||
#[Test] | ||
public function getContent(): void | ||
{ | ||
$response = new ToolCallResponse($toolCall = new ToolCall('ID', 'name', ['foo' => 'bar'])); | ||
self::assertSame([$toolCall], $response->getContent()); | ||
} | ||
} |