From 34d284b1c45ecfffb9041153231b68ffde591e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Mon, 22 Sep 2025 00:05:49 +0200 Subject: [PATCH] Do not test against real LCSC provider... --- .../Providers/EmptyProvider.php | 76 +++++++++++++++++++ .../BulkInfoProviderImportControllerTest.php | 4 +- 2 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 src/Services/InfoProviderSystem/Providers/EmptyProvider.php diff --git a/src/Services/InfoProviderSystem/Providers/EmptyProvider.php b/src/Services/InfoProviderSystem/Providers/EmptyProvider.php new file mode 100644 index 00000000..e0de9772 --- /dev/null +++ b/src/Services/InfoProviderSystem/Providers/EmptyProvider.php @@ -0,0 +1,76 @@ +. + */ + +declare(strict_types=1); + + +namespace App\Services\InfoProviderSystem\Providers; + +use App\Services\InfoProviderSystem\DTOs\FileDTO; +use App\Services\InfoProviderSystem\DTOs\PartDetailDTO; +use App\Services\InfoProviderSystem\DTOs\SearchResultDTO; +use Symfony\Component\DependencyInjection\Attribute\When; + +/** + * This is a provider, which is used during tests. It always returns no results. + */ +#[When(env: 'test')] +class EmptyProvider implements InfoProviderInterface +{ + public function getProviderInfo(): array + { + return [ + 'name' => 'Empty Provider', + 'description' => 'This is a test provider', + //'url' => 'https://example.com', + 'disabled_help' => 'This provider is disabled for testing purposes' + ]; + } + + public function getProviderKey(): string + { + return 'empty'; + } + + public function isActive(): bool + { + return true; + } + + public function searchByKeyword(string $keyword): array + { + return [ + + ]; + } + + public function getCapabilities(): array + { + return [ + ProviderCapabilities::BASIC, + ProviderCapabilities::FOOTPRINT, + ]; + } + + public function getDetails(string $id): PartDetailDTO + { + throw new \RuntimeException('No part details available'); + } +} diff --git a/tests/Controller/BulkInfoProviderImportControllerTest.php b/tests/Controller/BulkInfoProviderImportControllerTest.php index 47275b9f..e71a5fa2 100644 --- a/tests/Controller/BulkInfoProviderImportControllerTest.php +++ b/tests/Controller/BulkInfoProviderImportControllerTest.php @@ -761,12 +761,12 @@ class BulkInfoProviderImportControllerTest extends WebTestCase // Create field mappings with multiple keywords $fieldMappings = [ - new \App\Services\InfoProviderSystem\DTOs\BulkSearchFieldMappingDTO('name', ['lcsc'], 1) + new \App\Services\InfoProviderSystem\DTOs\BulkSearchFieldMappingDTO('empty', ['test'], 1) ]; // The service should be able to process the request and throw an exception when no results are found try { - $bulkService->performBulkSearch([$part], $fieldMappings, false); + $response = $bulkService->performBulkSearch([$part], $fieldMappings, false); $this->fail('Expected RuntimeException to be thrown when no search results are found'); } catch (\RuntimeException $e) { $this->assertStringContainsString('No search results found', $e->getMessage());