45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace App\Tests\Unit\Infrastructure\AI\Agent;
|
||
|
|
|
||
|
|
use App\Infrastructure\AI\Agent\OllamaVisionAgent;
|
||
|
|
use App\Infrastructure\AI\OllamaClientInterface;
|
||
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
||
|
|
use PHPUnit\Framework\TestCase;
|
||
|
|
|
||
|
|
final class OllamaVisionAgentTest extends TestCase
|
||
|
|
{
|
||
|
|
private OllamaClientInterface&MockObject $ollama;
|
||
|
|
private OllamaVisionAgent $agent;
|
||
|
|
|
||
|
|
protected function setUp(): void
|
||
|
|
{
|
||
|
|
$this->ollama = $this->createMock(OllamaClientInterface::class);
|
||
|
|
$this->agent = new OllamaVisionAgent($this->ollama, 'llava');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function testParsesModelAndSerialFromResponse(): void
|
||
|
|
{
|
||
|
|
$this->ollama->method('generateWithImage')
|
||
|
|
->willReturn("MODEL: Dell Latitude 5520\nSERIAL: ABC12345");
|
||
|
|
|
||
|
|
$result = $this->agent->analyze('/tmp/photo.jpg');
|
||
|
|
|
||
|
|
self::assertSame('Dell Latitude 5520', $result['model']);
|
||
|
|
self::assertSame('ABC12345', $result['serial']);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function testReturnsEmptyStringsWhenNotFound(): void
|
||
|
|
{
|
||
|
|
$this->ollama->method('generateWithImage')
|
||
|
|
->willReturn('I cannot read the nameplate clearly.');
|
||
|
|
|
||
|
|
$result = $this->agent->analyze('/tmp/photo.jpg');
|
||
|
|
|
||
|
|
self::assertSame('', $result['model']);
|
||
|
|
self::assertSame('', $result['serial']);
|
||
|
|
}
|
||
|
|
}
|