|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\AI\Platform\Tests\Bridge\Perplexity\Contract; |
| 13 | + |
| 14 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 15 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 16 | +use PHPUnit\Framework\Attributes\Medium; |
| 17 | +use PHPUnit\Framework\TestCase; |
| 18 | +use Symfony\AI\Platform\Bridge\Perplexity\Contract\FileUrlNormalizer; |
| 19 | +use Symfony\AI\Platform\Bridge\Perplexity\Perplexity; |
| 20 | +use Symfony\AI\Platform\Contract; |
| 21 | +use Symfony\AI\Platform\Contract\Normalizer\Message\MessageBagNormalizer; |
| 22 | +use Symfony\AI\Platform\Message\Content\DocumentUrl; |
| 23 | + |
| 24 | +#[Medium] |
| 25 | +#[CoversClass(FileUrlNormalizer::class)] |
| 26 | +#[CoversClass(MessageBagNormalizer::class)] |
| 27 | +final class FileUrlNormalizerTest extends TestCase |
| 28 | +{ |
| 29 | + public function testSupportsNormalization() |
| 30 | + { |
| 31 | + $normalizer = new FileUrlNormalizer(); |
| 32 | + |
| 33 | + $this->assertTrue($normalizer->supportsNormalization(new DocumentUrl(\dirname(__DIR__, 6).'/fixtures/not-a-document.pdf'), context: [ |
| 34 | + Contract::CONTEXT_MODEL => new Perplexity(), |
| 35 | + ])); |
| 36 | + $this->assertFalse($normalizer->supportsNormalization('not a document')); |
| 37 | + } |
| 38 | + |
| 39 | + public function testGetSupportedTypes() |
| 40 | + { |
| 41 | + $normalizer = new FileUrlNormalizer(); |
| 42 | + |
| 43 | + $expected = [ |
| 44 | + DocumentUrl::class => true, |
| 45 | + ]; |
| 46 | + |
| 47 | + $this->assertSame($expected, $normalizer->getSupportedTypes(null)); |
| 48 | + } |
| 49 | + |
| 50 | + #[DataProvider('normalizeDataProvider')] |
| 51 | + public function testNormalize(DocumentUrl $document, array $expected) |
| 52 | + { |
| 53 | + $normalizer = new FileUrlNormalizer(); |
| 54 | + |
| 55 | + $normalized = $normalizer->normalize($document); |
| 56 | + |
| 57 | + $this->assertEquals($expected, $normalized); |
| 58 | + } |
| 59 | + |
| 60 | + public static function normalizeDataProvider(): iterable |
| 61 | + { |
| 62 | + yield 'document from file url' => [ |
| 63 | + new DocumentUrl(\dirname(__DIR__, 6).'/fixtures/document.pdf'), |
| 64 | + [ |
| 65 | + 'type' => 'file_url', |
| 66 | + 'file_url' => [ |
| 67 | + 'url' => \dirname(__DIR__, 6).'/fixtures/document.pdf', |
| 68 | + ], |
| 69 | + ], |
| 70 | + ]; |
| 71 | + } |
| 72 | +} |
0 commit comments