mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-02-16 22:49:36 +00:00
Ran rector and made tests final
This commit is contained in:
parent
43d72faf48
commit
b21d294cf8
162 changed files with 407 additions and 393 deletions
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
|
@ -17,18 +20,18 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Services\InfoProviderSystem\DTOs;
|
||||
|
||||
use App\Services\InfoProviderSystem\Providers\InfoProviderInterface;
|
||||
use App\Services\InfoProviderSystem\DTOs\BulkSearchFieldMappingDTO;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BulkSearchFieldMappingDTOTest extends TestCase
|
||||
final class BulkSearchFieldMappingDTOTest extends TestCase
|
||||
{
|
||||
|
||||
public function testProviderInstanceNormalization(): void
|
||||
{
|
||||
$mockProvider = $this->createMock(\App\Services\InfoProviderSystem\Providers\InfoProviderInterface::class);
|
||||
$mockProvider = $this->createMock(InfoProviderInterface::class);
|
||||
$mockProvider->method('getProviderKey')->willReturn('mock_provider');
|
||||
|
||||
$fieldMapping = new BulkSearchFieldMappingDTO(field: 'mpn', providers: ['provider1', $mockProvider], priority: 5);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
|
@ -17,46 +20,47 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Services\InfoProviderSystem\DTOs;
|
||||
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Services\InfoProviderSystem\DTOs\BulkSearchPartResultDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\BulkSearchPartResultsDTO;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BulkSearchPartResultsDTOTest extends TestCase
|
||||
final class BulkSearchPartResultsDTOTest extends TestCase
|
||||
{
|
||||
|
||||
public function testHasErrors(): void
|
||||
{
|
||||
$test = new BulkSearchPartResultsDTO($this->createMock(\App\Entity\Parts\Part::class), [], []);
|
||||
$test = new BulkSearchPartResultsDTO($this->createStub(Part::class), [], []);
|
||||
$this->assertFalse($test->hasErrors());
|
||||
$test = new BulkSearchPartResultsDTO($this->createMock(\App\Entity\Parts\Part::class), [], ['error1']);
|
||||
$test = new BulkSearchPartResultsDTO($this->createStub(Part::class), [], ['error1']);
|
||||
$this->assertTrue($test->hasErrors());
|
||||
}
|
||||
|
||||
public function testGetErrorCount(): void
|
||||
{
|
||||
$test = new BulkSearchPartResultsDTO($this->createMock(\App\Entity\Parts\Part::class), [], []);
|
||||
$test = new BulkSearchPartResultsDTO($this->createStub(Part::class), [], []);
|
||||
$this->assertCount(0, $test->errors);
|
||||
$test = new BulkSearchPartResultsDTO($this->createMock(\App\Entity\Parts\Part::class), [], ['error1', 'error2']);
|
||||
$test = new BulkSearchPartResultsDTO($this->createStub(Part::class), [], ['error1', 'error2']);
|
||||
$this->assertCount(2, $test->errors);
|
||||
}
|
||||
|
||||
public function testHasResults(): void
|
||||
{
|
||||
$test = new BulkSearchPartResultsDTO($this->createMock(\App\Entity\Parts\Part::class), [], []);
|
||||
$test = new BulkSearchPartResultsDTO($this->createStub(Part::class), [], []);
|
||||
$this->assertFalse($test->hasResults());
|
||||
$test = new BulkSearchPartResultsDTO($this->createMock(\App\Entity\Parts\Part::class), [ $this->createMock(\App\Services\InfoProviderSystem\DTOs\BulkSearchPartResultDTO::class) ], []);
|
||||
$test = new BulkSearchPartResultsDTO($this->createStub(Part::class), [ $this->createStub(BulkSearchPartResultDTO::class) ], []);
|
||||
$this->assertTrue($test->hasResults());
|
||||
}
|
||||
|
||||
public function testGetResultCount(): void
|
||||
{
|
||||
$test = new BulkSearchPartResultsDTO($this->createMock(\App\Entity\Parts\Part::class), [], []);
|
||||
$test = new BulkSearchPartResultsDTO($this->createStub(Part::class), [], []);
|
||||
$this->assertCount(0, $test->searchResults);
|
||||
$test = new BulkSearchPartResultsDTO($this->createMock(\App\Entity\Parts\Part::class), [
|
||||
$this->createMock(\App\Services\InfoProviderSystem\DTOs\BulkSearchPartResultDTO::class),
|
||||
$this->createMock(\App\Services\InfoProviderSystem\DTOs\BulkSearchPartResultDTO::class)
|
||||
$test = new BulkSearchPartResultsDTO($this->createStub(Part::class), [
|
||||
$this->createStub(BulkSearchPartResultDTO::class),
|
||||
$this->createStub(BulkSearchPartResultDTO::class)
|
||||
], []);
|
||||
$this->assertCount(2, $test->searchResults);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
|
@ -17,7 +20,6 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Services\InfoProviderSystem\DTOs;
|
||||
|
||||
use App\Entity\Parts\Part;
|
||||
|
|
@ -29,7 +31,7 @@ use Doctrine\ORM\EntityManagerInterface;
|
|||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
class BulkSearchResponseDTOTest extends KernelTestCase
|
||||
final class BulkSearchResponseDTOTest extends KernelTestCase
|
||||
{
|
||||
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ use PHPUnit\Framework\Attributes\DataProvider;
|
|||
use App\Services\InfoProviderSystem\DTOs\FileDTO;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FileDTOTest extends TestCase
|
||||
final class FileDTOTest extends TestCase
|
||||
{
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ use PHPUnit\Framework\Attributes\DataProvider;
|
|||
use App\Services\InfoProviderSystem\DTOs\ParameterDTO;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ParameterDTOTest extends TestCase
|
||||
final class ParameterDTOTest extends TestCase
|
||||
{
|
||||
|
||||
public static function parseValueFieldDataProvider(): \Generator
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ use App\Services\InfoProviderSystem\DTOs\PriceDTO;
|
|||
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class PurchaseInfoDTOTest extends TestCase
|
||||
final class PurchaseInfoDTOTest extends TestCase
|
||||
{
|
||||
public function testThrowOnInvalidType(): void
|
||||
{
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace App\Tests\Services\InfoProviderSystem\DTOs;
|
|||
use App\Services\InfoProviderSystem\DTOs\SearchResultDTO;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SearchResultDTOTest extends TestCase
|
||||
final class SearchResultDTOTest extends TestCase
|
||||
{
|
||||
public function testPreviewImageURL(): void
|
||||
{
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ use PhpParser\Node\Param;
|
|||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class DTOtoEntityConverterTest extends WebTestCase
|
||||
final class DTOtoEntityConverterTest extends WebTestCase
|
||||
{
|
||||
|
||||
private ?DTOtoEntityConverter $service = null;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ use App\Services\InfoProviderSystem\Providers\InfoProviderInterface;
|
|||
use App\Services\InfoProviderSystem\Providers\URLHandlerInfoProviderInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ProviderRegistryTest extends TestCase
|
||||
final class ProviderRegistryTest extends TestCase
|
||||
{
|
||||
|
||||
/** @var InfoProviderInterface[] */
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue