44
55namespace App \Tests \Services \InfoProviderSystem \Providers ;
66
7- use App \Services \InfoProviderSystem \Providers \BuerklinProvider ;
87use App \Services \InfoProviderSystem \DTOs \PartDetailDTO ;
98use App \Services \InfoProviderSystem \DTOs \SearchResultDTO ;
9+ use App \Services \InfoProviderSystem \Providers \BuerklinProvider ;
1010use App \Settings \InfoProviderSystem \BuerklinSettings ;
1111use PHPUnit \Framework \TestCase ;
12+ use Psr \Cache \CacheItemInterface ;
13+ use Psr \Cache \CacheItemPoolInterface ;
1214use Symfony \Contracts \HttpClient \HttpClientInterface ;
1315use Symfony \Contracts \HttpClient \ResponseInterface ;
14- use Psr \Cache \CacheItemPoolInterface ;
15- use Psr \Cache \CacheItemInterface ;
1616
1717/**
1818 * Full behavioral test suite for BuerklinProvider.
2121class BuerklinProviderTest extends TestCase
2222{
2323 private HttpClientInterface $ httpClient ;
24- private OAuthTokenManager $ tokenManager ;
2524 private CacheItemPoolInterface $ cache ;
2625 private BuerklinSettings $ settings ;
2726 private BuerklinProvider $ provider ;
@@ -38,13 +37,19 @@ protected function setUp(): void
3837 $ this ->cache = $ this ->createMock (CacheItemPoolInterface::class);
3938 $ this ->cache ->method ('getItem ' )->willReturn ($ cacheItem );
4039
41- $ this ->settings = new BuerklinSettings ();
42- $ this ->settings ->clientId = 'CID ' ;
43- $ this ->settings ->secret = 'SECRET ' ;
44- $ this ->settings ->username = 'USER ' ;
45- $ this ->settings ->password = 'PASS ' ;
46- $ this ->settings ->language = 'en ' ;
47- $ this ->settings ->currency = 'EUR ' ;
40+ // IMPORTANT: Settings must not be instantiated directly (SettingsBundle forbids constructor)
41+ $ ref = new \ReflectionClass (BuerklinSettings::class);
42+ /** @var BuerklinSettings $settings */
43+ $ settings = $ ref ->newInstanceWithoutConstructor ();
44+
45+ $ settings ->clientId = 'CID ' ;
46+ $ settings ->secret = 'SECRET ' ;
47+ $ settings ->username = 'USER ' ;
48+ $ settings ->password = 'PASS ' ;
49+ $ settings ->language = 'en ' ;
50+ $ settings ->currency = 'EUR ' ;
51+
52+ $ this ->settings = $ settings ;
4853
4954 $ this ->provider = new BuerklinProvider (
5055 client: $ this ->httpClient ,
@@ -62,15 +67,12 @@ private function mockApi(string $expectedUrl, array $jsonResponse): void
6267 ->method ('request ' )
6368 ->with (
6469 'GET ' ,
65- $ this ->callback (fn ($ url ) => str_contains ($ url , $ expectedUrl )),
70+ $ this ->callback (fn ($ url ) => str_contains (( string ) $ url , $ expectedUrl )),
6671 $ this ->anything ()
6772 )
6873 ->willReturn ($ response );
6974 }
7075
71- // ---------------------------------------------------------
72- // Test: attributesToParameters
73- // ---------------------------------------------------------
7476 public function testAttributesToParametersParsesUnitsAndValues (): void
7577 {
7678 $ method = new \ReflectionMethod (BuerklinProvider::class, 'attributesToParameters ' );
@@ -117,9 +119,6 @@ public function testAttributesToParametersParsesUnitsAndValues(): void
117119 $ this ->assertNull ($ params [2 ]->unit );
118120 }
119121
120- // ---------------------------------------------------------
121- // Test: complianceToParameters
122- // ---------------------------------------------------------
123122 public function testComplianceParameters (): void
124123 {
125124 $ method = new \ReflectionMethod (BuerklinProvider::class, 'complianceToParameters ' );
@@ -151,9 +150,6 @@ public function testComplianceParameters(): void
151150 $ this ->assertSame ('85411000 ' , $ map ['Customs code ' ]);
152151 }
153152
154- // ---------------------------------------------------------
155- // Test: image handling
156- // ---------------------------------------------------------
157153 public function testImageSelectionPrefersZoomAndDeduplicates (): void
158154 {
159155 $ method = new \ReflectionMethod (BuerklinProvider::class, 'getProductImages ' );
@@ -162,7 +158,7 @@ public function testImageSelectionPrefersZoomAndDeduplicates(): void
162158 $ images = [
163159 ['format ' => 'product ' , 'url ' => '/img/a.webp ' ],
164160 ['format ' => 'zoom ' , 'url ' => '/img/z.webp ' ],
165- ['format ' => 'zoom ' , 'url ' => '/img/z.webp ' ], // dup
161+ ['format ' => 'zoom ' , 'url ' => '/img/z.webp ' ], // duplicate
166162 ['format ' => 'thumbnail ' , 'url ' => '/img/t.webp ' ]
167163 ];
168164
@@ -172,9 +168,6 @@ public function testImageSelectionPrefersZoomAndDeduplicates(): void
172168 $ this ->assertSame ('https://www.buerklin.com/img/z.webp ' , $ results [0 ]->url );
173169 }
174170
175- // ---------------------------------------------------------
176- // Test: footprint extraction
177- // ---------------------------------------------------------
178171 public function testFootprintExtraction (): void
179172 {
180173 $ method = new \ReflectionMethod (BuerklinProvider::class, 'getPartDetail ' );
@@ -203,9 +196,6 @@ public function testFootprintExtraction(): void
203196 $ this ->assertSame ('SOT-23 ' , $ dto ->footprint );
204197 }
205198
206- // ---------------------------------------------------------
207- // Test: price formatting
208- // ---------------------------------------------------------
209199 public function testPriceFormatting (): void
210200 {
211201 $ detailPrice = [
@@ -222,16 +212,11 @@ public function testPriceFormatting(): void
222212 $ vendorInfo = $ method ->invoke ($ this ->provider , 'SKU1 ' , 'https://x ' , $ detailPrice );
223213
224214 $ price = $ vendorInfo [0 ]->prices [0 ];
225-
226215 $ this ->assertSame ('0.0885 ' , $ price ->price );
227216 }
228217
229- // ---------------------------------------------------------
230- // Test: batch search produces SearchResultDTO[]
231- // ---------------------------------------------------------
232218 public function testBatchSearchReturnsSearchResultDTO (): void
233219 {
234- // Mock searchByKeyword to avoid HTTP
235220 $ mockDetail = new PartDetailDTO (
236221 provider_key: 'buerklin ' ,
237222 provider_id: 'TESTID ' ,
@@ -242,7 +227,6 @@ public function testBatchSearchReturnsSearchResultDTO(): void
242227 $ provider = $ this ->getMockBuilder (BuerklinProvider::class)
243228 ->setConstructorArgs ([
244229 $ this ->httpClient ,
245- $ this ->tokenManager ,
246230 $ this ->cache ,
247231 $ this ->settings
248232 ])
@@ -254,13 +238,12 @@ public function testBatchSearchReturnsSearchResultDTO(): void
254238 $ result = $ provider ->searchByKeywordsBatch (['ABC ' ]);
255239
256240 $ this ->assertArrayHasKey ('ABC ' , $ result );
241+ $ this ->assertIsArray ($ result ['ABC ' ]);
242+ $ this ->assertCount (1 , $ result ['ABC ' ]);
257243 $ this ->assertInstanceOf (SearchResultDTO::class, $ result ['ABC ' ][0 ]);
258244 $ this ->assertSame ('Zener ' , $ result ['ABC ' ][0 ]->name );
259245 }
260246
261- // ---------------------------------------------------------
262- // Test: convertPartDetailToSearchResult
263- // ---------------------------------------------------------
264247 public function testConvertPartDetailToSearchResult (): void
265248 {
266249 $ detail = new PartDetailDTO (
0 commit comments