|
12 | 12 | namespace Symfony\AI\Platform\Tests\Bridge\Google\Contract; |
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\Attributes\CoversClass; |
| 15 | +use PHPUnit\Framework\Attributes\DataProvider; |
15 | 16 | use PHPUnit\Framework\Attributes\Small; |
16 | 17 | use PHPUnit\Framework\Attributes\Test; |
17 | 18 | use PHPUnit\Framework\Attributes\UsesClass; |
18 | 19 | use PHPUnit\Framework\TestCase; |
19 | 20 | use Symfony\AI\Platform\Bridge\Google\Contract\UserMessageNormalizer; |
20 | 21 | use Symfony\AI\Platform\Bridge\Google\Gemini; |
21 | 22 | use Symfony\AI\Platform\Contract; |
| 23 | +use Symfony\AI\Platform\Message\Content\Audio; |
| 24 | +use Symfony\AI\Platform\Message\Content\Document; |
22 | 25 | use Symfony\AI\Platform\Message\Content\File; |
23 | 26 | use Symfony\AI\Platform\Message\Content\Image; |
24 | 27 | use Symfony\AI\Platform\Message\Content\Text; |
|
30 | 33 | #[UsesClass(UserMessage::class)] |
31 | 34 | #[UsesClass(Text::class)] |
32 | 35 | #[UsesClass(File::class)] |
| 36 | +#[UsesClass(Image::class)] |
| 37 | +#[UsesClass(Document::class)] |
| 38 | +#[UsesClass(Audio::class)] |
33 | 39 | final class UserMessageNormalizerTest extends TestCase |
34 | 40 | { |
35 | 41 | #[Test] |
@@ -62,22 +68,32 @@ public function normalizeTextContent(): void |
62 | 68 | self::assertSame([['text' => 'Write a story about a magic backpack.']], $normalized); |
63 | 69 | } |
64 | 70 |
|
| 71 | + #[DataProvider('binaryContentProvider')] |
65 | 72 | #[Test] |
66 | | - public function normalizeImageContent(): void |
| 73 | + public function normalizeBinaryContent(File $content, string $expectedMimeType, string $expectedPrefix): void |
67 | 74 | { |
68 | 75 | $normalizer = new UserMessageNormalizer(); |
69 | | - $imageContent = Image::fromFile(\dirname(__DIR__, 6).'/fixtures/image.jpg'); |
70 | | - $message = new UserMessage(new Text('Tell me about this instrument'), $imageContent); |
| 76 | + $message = new UserMessage(new Text('Tell me about this instrument'), $content); |
71 | 77 |
|
72 | 78 | $normalized = $normalizer->normalize($message); |
73 | 79 |
|
74 | 80 | self::assertCount(2, $normalized); |
75 | 81 | self::assertSame(['text' => 'Tell me about this instrument'], $normalized[0]); |
76 | 82 | self::assertArrayHasKey('inline_data', $normalized[1]); |
77 | | - self::assertSame('image/jpeg', $normalized[1]['inline_data']['mime_type']); |
| 83 | + self::assertSame($expectedMimeType, $normalized[1]['inline_data']['mime_type']); |
78 | 84 | self::assertNotEmpty($normalized[1]['inline_data']['data']); |
79 | 85 |
|
80 | | - // Verify that the base64 data string starts correctly for a JPEG |
81 | | - self::assertStringStartsWith('/9j/', $normalized[1]['inline_data']['data']); |
| 86 | + // Verify that the base64 data string starts correctly |
| 87 | + self::assertStringStartsWith($expectedPrefix, $normalized[1]['inline_data']['data']); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * @return iterable<string, array{0: File, 1: string, 2: string}> |
| 92 | + */ |
| 93 | + public static function binaryContentProvider(): iterable |
| 94 | + { |
| 95 | + yield 'image' => [Image::fromFile(\dirname(__DIR__, 6).'/fixtures/image.jpg'), 'image/jpeg', '/9j/']; |
| 96 | + yield 'document' => [Document::fromFile(\dirname(__DIR__, 6).'/fixtures/document.pdf'), 'application/pdf', 'JVBE']; |
| 97 | + yield 'audio' => [Audio::fromFile(\dirname(__DIR__, 6).'/fixtures/audio.mp3'), 'audio/mpeg', 'SUQz']; |
82 | 98 | } |
83 | 99 | } |
0 commit comments