Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/platform/src/Result/BinaryResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@
final class BinaryResult extends BaseResult
{
public function __construct(
public string $data,
public ?string $mimeType = null,
private string $data,
private ?string $mimeType = null,
) {
}

public function getMimeType(): ?string
{
return $this->mimeType;
}

public function getContent(): string
{
return $this->data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ public function getContent(): string
$result = $converter->convert($rawResult);

$this->assertInstanceOf(BinaryResult::class, $result);
$this->assertSame('audio/mpeg', $result->mimeType);
$this->assertSame('audio/mpeg', $result->getMimeType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function testConvertsInlineDataToBinaryResult()
$result = $converter->convert(new RawHttpResult($httpResponse));
$this->assertInstanceOf(BinaryResult::class, $result);
$this->assertSame('base64EncodedImageData', $result->getContent());
$this->assertSame('image/png', $result->mimeType);
$this->assertSame('image/png', $result->getMimeType());
}

public function testConvertsInlineDataWithoutMimeTypeToBinaryResult()
Expand All @@ -130,6 +130,6 @@ public function testConvertsInlineDataWithoutMimeTypeToBinaryResult()
$result = $converter->convert(new RawHttpResult($httpResponse));
$this->assertInstanceOf(BinaryResult::class, $result);
$this->assertSame('base64EncodedData', $result->getContent());
$this->assertNull($result->mimeType);
$this->assertNull($result->getMimeType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,6 @@ public function testConvertWithTextToImageTask()

$this->assertInstanceOf(BinaryResult::class, $convertedResult);
$this->assertSame($binaryContent, $convertedResult->getContent());
$this->assertSame('image/png', $convertedResult->mimeType);
$this->assertSame('image/png', $convertedResult->getMimeType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function testConvertsInlineDataToBinaryResult()

$this->assertInstanceOf(BinaryResult::class, $result);
$this->assertSame('base64EncodedImageData', $result->getContent());
$this->assertSame('image/png', $result->mimeType);
$this->assertSame('image/png', $result->getMimeType());
}

public function testConvertsInlineDataWithoutMimeTypeToBinaryResult()
Expand Down Expand Up @@ -184,6 +184,6 @@ public function testConvertsInlineDataWithoutMimeTypeToBinaryResult()

$this->assertInstanceOf(BinaryResult::class, $result);
$this->assertSame('base64EncodedData', $result->getContent());
$this->assertNull($result->mimeType);
$this->assertNull($result->getMimeType());
}
}
61 changes: 61 additions & 0 deletions src/platform/tests/Result/BinaryResultTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\AI\Platform\Tests\Result;

use PHPUnit\Framework\TestCase;
use Symfony\AI\Platform\Result\BinaryResult;

final class BinaryResultTest extends TestCase
{
public function testGetContent()
{
$result = new BinaryResult($expected = 'binary data');
$this->assertSame($expected, $result->getContent());
}

public function testGetMimeType()
{
$result = new BinaryResult('binary data', $expected = 'image/png');
$this->assertSame($expected, $result->getMimeType());
}

public function testGetMimeTypeReturnsNullWhenNotSet()
{
$result = new BinaryResult('binary data');
$this->assertNull($result->getMimeType());
}

public function testToBase64()
{
$data = 'Hello World';
$result = new BinaryResult($data);
$this->assertSame(base64_encode($data), $result->toBase64());
}

public function testToDataUri()
{
$data = 'Hello World';
$mimeType = 'text/plain';
$result = new BinaryResult($data, $mimeType);
$this->assertSame('data:text/plain;base64,'.base64_encode($data), $result->toDataUri());
}

public function testToDataUriThrowsExceptionWhenMimeTypeNotSet()
{
$result = new BinaryResult('binary data');

$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Mime type is not set.');

$result->toDataUri();
}
}