|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 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\Message\Content; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\AI\Platform\Message\Content\File; |
| 16 | + |
| 17 | +final class FileTest extends TestCase |
| 18 | +{ |
| 19 | + public function testConstructWithValidDataUrl() |
| 20 | + { |
| 21 | + $image = File::fromDataUrl('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABKklEQVR42mNk+A8AAwMhIv9n+X'); |
| 22 | + |
| 23 | + $this->assertStringStartsWith('data:image/png;base64', $image->asDataUrl()); |
| 24 | + } |
| 25 | + |
| 26 | + public function testWithValidFile() |
| 27 | + { |
| 28 | + $image = File::fromFile(\dirname(__DIR__, 5).'/fixtures/image.jpg'); |
| 29 | + |
| 30 | + $this->assertStringStartsWith('data:image/jpeg;base64,', $image->asDataUrl()); |
| 31 | + } |
| 32 | + |
| 33 | + public function testFromBinaryWithInvalidFile() |
| 34 | + { |
| 35 | + $this->expectExceptionMessage('The file "foo.jpg" does not exist or is not readable.'); |
| 36 | + |
| 37 | + File::fromFile('foo.jpg'); |
| 38 | + } |
| 39 | + |
| 40 | + public function testCanBeSerialized() |
| 41 | + { |
| 42 | + $audio = File::fromFile(\dirname(__DIR__, 5).'/fixtures/image.jpg'); |
| 43 | + |
| 44 | + $serialized = serialize($audio); |
| 45 | + $unserialized = unserialize($serialized); |
| 46 | + $this->assertInstanceOf(File::class, $unserialized); |
| 47 | + $this->assertSame('image.jpg', $unserialized->getFilename()); |
| 48 | + } |
| 49 | +} |
0 commit comments