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

@ -28,10 +28,8 @@ use App\Services\Attachments\AttachmentPathResolver;
use const DIRECTORY_SEPARATOR;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class AttachmentPathResolverTest extends WebTestCase
final class AttachmentPathResolverTest extends WebTestCase
{
protected string $media_path;
protected string $footprint_path;
protected $projectDir_orig;
protected $projectDir;
/**
@ -46,8 +44,8 @@ class AttachmentPathResolverTest extends WebTestCase
$this->projectDir_orig = realpath(self::$kernel->getProjectDir());
$this->projectDir = str_replace('\\', '/', $this->projectDir_orig);
$this->media_path = $this->projectDir.'/public/media';
$this->footprint_path = $this->projectDir.'/public/img/footprints';
$media_path = $this->projectDir.'/public/media';
$footprint_path = $this->projectDir.'/public/img/footprints';
$this->service = self::getContainer()->get(AttachmentPathResolver::class);
}

View file

@ -26,7 +26,7 @@ use PHPUnit\Framework\Attributes\DataProvider;
use App\Services\Attachments\AttachmentURLGenerator;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class AttachmentURLGeneratorTest extends WebTestCase
final class AttachmentURLGeneratorTest extends WebTestCase
{
protected const PUBLIC_DIR = '/public';

View file

@ -26,7 +26,7 @@ use PHPUnit\Framework\Attributes\DataProvider;
use App\Services\Attachments\BuiltinAttachmentsFinder;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class BuiltinAttachmentsFinderTest extends WebTestCase
final class BuiltinAttachmentsFinderTest extends WebTestCase
{
protected static array $mock_list = [
'%FOOTPRINTS%/test/test.jpg', '%FOOTPRINTS%/test/test.png', '%FOOTPRINTS%/123.jpg', '%FOOTPRINTS%/123.jpeg',

View file

@ -26,7 +26,7 @@ use PHPUnit\Framework\Attributes\DataProvider;
use App\Services\Attachments\FileTypeFilterTools;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class FileTypeFilterToolsTest extends WebTestCase
final class FileTypeFilterToolsTest extends WebTestCase
{
protected static $service;

View file

@ -35,7 +35,7 @@ use App\Services\Formatters\AmountFormatter;
use App\Settings\SynonymSettings;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class ElementTypeNameGeneratorTest extends WebTestCase
final class ElementTypeNameGeneratorTest extends WebTestCase
{
protected ElementTypeNameGenerator $service;
private SynonymSettings $synonymSettings;

View file

@ -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;
use App\Entity\Parameters\CategoryParameter;
@ -26,7 +28,7 @@ use App\Exceptions\EntityNotSupportedException;
use App\Services\ElementTypes;
use PHPUnit\Framework\TestCase;
class ElementTypesTest extends TestCase
final class ElementTypesTest extends TestCase
{
public function testFromClass(): void

View file

@ -28,7 +28,7 @@ use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
class EntityMergerHelperTraitTest extends KernelTestCase
final class EntityMergerHelperTraitTest extends KernelTestCase
{
use EntityMergerHelperTrait;

View file

@ -36,7 +36,7 @@ use App\Services\EntityMergers\Mergers\PartMerger;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class PartMergerTest extends KernelTestCase
final class PartMergerTest extends KernelTestCase
{
/** @var PartMerger|null */

View file

@ -27,7 +27,7 @@ use App\Services\Formatters\AmountFormatter;
use InvalidArgumentException;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class AmountFormatterTest extends WebTestCase
final class AmountFormatterTest extends WebTestCase
{
/**
* @var AmountFormatter

View file

@ -25,7 +25,7 @@ namespace App\Tests\Services\Formatters;
use App\Services\Formatters\SIFormatter;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class SIFormatterTest extends WebTestCase
final class SIFormatterTest extends WebTestCase
{
/**
* @var SIFormatter

View file

@ -22,6 +22,8 @@ declare(strict_types=1);
*/
namespace App\Tests\Services\ImportExportSystem;
use App\Entity\PriceInformations\Orderdetail;
use App\Entity\Parts\Category;
use App\Entity\Parts\Part;
use App\Entity\Parts\Supplier;
use App\Entity\ProjectSystem\Project;
@ -31,7 +33,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\File\File;
class BOMImporterTest extends WebTestCase
final class BOMImporterTest extends WebTestCase
{
/**
@ -391,7 +393,7 @@ class BOMImporterTest extends WebTestCase
// Check first entry
$this->assertEquals('R1,R2', $bom_entries[0]->getMountnames());
$this->assertEquals(2.0, $bom_entries[0]->getQuantity());
$this->assertEqualsWithDelta(2.0, $bom_entries[0]->getQuantity(), PHP_FLOAT_EPSILON);
$this->assertEquals('CRCW080510K0FKEA (R_0805_2012Metric)', $bom_entries[0]->getName());
$this->assertStringContainsString('Value: 10k', $bom_entries[0]->getComment());
$this->assertStringContainsString('MPN: CRCW080510K0FKEA', $bom_entries[0]->getComment());
@ -402,7 +404,7 @@ class BOMImporterTest extends WebTestCase
// Check second entry
$this->assertEquals('C1', $bom_entries[1]->getMountnames());
$this->assertEquals(1.0, $bom_entries[1]->getQuantity());
$this->assertEqualsWithDelta(1.0, $bom_entries[1]->getQuantity(), PHP_FLOAT_EPSILON);
$this->assertStringContainsString('LCSC SPN: C789012', $bom_entries[1]->getComment());
$this->assertStringContainsString('Mouser SPN: 80-CL21A104KOCLRNC', $bom_entries[1]->getComment());
@ -542,7 +544,7 @@ class BOMImporterTest extends WebTestCase
$this->assertCount(1, $bom_entries); // Should merge into one entry
$this->assertEquals('R1,R2', $bom_entries[0]->getMountnames());
$this->assertEquals(2.0, $bom_entries[0]->getQuantity());
$this->assertEqualsWithDelta(2.0, $bom_entries[0]->getQuantity(), PHP_FLOAT_EPSILON);
$this->assertEquals('CRCW080510K0FKEA', $bom_entries[0]->getName());
}
@ -630,7 +632,7 @@ class BOMImporterTest extends WebTestCase
$this->entityManager->persist($part);
// Create orderdetail linking the part to a supplier SPN
$orderdetail = new \App\Entity\PriceInformations\Orderdetail();
$orderdetail = new Orderdetail();
$orderdetail->setPart($part);
$orderdetail->setSupplier($lcscSupplier);
$orderdetail->setSupplierpartnr('C123456');
@ -664,7 +666,7 @@ class BOMImporterTest extends WebTestCase
$this->assertSame($part, $bom_entries[0]->getPart());
$this->assertEquals('Test Resistor 10k 0805', $bom_entries[0]->getName());
$this->assertEquals('R1,R2', $bom_entries[0]->getMountnames());
$this->assertEquals(2.0, $bom_entries[0]->getQuantity());
$this->assertEqualsWithDelta(2.0, $bom_entries[0]->getQuantity(), PHP_FLOAT_EPSILON);
$this->assertStringContainsString('LCSC SPN: C123456', $bom_entries[0]->getComment());
$this->assertStringContainsString('Part-DB ID: ' . $part->getID(), $bom_entries[0]->getComment());
@ -691,7 +693,7 @@ class BOMImporterTest extends WebTestCase
$part1->setCategory($this->getDefaultCategory($this->entityManager));
$this->entityManager->persist($part1);
$orderdetail1 = new \App\Entity\PriceInformations\Orderdetail();
$orderdetail1 = new Orderdetail();
$orderdetail1->setPart($part1);
$orderdetail1->setSupplier($lcscSupplier);
$orderdetail1->setSupplierpartnr('C123456');
@ -703,7 +705,7 @@ class BOMImporterTest extends WebTestCase
$part2->setCategory($this->getDefaultCategory($this->entityManager));
$this->entityManager->persist($part2);
$orderdetail2 = new \App\Entity\PriceInformations\Orderdetail();
$orderdetail2 = new Orderdetail();
$orderdetail2->setPart($part2);
$orderdetail2->setSupplier($mouserSupplier);
$orderdetail2->setSupplierpartnr('789-CAP100NF');
@ -794,12 +796,12 @@ class BOMImporterTest extends WebTestCase
private function getDefaultCategory(EntityManagerInterface $entityManager)
{
// Get the first available category or create a default one
$categoryRepo = $entityManager->getRepository(\App\Entity\Parts\Category::class);
$categoryRepo = $entityManager->getRepository(Category::class);
$categories = $categoryRepo->findAll();
if (empty($categories)) {
// Create a default category if none exists
$category = new \App\Entity\Parts\Category();
$category = new Category();
$category->setName('Default Category');
$entityManager->persist($category);
$entityManager->flush();

View file

@ -32,18 +32,16 @@ use Symfony\Contracts\Translation\TranslatorInterface;
/**
* @see \App\Services\ImportExportSystem\BOMValidationService
*/
class BOMValidationServiceTest extends WebTestCase
final class BOMValidationServiceTest extends WebTestCase
{
private BOMValidationService $validationService;
private EntityManagerInterface $entityManager;
private TranslatorInterface $translator;
protected function setUp(): void
{
self::bootKernel();
$this->entityManager = self::getContainer()->get(EntityManagerInterface::class);
$this->translator = self::getContainer()->get(TranslatorInterface::class);
$this->validationService = new BOMValidationService($this->entityManager, $this->translator);
$entityManager = self::getContainer()->get(EntityManagerInterface::class);
$translator = self::getContainer()->get(TranslatorInterface::class);
$this->validationService = new BOMValidationService($entityManager, $translator);
}
public function testValidateBOMEntryWithValidData(): void
@ -244,7 +242,7 @@ class BOMValidationServiceTest extends WebTestCase
$this->assertTrue($result['is_valid']);
$this->assertCount(1, $result['info']);
$this->assertStringContainsString('library prefix', $result['info'][0]);
$this->assertStringContainsString('library prefix', (string) $result['info'][0]);
}
public function testValidateBOMEntriesWithMultipleEntries(): void
@ -314,7 +312,7 @@ class BOMValidationServiceTest extends WebTestCase
$this->assertEquals(2, $stats['error_count']);
$this->assertEquals(1, $stats['warning_count']);
$this->assertEquals(2, $stats['info_count']);
$this->assertEquals(80.0, $stats['success_rate']);
$this->assertEqualsWithDelta(80.0, $stats['success_rate'], PHP_FLOAT_EPSILON);
}
public function testGetErrorMessage(): void
@ -344,6 +342,6 @@ class BOMValidationServiceTest extends WebTestCase
$message = $this->validationService->getErrorMessage($validation_result);
$this->assertEquals('', $message);
$this->assertSame('', $message);
}
}

View file

@ -28,7 +28,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Request;
use PhpOffice\PhpSpreadsheet\IOFactory;
class EntityExporterTest extends WebTestCase
final class EntityExporterTest extends WebTestCase
{
/**
* @var EntityExporter
@ -111,6 +111,6 @@ class EntityExporterTest extends WebTestCase
$response = $this->service->exportEntityFromRequest($entities, $request);
$this->assertSame('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $response->headers->get('Content-Type'));
$this->assertStringContainsString('export_Category_simple.xlsx', $response->headers->get('Content-Disposition'));
$this->assertStringContainsString('export_Category_simple.xlsx', (string) $response->headers->get('Content-Disposition'));
}
}

View file

@ -41,7 +41,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
#[Group('DB')]
class EntityImporterTest extends WebTestCase
final class EntityImporterTest extends WebTestCase
{
/**
* @var EntityImporter

View file

@ -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);

View file

@ -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);
}

View file

@ -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;

View file

@ -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
{

View file

@ -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

View file

@ -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
{

View file

@ -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
{

View file

@ -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;

View file

@ -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[] */

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

View file

@ -50,7 +50,7 @@ use App\Services\LabelSystem\BarcodeScanner\EIGP114BarcodeScanResult;
use App\Services\LabelSystem\BarcodeScanner\LocalBarcodeScanResult;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class BarcodeScanHelperTest extends WebTestCase
final class BarcodeScanHelperTest extends WebTestCase
{
private ?BarcodeScanHelper $service = null;

View file

@ -25,7 +25,7 @@ namespace App\Tests\Services\LabelSystem\BarcodeScanner;
use App\Services\LabelSystem\BarcodeScanner\EIGP114BarcodeScanResult;
use PHPUnit\Framework\TestCase;
class EIGP114BarcodeScanResultTest extends TestCase
final class EIGP114BarcodeScanResultTest extends TestCase
{
public function testGuessBarcodeVendor(): void

View file

@ -48,7 +48,7 @@ use App\Entity\Parts\StorageLocation;
use App\Services\LabelSystem\Barcodes\BarcodeContentGenerator;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class BarcodeContentGeneratorTest extends KernelTestCase
final class BarcodeContentGeneratorTest extends KernelTestCase
{
private ?object $service = null;

View file

@ -27,7 +27,7 @@ use App\Services\LabelSystem\Barcodes\BarcodeHelper;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class BarcodeHelperTest extends WebTestCase
final class BarcodeHelperTest extends WebTestCase
{
protected ?BarcodeHelper $service = null;

View file

@ -51,7 +51,7 @@ use App\Entity\Parts\StorageLocation;
use App\Services\LabelSystem\LabelGenerator;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class LabelGeneratorTest extends WebTestCase
final class LabelGeneratorTest extends WebTestCase
{
/**
* @var LabelGenerator

View file

@ -47,7 +47,7 @@ use App\Entity\Parts\PartLot;
use App\Services\LabelSystem\LabelTextReplacer;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class LabelTextReplacerTest extends WebTestCase
final class LabelTextReplacerTest extends WebTestCase
{
/**
* @var LabelTextReplacer

View file

@ -46,7 +46,7 @@ use App\Entity\Base\AbstractDBElement;
use App\Services\LabelSystem\PlaceholderProviders\AbstractDBElementProvider;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class AbstractElementProviderTest extends WebTestCase
final class AbstractElementProviderTest extends WebTestCase
{
/**
* @var AbstractDBElementProvider

View file

@ -46,7 +46,7 @@ use App\Entity\Parts\Part;
use App\Services\LabelSystem\PlaceholderProviders\GlobalProviders;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class GlobalProvidersTest extends WebTestCase
final class GlobalProvidersTest extends WebTestCase
{
/**
* @var GlobalProviders

View file

@ -46,7 +46,7 @@ use App\Entity\Contracts\NamedElementInterface;
use App\Services\LabelSystem\PlaceholderProviders\NamedElementProvider;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class NamedElementProviderTest extends WebTestCase
final class NamedElementProviderTest extends WebTestCase
{
/**
* @var NamedElementProvider

View file

@ -49,7 +49,7 @@ use App\Entity\UserSystem\User;
use App\Services\LabelSystem\PlaceholderProviders\PartLotProvider;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class PartLotProviderTest extends WebTestCase
final class PartLotProviderTest extends WebTestCase
{
/**
* @var PartLotProvider

View file

@ -53,7 +53,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
#[Group('DB')]
class PartProviderTest extends WebTestCase
final class PartProviderTest extends WebTestCase
{
/**
* @var PartProvider
@ -62,20 +62,15 @@ class PartProviderTest extends WebTestCase
protected Part $target;
/**
* @var EntityManager
*/
protected $em;
protected function setUp(): void
{
self::bootKernel();
$this->service = self::getContainer()->get(PartProvider::class);
$this->target = new Part();
$this->em = self::getContainer()->get(EntityManagerInterface::class);
$em = self::getContainer()->get(EntityManagerInterface::class);
$this->target->setCategory($this->em->find(Category::class, 6));
$this->target->setFootprint($this->em->find(Footprint::class, 6));
$this->target->setCategory($em->find(Category::class, 6));
$this->target->setFootprint($em->find(Footprint::class, 6));
$this->target->setManufacturer(null);
$this->target->setMass(1234.2);

View file

@ -48,7 +48,7 @@ use App\Services\LabelSystem\PlaceholderProviders\TimestampableElementProvider;
use DateTime;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class TimestampableElementProviderTest extends WebTestCase
final class TimestampableElementProviderTest extends WebTestCase
{
/**
* @var GlobalProviders

View file

@ -52,7 +52,7 @@ use App\Services\LabelSystem\SandboxedTwigFactory;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Twig\Sandbox\SecurityError;
class SandboxedTwigFactoryTest extends WebTestCase
final class SandboxedTwigFactoryTest extends WebTestCase
{
private ?SandboxedTwigFactory $service = null;

View file

@ -44,7 +44,7 @@ namespace App\Tests\Services\LogSystem;
use App\Services\LogSystem\EventCommentHelper;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class EventCommentHelperTest extends WebTestCase
final class EventCommentHelperTest extends WebTestCase
{
/**
* @var EventCommentHelper

View file

@ -28,7 +28,7 @@ use App\Settings\SystemSettings\HistorySettings;
use App\Tests\SettingsTestHelper;
use PHPUnit\Framework\TestCase;
class EventCommentNeededHelperTest extends TestCase
final class EventCommentNeededHelperTest extends TestCase
{
public function testIsCommentNeeded(): void
{

View file

@ -48,7 +48,7 @@ use App\Entity\LogSystem\UserLogoutLogEntry;
use App\Services\LogSystem\EventLogger;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class EventLoggerTest extends WebTestCase
final class EventLoggerTest extends WebTestCase
{
/**
* @var EventLogger

View file

@ -29,7 +29,7 @@ use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class TimeTravelTest extends KernelTestCase
final class TimeTravelTest extends KernelTestCase
{
private TimeTravel $service;

View file

@ -26,7 +26,7 @@ use PHPUnit\Framework\Attributes\DataProvider;
use App\Services\Misc\FAIconGenerator;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class FAIconGeneratorTest extends WebTestCase
final class FAIconGeneratorTest extends WebTestCase
{
/**
* @var FAIconGenerator

View file

@ -25,7 +25,7 @@ namespace App\Tests\Services\Misc;
use App\Services\ImportExportSystem\PartKeeprImporter\MySQLDumpXMLConverter;
use PHPUnit\Framework\TestCase;
class MySQLDumpXMLConverterTest extends TestCase
final class MySQLDumpXMLConverterTest extends TestCase
{
public function testConvertMySQLDumpXMLDataToArrayStructure(): void

View file

@ -45,7 +45,7 @@ use PHPUnit\Framework\Attributes\DataProvider;
use App\Services\Misc\RangeParser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class RangeParserTest extends WebTestCase
final class RangeParserTest extends WebTestCase
{
/**
* @var RangeParser

View file

@ -46,7 +46,7 @@ use App\Entity\Parameters\AbstractParameter;
use App\Services\Parameters\ParameterExtractor;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class ParameterExtractorTest extends WebTestCase
final class ParameterExtractorTest extends WebTestCase
{
protected $service;

View file

@ -18,7 +18,7 @@ class TestPartLot extends PartLot
}
}
class PartLotWithdrawAddHelperTest extends WebTestCase
final class PartLotWithdrawAddHelperTest extends WebTestCase
{
/**

View file

@ -27,7 +27,7 @@ use App\Services\Parts\PartsTableActionHandler;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\RedirectResponse;
class PartsTableActionHandlerTest extends WebTestCase
final class PartsTableActionHandlerTest extends WebTestCase
{
private PartsTableActionHandler $service;

View file

@ -30,7 +30,7 @@ use App\Services\Formatters\AmountFormatter;
use App\Services\Parts\PricedetailHelper;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class PricedetailHelperTest extends WebTestCase
final class PricedetailHelperTest extends WebTestCase
{
/**
* @var AmountFormatter

View file

@ -29,7 +29,7 @@ use App\Entity\ProjectSystem\ProjectBOMEntry;
use App\Services\ProjectSystem\ProjectBuildHelper;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class ProjectBuildHelperTest extends WebTestCase
final class ProjectBuildHelperTest extends WebTestCase
{
/** @var ProjectBuildHelper */
protected $service;

View file

@ -26,7 +26,7 @@ use App\Entity\ProjectSystem\Project;
use App\Services\ProjectSystem\ProjectBuildPartHelper;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class ProjectBuildPartHelperTest extends WebTestCase
final class ProjectBuildPartHelperTest extends WebTestCase
{
/** @var ProjectBuildPartHelper */
protected $service;

View file

@ -25,7 +25,7 @@ namespace App\Tests\Services\System;
use App\Services\System\BackupManager;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class BackupManagerTest extends KernelTestCase
final class BackupManagerTest extends KernelTestCase
{
private ?BackupManager $backupManager = null;
@ -77,9 +77,9 @@ class BackupManagerTest extends KernelTestCase
$result = preg_match('/pre-update-v([\d.]+)-to-v?([\d.]+)-/', $filename, $matches);
$this->assertEquals(1, $result);
$this->assertEquals('2.5.1', $matches[1]);
$this->assertEquals('2.6.0', $matches[2]);
$this->assertSame(1, $result);
$this->assertSame('2.5.1', $matches[1]);
$this->assertSame('2.6.0', $matches[2]);
}
/**
@ -90,13 +90,13 @@ class BackupManagerTest extends KernelTestCase
// Without 'v' prefix on target version
$filename1 = 'pre-update-v1.0.0-to-2.0.0-2024-01-30-185400.zip';
preg_match('/pre-update-v([\d.]+)-to-v?([\d.]+)-/', $filename1, $matches1);
$this->assertEquals('1.0.0', $matches1[1]);
$this->assertEquals('2.0.0', $matches1[2]);
$this->assertSame('1.0.0', $matches1[1]);
$this->assertSame('2.0.0', $matches1[2]);
// With 'v' prefix on target version
$filename2 = 'pre-update-v1.0.0-to-v2.0.0-2024-01-30-185400.zip';
preg_match('/pre-update-v([\d.]+)-to-v?([\d.]+)-/', $filename2, $matches2);
$this->assertEquals('1.0.0', $matches2[1]);
$this->assertEquals('2.0.0', $matches2[2]);
$this->assertSame('1.0.0', $matches2[1]);
$this->assertSame('2.0.0', $matches2[2]);
}
}

View file

@ -25,7 +25,7 @@ namespace App\Tests\Services\System;
use App\Services\System\UpdateExecutor;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class UpdateExecutorTest extends KernelTestCase
final class UpdateExecutorTest extends KernelTestCase
{
private ?UpdateExecutor $updateExecutor = null;

View file

@ -30,7 +30,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
/**
* @Group DB
*/
class NodesListBuilderTest extends WebTestCase
final class NodesListBuilderTest extends WebTestCase
{
protected $em;
/**

View file

@ -31,7 +31,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
#[Group('DB')]
class TreeViewGeneratorTest extends WebTestCase
final class TreeViewGeneratorTest extends WebTestCase
{
protected $em;
/**

View file

@ -30,7 +30,7 @@ use App\Services\UserSystem\PermissionManager;
use InvalidArgumentException;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class PermissionManagerTest extends WebTestCase
final class PermissionManagerTest extends WebTestCase
{
protected ?User $user_withoutGroup = null;

View file

@ -39,7 +39,7 @@ class TestPermissionHolder implements HasPermissionsInterface
}
}
class PermissionSchemaUpdaterTest extends WebTestCase
final class PermissionSchemaUpdaterTest extends WebTestCase
{
/**
* @var PermissionSchemaUpdater

View file

@ -27,7 +27,7 @@ use App\Services\UserSystem\TFA\BackupCodeGenerator;
use PHPUnit\Framework\TestCase;
use RuntimeException;
class BackupCodeGeneratorTest extends TestCase
final class BackupCodeGeneratorTest extends TestCase
{
/**
* Test if an exception is thrown if you are using a too high code length.

View file

@ -26,7 +26,7 @@ use App\Entity\UserSystem\User;
use App\Services\UserSystem\TFA\BackupCodeManager;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class BackupCodeManagerTest extends WebTestCase
final class BackupCodeManagerTest extends WebTestCase
{
/**
* @var BackupCodeManager

View file

@ -34,7 +34,7 @@ use Symfony\Component\Security\Core\Authentication\Token\NullToken;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Http\Authenticator\Token\PostAuthenticationToken;
class VoterHelperTest extends KernelTestCase
final class VoterHelperTest extends KernelTestCase
{
protected ?VoterHelper $service = null;