Ran rector and made tests final

This commit is contained in:
Jan Böhmer 2026-02-14 23:32:43 +01:00
parent 43d72faf48
commit b21d294cf8
162 changed files with 407 additions and 393 deletions

View file

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Tests\Services\InfoProviderSystem\Providers;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
use App\Services\InfoProviderSystem\DTOs\SearchResultDTO;
use App\Services\InfoProviderSystem\Providers\BuerklinProvider;
@ -18,7 +19,7 @@ use Symfony\Contracts\HttpClient\ResponseInterface;
* Full behavioral test suite for BuerklinProvider.
* Includes parameter parsing, compliance parsing, images, prices and batch mode.
*/
class BuerklinProviderTest extends TestCase
final class BuerklinProviderTest extends TestCase
{
private HttpClientInterface $httpClient;
private CacheItemPoolInterface $cache;
@ -108,14 +109,14 @@ class BuerklinProviderTest extends TestCase
$this->assertSame('Zener voltage', $params[0]->name);
$this->assertNull($params[0]->value_text);
$this->assertSame(12.0, $params[0]->value_typ);
$this->assertEqualsWithDelta(12.0, $params[0]->value_typ, PHP_FLOAT_EPSILON);
$this->assertNull($params[0]->value_min);
$this->assertNull($params[0]->value_max);
$this->assertSame('V', $params[0]->unit);
$this->assertSame('Length', $params[1]->name);
$this->assertNull($params[1]->value_text);
$this->assertSame(2.9, $params[1]->value_typ);
$this->assertEqualsWithDelta(2.9, $params[1]->value_typ, PHP_FLOAT_EPSILON);
$this->assertSame('mm', $params[1]->unit);
$this->assertSame('Assembly', $params[2]->name);
@ -273,75 +274,70 @@ class BuerklinProviderTest extends TestCase
$this->assertSame(['buerklin.com'], $this->provider->getHandledDomains());
}
/**
* @dataProvider buerklinIdFromUrlProvider
*/
#[DataProvider('buerklinIdFromUrlProvider')]
public function testGetIDFromURLExtractsId(string $url, ?string $expected): void
{
$this->assertSame($expected, $this->provider->getIDFromURL($url));
}
public static function buerklinIdFromUrlProvider(): array
public static function buerklinIdFromUrlProvider(): \Iterator
{
return [
'de long path' => [
'https://www.buerklin.com/de/p/bkl-electronic/niedervoltsteckverbinder/072341-l/40F1332/',
'40F1332',
],
'de short path' => [
'https://www.buerklin.com/de/p/40F1332/',
'40F1332',
],
'en long path' => [
'https://www.buerklin.com/en/p/bkl-electronic/dc-connectors/072341-l/40F1332/',
'40F1332',
],
'en short path' => [
'https://www.buerklin.com/en/p/40F1332/',
'40F1332',
],
'fragment should be ignored' => [
'https://www.buerklin.com/de/p/bkl-electronic/niedervoltsteckverbinder/072341-l/40F1332/#download',
'40F1332',
],
'no trailing slash' => [
'https://www.buerklin.com/en/p/40F1332',
'40F1332',
],
'query should be ignored' => [
'https://www.buerklin.com/en/p/40F1332/?foo=bar',
'40F1332',
],
'query and fragment should be ignored' => [
'https://www.buerklin.com/en/p/40F1332/?foo=bar#download',
'40F1332',
],
// Negative cases
'not a product url (no /p/ segment)' => [
'https://www.buerklin.com/de/impressum/',
null,
],
'path contains "p" but not "/p/"' => [
'https://www.buerklin.com/de/help/price/',
null,
],
'ends with /p/ (no id)' => [
'https://www.buerklin.com/de/p/',
null,
],
'ends with /p (no trailing slash)' => [
'https://www.buerklin.com/de/p',
null,
],
'empty string' => [
'',
null,
],
'not a url string' => [
'not a url',
null,
],
yield 'de long path' => [
'https://www.buerklin.com/de/p/bkl-electronic/niedervoltsteckverbinder/072341-l/40F1332/',
'40F1332',
];
yield 'de short path' => [
'https://www.buerklin.com/de/p/40F1332/',
'40F1332',
];
yield 'en long path' => [
'https://www.buerklin.com/en/p/bkl-electronic/dc-connectors/072341-l/40F1332/',
'40F1332',
];
yield 'en short path' => [
'https://www.buerklin.com/en/p/40F1332/',
'40F1332',
];
yield 'fragment should be ignored' => [
'https://www.buerklin.com/de/p/bkl-electronic/niedervoltsteckverbinder/072341-l/40F1332/#download',
'40F1332',
];
yield 'no trailing slash' => [
'https://www.buerklin.com/en/p/40F1332',
'40F1332',
];
yield 'query should be ignored' => [
'https://www.buerklin.com/en/p/40F1332/?foo=bar',
'40F1332',
];
yield 'query and fragment should be ignored' => [
'https://www.buerklin.com/en/p/40F1332/?foo=bar#download',
'40F1332',
];
// Negative cases
yield 'not a product url (no /p/ segment)' => [
'https://www.buerklin.com/de/impressum/',
null,
];
yield 'path contains "p" but not "/p/"' => [
'https://www.buerklin.com/de/help/price/',
null,
];
yield 'ends with /p/ (no id)' => [
'https://www.buerklin.com/de/p/',
null,
];
yield 'ends with /p (no trailing slash)' => [
'https://www.buerklin.com/de/p',
null,
];
yield 'empty string' => [
'',
null,
];
yield 'not a url string' => [
'not a url',
null,
];
}
}

View file

@ -37,7 +37,7 @@ use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\Response\MockResponse;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class LCSCProviderTest extends TestCase
final class LCSCProviderTest extends TestCase
{
private LCSCSettings $settings;
private LCSCProvider $provider;
@ -67,7 +67,7 @@ class LCSCProviderTest extends TestCase
public function testGetProviderKey(): void
{
$this->assertEquals('lcsc', $this->provider->getProviderKey());
$this->assertSame('lcsc', $this->provider->getProviderKey());
}
public function testIsActiveWhenEnabled(): void
@ -125,8 +125,8 @@ class LCSCProviderTest extends TestCase
$this->assertIsArray($results);
$this->assertCount(1, $results);
$this->assertInstanceOf(PartDetailDTO::class, $results[0]);
$this->assertEquals('C123456', $results[0]->provider_id);
$this->assertEquals('Test Component', $results[0]->name);
$this->assertSame('C123456', $results[0]->provider_id);
$this->assertSame('Test Component', $results[0]->name);
}
public function testSearchByKeywordWithRegularTerm(): void
@ -162,8 +162,8 @@ class LCSCProviderTest extends TestCase
$this->assertIsArray($results);
$this->assertCount(1, $results);
$this->assertInstanceOf(PartDetailDTO::class, $results[0]);
$this->assertEquals('C789012', $results[0]->provider_id);
$this->assertEquals('Regular Component', $results[0]->name);
$this->assertSame('C789012', $results[0]->provider_id);
$this->assertSame('Regular Component', $results[0]->name);
}
public function testSearchByKeywordWithTipProduct(): void
@ -202,8 +202,8 @@ class LCSCProviderTest extends TestCase
$this->assertIsArray($results);
$this->assertCount(1, $results);
$this->assertInstanceOf(PartDetailDTO::class, $results[0]);
$this->assertEquals('C555555', $results[0]->provider_id);
$this->assertEquals('Tip Component', $results[0]->name);
$this->assertSame('C555555', $results[0]->provider_id);
$this->assertSame('Tip Component', $results[0]->name);
}
public function testSearchByKeywordsBatch(): void
@ -288,12 +288,12 @@ class LCSCProviderTest extends TestCase
$result = $this->provider->getDetails('C123456');
$this->assertInstanceOf(PartDetailDTO::class, $result);
$this->assertEquals('C123456', $result->provider_id);
$this->assertEquals('Detailed Component', $result->name);
$this->assertEquals('Detailed description', $result->description);
$this->assertEquals('Detailed Manufacturer', $result->manufacturer);
$this->assertSame('C123456', $result->provider_id);
$this->assertSame('Detailed Component', $result->name);
$this->assertSame('Detailed description', $result->description);
$this->assertSame('Detailed Manufacturer', $result->manufacturer);
$this->assertEquals('0603', $result->footprint);
$this->assertEquals('https://www.lcsc.com/product-detail/C123456.html', $result->provider_url);
$this->assertSame('https://www.lcsc.com/product-detail/C123456.html', $result->provider_url);
$this->assertCount(1, $result->images);
$this->assertCount(2, $result->parameters);
$this->assertCount(1, $result->vendor_infos);
@ -465,8 +465,8 @@ class LCSCProviderTest extends TestCase
$this->assertIsArray($result);
$this->assertCount(1, $result);
$this->assertInstanceOf(PurchaseInfoDTO::class, $result[0]);
$this->assertEquals('LCSC', $result[0]->distributor_name);
$this->assertEquals('C123456', $result[0]->order_number);
$this->assertSame('LCSC', $result[0]->distributor_name);
$this->assertSame('C123456', $result[0]->order_number);
$this->assertCount(2, $result[0]->prices);
}
@ -493,7 +493,7 @@ class LCSCProviderTest extends TestCase
$this->httpClient->setResponseFactory([$mockResponse]);
$result = $this->provider->getDetails('C123456');
$this->assertEquals('Electronic Components -> Resistors (SMT)', $result->category);
$this->assertSame('Electronic Components -> Resistors (SMT)', $result->category);
}
public function testEmptyFootprintHandling(): void