Reworked info provider system to merge all provider metadata into a unified DTO

This commit is contained in:
Jan Böhmer 2026-07-26 13:55:27 +02:00
parent 661cc5a052
commit 071ffe322d
39 changed files with 412 additions and 533 deletions

View file

@ -24,6 +24,7 @@ namespace App\Tests\Services\InfoProviderSystem\DTOs;
use App\Services\InfoProviderSystem\Providers\InfoProviderInterface;
use App\Services\InfoProviderSystem\DTOs\BulkSearchFieldMappingDTO;
use App\Services\InfoProviderSystem\DTOs\ProviderInfoDTO;
use PHPUnit\Framework\TestCase;
final class BulkSearchFieldMappingDTOTest extends TestCase
@ -32,7 +33,7 @@ final class BulkSearchFieldMappingDTOTest extends TestCase
public function testProviderInstanceNormalization(): void
{
$mockProvider = $this->createMock(InfoProviderInterface::class);
$mockProvider->method('getProviderKey')->willReturn('mock_provider');
$mockProvider->method('getProviderInfo')->willReturn(new ProviderInfoDTO(key: 'mock_provider', name: 'mock_provider'));
$fieldMapping = new BulkSearchFieldMappingDTO(field: 'mpn', providers: ['provider1', $mockProvider], priority: 5);
$this->assertSame(['provider1', 'mock_provider'], $fieldMapping->providers);

View file

@ -22,6 +22,7 @@ declare(strict_types=1);
*/
namespace App\Tests\Services\InfoProviderSystem;
use App\Services\InfoProviderSystem\DTOs\ProviderInfoDTO;
use App\Services\InfoProviderSystem\ProviderRegistry;
use App\Services\InfoProviderSystem\Providers\InfoProviderInterface;
use App\Services\InfoProviderSystem\Providers\URLHandlerInfoProviderInterface;
@ -46,7 +47,7 @@ final class ProviderRegistryTest extends TestCase
public function getMockProvider(string $key, bool $active = true): InfoProviderInterface
{
$mock = $this->createMockForIntersectionOfInterfaces([InfoProviderInterface::class, URLHandlerInfoProviderInterface::class]);
$mock->method('getProviderKey')->willReturn($key);
$mock->method('getProviderInfo')->willReturn(new ProviderInfoDTO(key: $key, name: $key));
$mock->method('isActive')->willReturn($active);
$mock->method('getHandledDomains')->willReturn(["$key.com", "test.$key.de"]);

View file

@ -27,6 +27,7 @@ use App\Services\InfoProviderSystem\DTOs\FileDTO;
use App\Services\InfoProviderSystem\DTOs\ParameterDTO;
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
use App\Services\InfoProviderSystem\DTOs\PriceDTO;
use App\Services\InfoProviderSystem\DTOs\ProviderInfoDTO;
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
use App\Services\InfoProviderSystem\Providers\LCSCProvider;
use App\Services\InfoProviderSystem\Providers\ProviderCapabilities;
@ -56,18 +57,10 @@ final class LCSCProviderTest extends TestCase
{
$info = $this->provider->getProviderInfo();
$this->assertIsArray($info);
$this->assertArrayHasKey('name', $info);
$this->assertArrayHasKey('description', $info);
$this->assertArrayHasKey('url', $info);
$this->assertArrayHasKey('disabled_help', $info);
$this->assertEquals('LCSC', $info['name']);
$this->assertEquals('https://www.lcsc.com/', $info['url']);
}
public function testGetProviderKey(): void
{
$this->assertSame('lcsc', $this->provider->getProviderKey());
$this->assertInstanceOf(ProviderInfoDTO::class, $info);
$this->assertSame('lcsc', $info->key);
$this->assertEquals('LCSC', $info->name);
$this->assertEquals('https://www.lcsc.com/', $info->url);
}
public function testIsActiveWhenEnabled(): void
@ -86,7 +79,7 @@ final class LCSCProviderTest extends TestCase
public function testGetCapabilities(): void
{
$capabilities = $this->provider->getCapabilities();
$capabilities = $this->provider->getProviderInfo()->capabilities;
$this->assertIsArray($capabilities);
$this->assertContains(ProviderCapabilities::BASIC, $capabilities);

View file

@ -24,6 +24,7 @@ namespace App\Tests\Services\InfoProviderSystem\Providers;
use App\Entity\Parts\ManufacturingStatus;
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
use App\Services\InfoProviderSystem\DTOs\ProviderInfoDTO;
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
use App\Services\InfoProviderSystem\DTOs\SearchResultDTO;
use App\Services\InfoProviderSystem\Providers\ProviderCapabilities;
@ -212,17 +213,10 @@ final class TMEProviderTest extends TestCase
{
$info = $this->provider->getProviderInfo();
$this->assertIsArray($info);
$this->assertArrayHasKey('name', $info);
$this->assertArrayHasKey('description', $info);
$this->assertArrayHasKey('url', $info);
$this->assertEquals('TME', $info['name']);
$this->assertEquals('https://tme.eu/', $info['url']);
}
public function testGetProviderKey(): void
{
$this->assertSame('tme', $this->provider->getProviderKey());
$this->assertInstanceOf(ProviderInfoDTO::class, $info);
$this->assertSame('tme', $info->key);
$this->assertEquals('TME', $info->name);
$this->assertEquals('https://tme.eu/', $info->url);
}
public function testIsActiveWithCredentials(): void
@ -239,7 +233,7 @@ final class TMEProviderTest extends TestCase
public function testGetCapabilities(): void
{
$capabilities = $this->provider->getCapabilities();
$capabilities = $this->provider->getProviderInfo()->capabilities;
$this->assertIsArray($capabilities);
$this->assertContains(ProviderCapabilities::BASIC, $capabilities);