Testing feature-service consumers
Testing
Unit tests
Run feature service tests
# Run all unit tests
Build/Scripts/runTests.sh -s unit
# Alternative: Via Composer script
composer ci:test:php:unit
Copied!
Mocking services
Example: Mocking feature services in tests
use Netresearch\NrLlm\Service\Feature\VisionServiceInterface;
use PHPUnit\Framework\TestCase;
class YourServiceTest extends TestCase
{
public function testImageEnhancement(): void
{
$visionMock = $this->createMock(VisionServiceInterface::class);
$visionMock->method('generateAltText')
->willReturn('Test alt text');
$service = new YourService($visionMock);
$result = $service->enhanceImage('https://example.com/test.jpg');
$this->assertEquals('Test alt text', $result['alt']);
}
}
Copied!