Run phpunit code quality rector

This commit is contained in:
Jan Böhmer 2025-07-14 00:38:54 +02:00
parent f215bd11cd
commit f3ad3c1ffe
15 changed files with 66 additions and 70 deletions

View file

@ -35,6 +35,9 @@ return RectorConfig::configure()
PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES, PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES,
PHPUnitSetList::PHPUNIT_90, PHPUnitSetList::PHPUNIT_90,
PHPUnitSetList::PHPUNIT_110, PHPUnitSetList::PHPUNIT_110,
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
]) ])
->withRules([ ->withRules([

View file

@ -52,7 +52,7 @@ class FilterTraitTest extends TestCase
#[DataProvider('isAggregateFunctionStringDataProvider')] #[DataProvider('isAggregateFunctionStringDataProvider')]
public function testIsAggregateFunctionString(bool $expected, string $input): void public function testIsAggregateFunctionString(bool $expected, string $input): void
{ {
$this->assertEquals($expected, $this->isAggregateFunctionString($input)); $this->assertSame($expected, $this->isAggregateFunctionString($input));
} }
} }

View file

@ -231,7 +231,7 @@ class AttachmentTest extends TestCase
//Ensure that changing the external path does reset the internal one //Ensure that changing the external path does reset the internal one
$attachment->setInternalPath('%MEDIA%/foo/bar.txt'); $attachment->setInternalPath('%MEDIA%/foo/bar.txt');
$attachment->setExternalPath('https://example.de'); $attachment->setExternalPath('https://example.de');
$this->assertSame(null, $attachment->getInternalPath()); $this->assertNull($attachment->getInternalPath());
//Ensure that setting the same value to the external path again doesn't reset the internal one //Ensure that setting the same value to the external path again doesn't reset the internal one
$attachment->setExternalPath('https://google.de'); $attachment->setExternalPath('https://google.de');

View file

@ -41,7 +41,7 @@ class PartTest extends TestCase
$lot = new PartLot(); $lot = new PartLot();
$part->addPartLot($lot); $part->addPartLot($lot);
$this->assertSame($part, $lot->getPart()); $this->assertSame($part, $lot->getPart());
$this->assertSame(1, $part->getPartLots()->count()); $this->assertCount(1, $part->getPartLots());
//Remove element //Remove element
$part->removePartLot($lot); $part->removePartLot($lot);

View file

@ -38,7 +38,7 @@ class OrderdetailTest extends TestCase
$pricedetail = new Pricedetail(); $pricedetail = new Pricedetail();
$orderdetail->addPricedetail($pricedetail); $orderdetail->addPricedetail($pricedetail);
$this->assertSame($orderdetail, $pricedetail->getOrderdetail()); $this->assertSame($orderdetail, $pricedetail->getOrderdetail());
$this->assertSame(1, $orderdetail->getPricedetails()->count()); $this->assertCount(1, $orderdetail->getPricedetails());
//After removal of the pricedetail, the orderdetail must be empty again //After removal of the pricedetail, the orderdetail must be empty again
$orderdetail->removePricedetail($pricedetail); $orderdetail->removePricedetail($pricedetail);

View file

@ -35,7 +35,7 @@ class ApiTokenTypeTest extends TestCase
public function testGetTypeFromToken(): void public function testGetTypeFromToken(): void
{ {
$this->assertEquals(ApiTokenType::PERSONAL_ACCESS_TOKEN, ApiTokenType::getTypeFromToken('tcp_123')); $this->assertSame(ApiTokenType::PERSONAL_ACCESS_TOKEN, ApiTokenType::getTypeFromToken('tcp_123'));
} }
public function testGetTypeFromTokenInvalid(): void public function testGetTypeFromTokenInvalid(): void

View file

@ -33,9 +33,6 @@ use PHPUnit\Framework\TestCase;
class ProjectBuildRequestTest extends TestCase class ProjectBuildRequestTest extends TestCase
{ {
/** @var MeasurementUnit $float_unit */
private MeasurementUnit $float_unit;
/** @var Project */ /** @var Project */
private Project $project1; private Project $project1;
/** @var ProjectBOMEntry */ /** @var ProjectBOMEntry */
@ -49,30 +46,25 @@ class ProjectBuildRequestTest extends TestCase
private PartLot $lot1b; private PartLot $lot1b;
private PartLot $lot2; private PartLot $lot2;
/** @var Part */
private Part $part1;
/** @var Part */
private Part $part2;
public function setUp(): void public function setUp(): void
{ {
$this->float_unit = new MeasurementUnit(); $float_unit = new MeasurementUnit();
$this->float_unit->setName('float'); $float_unit->setName('float');
$this->float_unit->setUnit('f'); $float_unit->setUnit('f');
$this->float_unit->setIsInteger(false); $float_unit->setIsInteger(false);
$this->float_unit->setUseSIPrefix(true); $float_unit->setUseSIPrefix(true);
//Setup some example parts and part lots //Setup some example parts and part lots
$this->part1 = new Part(); $part1 = new Part();
$this->part1->setName('Part 1'); $part1->setName('Part 1');
$this->lot1a = new class extends PartLot { $this->lot1a = new class extends PartLot {
public function getID(): ?int public function getID(): ?int
{ {
return 1; return 1;
} }
}; };
$this->part1->addPartLot($this->lot1a); $part1->addPartLot($this->lot1a);
$this->lot1a->setAmount(10); $this->lot1a->setAmount(10);
$this->lot1a->setDescription('Lot 1a'); $this->lot1a->setDescription('Lot 1a');
@ -82,25 +74,25 @@ class ProjectBuildRequestTest extends TestCase
return 2; return 2;
} }
}; };
$this->part1->addPartLot($this->lot1b); $part1->addPartLot($this->lot1b);
$this->lot1b->setAmount(20); $this->lot1b->setAmount(20);
$this->lot1b->setDescription('Lot 1b'); $this->lot1b->setDescription('Lot 1b');
$this->part2 = new Part(); $part2 = new Part();
$this->part2->setName('Part 2'); $part2->setName('Part 2');
$this->part2->setPartUnit($this->float_unit); $part2->setPartUnit($float_unit);
$this->lot2 = new PartLot(); $this->lot2 = new PartLot();
$this->part2->addPartLot($this->lot2); $part2->addPartLot($this->lot2);
$this->lot2->setAmount(2.5); $this->lot2->setAmount(2.5);
$this->lot2->setDescription('Lot 2'); $this->lot2->setDescription('Lot 2');
$this->bom_entry1a = new ProjectBOMEntry(); $this->bom_entry1a = new ProjectBOMEntry();
$this->bom_entry1a->setPart($this->part1); $this->bom_entry1a->setPart($part1);
$this->bom_entry1a->setQuantity(2); $this->bom_entry1a->setQuantity(2);
$this->bom_entry1b = new ProjectBOMEntry(); $this->bom_entry1b = new ProjectBOMEntry();
$this->bom_entry1b->setPart($this->part2); $this->bom_entry1b->setPart($part2);
$this->bom_entry1b->setQuantity(1.5); $this->bom_entry1b->setQuantity(1.5);
$this->bom_entry1c = new ProjectBOMEntry(); $this->bom_entry1c = new ProjectBOMEntry();

View file

@ -32,7 +32,6 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
*/ */
class NamedDBElementRepositoryTest extends WebTestCase class NamedDBElementRepositoryTest extends WebTestCase
{ {
private $entityManager;
/** /**
* @var StructuralDBElementRepository * @var StructuralDBElementRepository
*/ */
@ -42,11 +41,11 @@ class NamedDBElementRepositoryTest extends WebTestCase
{ {
$kernel = self::bootKernel(); $kernel = self::bootKernel();
$this->entityManager = $kernel->getContainer() $entityManager = $kernel->getContainer()
->get('doctrine') ->get('doctrine')
->getManager(); ->getManager();
$this->repo = $this->entityManager->getRepository(User::class); $this->repo = $entityManager->getRepository(User::class);
} }
public function testGetGenericNodeTree(): void public function testGetGenericNodeTree(): void

View file

@ -32,7 +32,6 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
*/ */
class StructuralDBElementRepositoryTest extends WebTestCase class StructuralDBElementRepositoryTest extends WebTestCase
{ {
private $entityManager;
/** /**
* @var StructuralDBElementRepository * @var StructuralDBElementRepository
*/ */
@ -42,11 +41,11 @@ class StructuralDBElementRepositoryTest extends WebTestCase
{ {
$kernel = self::bootKernel(); $kernel = self::bootKernel();
$this->entityManager = $kernel->getContainer() $entityManager = $kernel->getContainer()
->get('doctrine') ->get('doctrine')
->getManager(); ->getManager();
$this->repo = $this->entityManager->getRepository(AttachmentType::class); $this->repo = $entityManager->getRepository(AttachmentType::class);
} }
public function testFindRootNodes(): void public function testFindRootNodes(): void

View file

@ -30,7 +30,6 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class UserRepositoryTest extends WebTestCase class UserRepositoryTest extends WebTestCase
{ {
private $entityManager;
/** /**
* @var UserRepository * @var UserRepository
*/ */
@ -40,11 +39,11 @@ class UserRepositoryTest extends WebTestCase
{ {
$kernel = self::bootKernel(); $kernel = self::bootKernel();
$this->entityManager = $kernel->getContainer() $entityManager = $kernel->getContainer()
->get('doctrine') ->get('doctrine')
->getManager(); ->getManager();
$this->repo = $this->entityManager->getRepository(User::class); $this->repo = $entityManager->getRepository(User::class);
} }

View file

@ -178,7 +178,9 @@ class PartMergerTest extends KernelTestCase
//But the new lots, should be assigned to the target part and contain the same info //But the new lots, should be assigned to the target part and contain the same info
$clone3 = $merged->getPartLots()->get(2); $clone3 = $merged->getPartLots()->get(2);
$clone4 = $merged->getPartLots()->get(3); $clone4 = $merged->getPartLots()->get(3);
$this->assertInstanceOf(PartLot::class, $clone3);
$this->assertSame($merged, $clone3->getPart()); $this->assertSame($merged, $clone3->getPart());
$this->assertInstanceOf(PartLot::class, $clone4);
$this->assertSame($merged, $clone4->getPart()); $this->assertSame($merged, $clone4->getPart());
} }

View file

@ -22,6 +22,7 @@ declare(strict_types=1);
*/ */
namespace App\Tests\Services\InfoProviderSystem; namespace App\Tests\Services\InfoProviderSystem;
use App\Entity\PriceInformations\Currency;
use App\Entity\Attachments\AttachmentType; use App\Entity\Attachments\AttachmentType;
use App\Entity\Parts\ManufacturingStatus; use App\Entity\Parts\ManufacturingStatus;
use App\Services\InfoProviderSystem\DTOs\FileDTO; use App\Services\InfoProviderSystem\DTOs\FileDTO;
@ -83,6 +84,7 @@ class DTOtoEntityConverterTest extends WebTestCase
//For non-base currencies, a new currency entity is created //For non-base currencies, a new currency entity is created
$currency = $entity->getCurrency(); $currency = $entity->getCurrency();
$this->assertInstanceOf(Currency::class, $currency);
$this->assertEquals($dto->currency_iso_code, $currency->getIsoCode()); $this->assertEquals($dto->currency_iso_code, $currency->getIsoCode());
} }

View file

@ -53,7 +53,7 @@ class EIGP114BarcodeScanResultTest extends TestCase
'4L' => 'US', '4L' => 'US',
'13Z' => 'Digi-Key', '13Z' => 'Digi-Key',
]); ]);
$this->assertEquals('digikey', $barcode->guessBarcodeVendor()); $this->assertSame('digikey', $barcode->guessBarcodeVendor());
//Mouser barcode: //Mouser barcode:
$barcode = new EIGP114BarcodeScanResult([ $barcode = new EIGP114BarcodeScanResult([
@ -66,7 +66,7 @@ class EIGP114BarcodeScanResultTest extends TestCase
'1V' => 'Mouser', '1V' => 'Mouser',
]); ]);
$this->assertEquals('mouser', $barcode->guessBarcodeVendor()); $this->assertSame('mouser', $barcode->guessBarcodeVendor());
//Farnell barcode: //Farnell barcode:
$barcode = new EIGP114BarcodeScanResult([ $barcode = new EIGP114BarcodeScanResult([
@ -79,7 +79,7 @@ class EIGP114BarcodeScanResultTest extends TestCase
'3P' => 'Farnell', '3P' => 'Farnell',
]); ]);
$this->assertEquals('element14', $barcode->guessBarcodeVendor()); $this->assertSame('element14', $barcode->guessBarcodeVendor());
} }
public function testIsFormat06Code(): void public function testIsFormat06Code(): void
@ -104,7 +104,7 @@ class EIGP114BarcodeScanResultTest extends TestCase
public function testParseFormat06Code(): void public function testParseFormat06Code(): void
{ {
$barcode = EIGP114BarcodeScanResult::parseFormat06Code("[)>\x1E06\x1DP596-777A1-ND\x1D1PXAF4444\x1DQ3\x1D10D1452\x1D1TBF1103\x1D4LUS\x1E\x04"); $barcode = EIGP114BarcodeScanResult::parseFormat06Code("[)>\x1E06\x1DP596-777A1-ND\x1D1PXAF4444\x1DQ3\x1D10D1452\x1D1TBF1103\x1D4LUS\x1E\x04");
$this->assertEquals([ $this->assertSame([
'P' => '596-777A1-ND', 'P' => '596-777A1-ND',
'1P' => 'XAF4444', '1P' => 'XAF4444',
'Q' => '3', 'Q' => '3',
@ -125,32 +125,32 @@ class EIGP114BarcodeScanResultTest extends TestCase
'4L' => 'US', '4L' => 'US',
]); ]);
$this->assertEquals('596-777A1-ND', $barcode->customerPartNumber); $this->assertSame('596-777A1-ND', $barcode->customerPartNumber);
$this->assertEquals('XAF4444', $barcode->supplierPartNumber); $this->assertSame('XAF4444', $barcode->supplierPartNumber);
$this->assertEquals(3, $barcode->quantity); $this->assertSame(3, $barcode->quantity);
$this->assertEquals('1452', $barcode->alternativeDateCode); $this->assertSame('1452', $barcode->alternativeDateCode);
$this->assertEquals('BF1103', $barcode->lotCode); $this->assertSame('BF1103', $barcode->lotCode);
$this->assertEquals('US', $barcode->countryOfOrigin); $this->assertSame('US', $barcode->countryOfOrigin);
} }
public function testDigikeyParsing(): void public function testDigikeyParsing(): void
{ {
$barcode = EIGP114BarcodeScanResult::parseFormat06Code("[)>\x1e06\x1dPQ1045-ND\x1d1P364019-01\x1d30PQ1045-ND\x1dK12432 TRAVIS FOSS P\x1d1K85732873\x1d10K103332956\x1d9D231013\x1d1TQJ13P\x1d11K1\x1d4LTW\x1dQ3\x1d11ZPICK\x1d12Z7360988\x1d13Z999999\x1d20Z0000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); $barcode = EIGP114BarcodeScanResult::parseFormat06Code("[)>\x1e06\x1dPQ1045-ND\x1d1P364019-01\x1d30PQ1045-ND\x1dK12432 TRAVIS FOSS P\x1d1K85732873\x1d10K103332956\x1d9D231013\x1d1TQJ13P\x1d11K1\x1d4LTW\x1dQ3\x1d11ZPICK\x1d12Z7360988\x1d13Z999999\x1d20Z0000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
$this->assertEquals('digikey', $barcode->guessBarcodeVendor()); $this->assertSame('digikey', $barcode->guessBarcodeVendor());
$this->assertEquals('Q1045-ND', $barcode->customerPartNumber); $this->assertSame('Q1045-ND', $barcode->customerPartNumber);
$this->assertEquals('364019-01', $barcode->supplierPartNumber); $this->assertSame('364019-01', $barcode->supplierPartNumber);
$this->assertEquals(3, $barcode->quantity); $this->assertSame(3, $barcode->quantity);
$this->assertEquals('231013', $barcode->dateCode); $this->assertSame('231013', $barcode->dateCode);
$this->assertEquals('QJ13P', $barcode->lotCode); $this->assertSame('QJ13P', $barcode->lotCode);
$this->assertEquals('TW', $barcode->countryOfOrigin); $this->assertSame('TW', $barcode->countryOfOrigin);
$this->assertEquals('Q1045-ND', $barcode->digikeyPartNumber); $this->assertSame('Q1045-ND', $barcode->digikeyPartNumber);
$this->assertEquals('85732873', $barcode->digikeySalesOrderNumber); $this->assertSame('85732873', $barcode->digikeySalesOrderNumber);
$this->assertEquals('103332956', $barcode->digikeyInvoiceNumber); $this->assertSame('103332956', $barcode->digikeyInvoiceNumber);
$this->assertEquals('PICK', $barcode->digikeyLabelType); $this->assertSame('PICK', $barcode->digikeyLabelType);
$this->assertEquals('7360988', $barcode->digikeyPartID); $this->assertSame('7360988', $barcode->digikeyPartID);
$this->assertEquals('999999', $barcode->digikeyNA); $this->assertSame('999999', $barcode->digikeyNA);
$this->assertEquals('0000000000000000000000000000000000000000000000000000000000000000000000000000000000000', $barcode->digikeyPadding); $this->assertSame('0000000000000000000000000000000000000000000000000000000000000000000000000000000000000', $barcode->digikeyPadding);
} }
} }

View file

@ -47,7 +47,7 @@ class TimeTravelTest extends KernelTestCase
$undeletedCategory = $this->service->undeleteEntity(Category::class, 100); $undeletedCategory = $this->service->undeleteEntity(Category::class, 100);
$this->assertInstanceOf(Category::class, $undeletedCategory); $this->assertInstanceOf(Category::class, $undeletedCategory);
$this->assertEquals(100, $undeletedCategory->getId()); $this->assertSame(100, $undeletedCategory->getId());
} }
public function testApplyEntry(): void public function testApplyEntry(): void
@ -65,8 +65,8 @@ class TimeTravelTest extends KernelTestCase
$this->service->applyEntry($category, $logEntry); $this->service->applyEntry($category, $logEntry);
$this->assertEquals('Old Category', $category->getName()); $this->assertSame('Old Category', $category->getName());
$this->assertEquals('Old Comment', $category->getComment()); $this->assertSame('Old Comment', $category->getComment());
} }
public function testRevertEntityToTimestamp(): void public function testRevertEntityToTimestamp(): void

View file

@ -90,9 +90,9 @@ class PermissionSchemaUpdaterTest extends WebTestCase
//Do an upgrade and afterward the move, add, and withdraw permissions should be set to ALLOW //Do an upgrade and afterward the move, add, and withdraw permissions should be set to ALLOW
self::assertTrue($this->service->upgradeSchema($user, 1)); self::assertTrue($this->service->upgradeSchema($user, 1));
self::assertEquals(PermissionData::ALLOW, $user->getPermissions()->getPermissionValue('parts_stock', 'move')); self::assertSame(PermissionData::ALLOW, $user->getPermissions()->getPermissionValue('parts_stock', 'move'));
self::assertEquals(PermissionData::ALLOW, $user->getPermissions()->getPermissionValue('parts_stock', 'add')); self::assertSame(PermissionData::ALLOW, $user->getPermissions()->getPermissionValue('parts_stock', 'add'));
self::assertEquals(PermissionData::ALLOW, $user->getPermissions()->getPermissionValue('parts_stock', 'withdraw')); self::assertSame(PermissionData::ALLOW, $user->getPermissions()->getPermissionValue('parts_stock', 'withdraw'));
} }
public function testUpgradeSchemaToVersion2(): void public function testUpgradeSchemaToVersion2(): void
@ -106,9 +106,9 @@ class PermissionSchemaUpdaterTest extends WebTestCase
//After the upgrade all operations should be available under the name "projects" with the same values //After the upgrade all operations should be available under the name "projects" with the same values
self::assertTrue($this->service->upgradeSchema($user, 2)); self::assertTrue($this->service->upgradeSchema($user, 2));
self::assertEquals(PermissionData::ALLOW, $user->getPermissions()->getPermissionValue('projects', 'read')); self::assertSame(PermissionData::ALLOW, $user->getPermissions()->getPermissionValue('projects', 'read'));
self::assertEquals(PermissionData::INHERIT, $user->getPermissions()->getPermissionValue('projects', 'edit')); self::assertSame(PermissionData::INHERIT, $user->getPermissions()->getPermissionValue('projects', 'edit'));
self::assertEquals(PermissionData::DISALLOW, $user->getPermissions()->getPermissionValue('projects', 'delete')); self::assertSame(PermissionData::DISALLOW, $user->getPermissions()->getPermissionValue('projects', 'delete'));
} }
public function testUpgradeSchemaToVersion3(): void public function testUpgradeSchemaToVersion3(): void