diff --git a/rector.php b/rector.php index ab637283..c45fab60 100644 --- a/rector.php +++ b/rector.php @@ -35,6 +35,9 @@ return RectorConfig::configure() PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES, PHPUnitSetList::PHPUNIT_90, PHPUnitSetList::PHPUNIT_110, + PHPUnitSetList::PHPUNIT_CODE_QUALITY, + + ]) ->withRules([ diff --git a/tests/DataTables/Filters/Constraints/FilterTraitTest.php b/tests/DataTables/Filters/Constraints/FilterTraitTest.php index 8d87071c..c2ec5905 100644 --- a/tests/DataTables/Filters/Constraints/FilterTraitTest.php +++ b/tests/DataTables/Filters/Constraints/FilterTraitTest.php @@ -52,7 +52,7 @@ class FilterTraitTest extends TestCase #[DataProvider('isAggregateFunctionStringDataProvider')] public function testIsAggregateFunctionString(bool $expected, string $input): void { - $this->assertEquals($expected, $this->isAggregateFunctionString($input)); + $this->assertSame($expected, $this->isAggregateFunctionString($input)); } } diff --git a/tests/Entity/Attachments/AttachmentTest.php b/tests/Entity/Attachments/AttachmentTest.php index c019c4bf..d878a689 100644 --- a/tests/Entity/Attachments/AttachmentTest.php +++ b/tests/Entity/Attachments/AttachmentTest.php @@ -231,7 +231,7 @@ class AttachmentTest extends TestCase //Ensure that changing the external path does reset the internal one $attachment->setInternalPath('%MEDIA%/foo/bar.txt'); $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 $attachment->setExternalPath('https://google.de'); diff --git a/tests/Entity/Parts/PartTest.php b/tests/Entity/Parts/PartTest.php index 3e9233c1..c1ae8935 100644 --- a/tests/Entity/Parts/PartTest.php +++ b/tests/Entity/Parts/PartTest.php @@ -41,7 +41,7 @@ class PartTest extends TestCase $lot = new PartLot(); $part->addPartLot($lot); $this->assertSame($part, $lot->getPart()); - $this->assertSame(1, $part->getPartLots()->count()); + $this->assertCount(1, $part->getPartLots()); //Remove element $part->removePartLot($lot); diff --git a/tests/Entity/PriceSystem/OrderdetailTest.php b/tests/Entity/PriceSystem/OrderdetailTest.php index 0046fd24..497f9ab3 100644 --- a/tests/Entity/PriceSystem/OrderdetailTest.php +++ b/tests/Entity/PriceSystem/OrderdetailTest.php @@ -38,7 +38,7 @@ class OrderdetailTest extends TestCase $pricedetail = new Pricedetail(); $orderdetail->addPricedetail($pricedetail); $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 $orderdetail->removePricedetail($pricedetail); diff --git a/tests/Entity/UserSystem/ApiTokenTypeTest.php b/tests/Entity/UserSystem/ApiTokenTypeTest.php index 21d14b69..a8e520f1 100644 --- a/tests/Entity/UserSystem/ApiTokenTypeTest.php +++ b/tests/Entity/UserSystem/ApiTokenTypeTest.php @@ -35,7 +35,7 @@ class ApiTokenTypeTest extends TestCase 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 diff --git a/tests/Helpers/Projects/ProjectBuildRequestTest.php b/tests/Helpers/Projects/ProjectBuildRequestTest.php index baccfcd1..1158d89a 100644 --- a/tests/Helpers/Projects/ProjectBuildRequestTest.php +++ b/tests/Helpers/Projects/ProjectBuildRequestTest.php @@ -33,9 +33,6 @@ use PHPUnit\Framework\TestCase; class ProjectBuildRequestTest extends TestCase { - /** @var MeasurementUnit $float_unit */ - private MeasurementUnit $float_unit; - /** @var Project */ private Project $project1; /** @var ProjectBOMEntry */ @@ -49,30 +46,25 @@ class ProjectBuildRequestTest extends TestCase private PartLot $lot1b; private PartLot $lot2; - /** @var Part */ - private Part $part1; - /** @var Part */ - private Part $part2; - public function setUp(): void { - $this->float_unit = new MeasurementUnit(); - $this->float_unit->setName('float'); - $this->float_unit->setUnit('f'); - $this->float_unit->setIsInteger(false); - $this->float_unit->setUseSIPrefix(true); + $float_unit = new MeasurementUnit(); + $float_unit->setName('float'); + $float_unit->setUnit('f'); + $float_unit->setIsInteger(false); + $float_unit->setUseSIPrefix(true); //Setup some example parts and part lots - $this->part1 = new Part(); - $this->part1->setName('Part 1'); + $part1 = new Part(); + $part1->setName('Part 1'); $this->lot1a = new class extends PartLot { public function getID(): ?int { return 1; } }; - $this->part1->addPartLot($this->lot1a); + $part1->addPartLot($this->lot1a); $this->lot1a->setAmount(10); $this->lot1a->setDescription('Lot 1a'); @@ -82,25 +74,25 @@ class ProjectBuildRequestTest extends TestCase return 2; } }; - $this->part1->addPartLot($this->lot1b); + $part1->addPartLot($this->lot1b); $this->lot1b->setAmount(20); $this->lot1b->setDescription('Lot 1b'); - $this->part2 = new Part(); + $part2 = new Part(); - $this->part2->setName('Part 2'); - $this->part2->setPartUnit($this->float_unit); + $part2->setName('Part 2'); + $part2->setPartUnit($float_unit); $this->lot2 = new PartLot(); - $this->part2->addPartLot($this->lot2); + $part2->addPartLot($this->lot2); $this->lot2->setAmount(2.5); $this->lot2->setDescription('Lot 2'); $this->bom_entry1a = new ProjectBOMEntry(); - $this->bom_entry1a->setPart($this->part1); + $this->bom_entry1a->setPart($part1); $this->bom_entry1a->setQuantity(2); $this->bom_entry1b = new ProjectBOMEntry(); - $this->bom_entry1b->setPart($this->part2); + $this->bom_entry1b->setPart($part2); $this->bom_entry1b->setQuantity(1.5); $this->bom_entry1c = new ProjectBOMEntry(); diff --git a/tests/Repository/NamedDBElementRepositoryTest.php b/tests/Repository/NamedDBElementRepositoryTest.php index fae9765d..117d7d0e 100644 --- a/tests/Repository/NamedDBElementRepositoryTest.php +++ b/tests/Repository/NamedDBElementRepositoryTest.php @@ -32,7 +32,6 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; */ class NamedDBElementRepositoryTest extends WebTestCase { - private $entityManager; /** * @var StructuralDBElementRepository */ @@ -42,11 +41,11 @@ class NamedDBElementRepositoryTest extends WebTestCase { $kernel = self::bootKernel(); - $this->entityManager = $kernel->getContainer() + $entityManager = $kernel->getContainer() ->get('doctrine') ->getManager(); - $this->repo = $this->entityManager->getRepository(User::class); + $this->repo = $entityManager->getRepository(User::class); } public function testGetGenericNodeTree(): void diff --git a/tests/Repository/StructuralDBElementRepositoryTest.php b/tests/Repository/StructuralDBElementRepositoryTest.php index 47c0cb45..5ab8b788 100644 --- a/tests/Repository/StructuralDBElementRepositoryTest.php +++ b/tests/Repository/StructuralDBElementRepositoryTest.php @@ -32,7 +32,6 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; */ class StructuralDBElementRepositoryTest extends WebTestCase { - private $entityManager; /** * @var StructuralDBElementRepository */ @@ -42,11 +41,11 @@ class StructuralDBElementRepositoryTest extends WebTestCase { $kernel = self::bootKernel(); - $this->entityManager = $kernel->getContainer() + $entityManager = $kernel->getContainer() ->get('doctrine') ->getManager(); - $this->repo = $this->entityManager->getRepository(AttachmentType::class); + $this->repo = $entityManager->getRepository(AttachmentType::class); } public function testFindRootNodes(): void diff --git a/tests/Repository/UserRepositoryTest.php b/tests/Repository/UserRepositoryTest.php index 0e6f3c2d..67a77aea 100644 --- a/tests/Repository/UserRepositoryTest.php +++ b/tests/Repository/UserRepositoryTest.php @@ -30,7 +30,6 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class UserRepositoryTest extends WebTestCase { - private $entityManager; /** * @var UserRepository */ @@ -40,11 +39,11 @@ class UserRepositoryTest extends WebTestCase { $kernel = self::bootKernel(); - $this->entityManager = $kernel->getContainer() + $entityManager = $kernel->getContainer() ->get('doctrine') ->getManager(); - $this->repo = $this->entityManager->getRepository(User::class); + $this->repo = $entityManager->getRepository(User::class); } diff --git a/tests/Services/EntityMergers/Mergers/PartMergerTest.php b/tests/Services/EntityMergers/Mergers/PartMergerTest.php index bf02744a..56c7712e 100644 --- a/tests/Services/EntityMergers/Mergers/PartMergerTest.php +++ b/tests/Services/EntityMergers/Mergers/PartMergerTest.php @@ -178,7 +178,9 @@ class PartMergerTest extends KernelTestCase //But the new lots, should be assigned to the target part and contain the same info $clone3 = $merged->getPartLots()->get(2); $clone4 = $merged->getPartLots()->get(3); + $this->assertInstanceOf(PartLot::class, $clone3); $this->assertSame($merged, $clone3->getPart()); + $this->assertInstanceOf(PartLot::class, $clone4); $this->assertSame($merged, $clone4->getPart()); } diff --git a/tests/Services/InfoProviderSystem/DTOtoEntityConverterTest.php b/tests/Services/InfoProviderSystem/DTOtoEntityConverterTest.php index 396969e2..6c933472 100644 --- a/tests/Services/InfoProviderSystem/DTOtoEntityConverterTest.php +++ b/tests/Services/InfoProviderSystem/DTOtoEntityConverterTest.php @@ -22,6 +22,7 @@ declare(strict_types=1); */ namespace App\Tests\Services\InfoProviderSystem; +use App\Entity\PriceInformations\Currency; use App\Entity\Attachments\AttachmentType; use App\Entity\Parts\ManufacturingStatus; use App\Services\InfoProviderSystem\DTOs\FileDTO; @@ -83,6 +84,7 @@ class DTOtoEntityConverterTest extends WebTestCase //For non-base currencies, a new currency entity is created $currency = $entity->getCurrency(); + $this->assertInstanceOf(Currency::class, $currency); $this->assertEquals($dto->currency_iso_code, $currency->getIsoCode()); } diff --git a/tests/Services/LabelSystem/BarcodeScanner/EIGP114BarcodeScanResultTest.php b/tests/Services/LabelSystem/BarcodeScanner/EIGP114BarcodeScanResultTest.php index d0ad8572..3a414997 100644 --- a/tests/Services/LabelSystem/BarcodeScanner/EIGP114BarcodeScanResultTest.php +++ b/tests/Services/LabelSystem/BarcodeScanner/EIGP114BarcodeScanResultTest.php @@ -53,7 +53,7 @@ class EIGP114BarcodeScanResultTest extends TestCase '4L' => 'US', '13Z' => 'Digi-Key', ]); - $this->assertEquals('digikey', $barcode->guessBarcodeVendor()); + $this->assertSame('digikey', $barcode->guessBarcodeVendor()); //Mouser barcode: $barcode = new EIGP114BarcodeScanResult([ @@ -66,7 +66,7 @@ class EIGP114BarcodeScanResultTest extends TestCase '1V' => 'Mouser', ]); - $this->assertEquals('mouser', $barcode->guessBarcodeVendor()); + $this->assertSame('mouser', $barcode->guessBarcodeVendor()); //Farnell barcode: $barcode = new EIGP114BarcodeScanResult([ @@ -79,7 +79,7 @@ class EIGP114BarcodeScanResultTest extends TestCase '3P' => 'Farnell', ]); - $this->assertEquals('element14', $barcode->guessBarcodeVendor()); + $this->assertSame('element14', $barcode->guessBarcodeVendor()); } public function testIsFormat06Code(): void @@ -104,7 +104,7 @@ class EIGP114BarcodeScanResultTest extends TestCase public function testParseFormat06Code(): void { $barcode = EIGP114BarcodeScanResult::parseFormat06Code("[)>\x1E06\x1DP596-777A1-ND\x1D1PXAF4444\x1DQ3\x1D10D1452\x1D1TBF1103\x1D4LUS\x1E\x04"); - $this->assertEquals([ + $this->assertSame([ 'P' => '596-777A1-ND', '1P' => 'XAF4444', 'Q' => '3', @@ -125,32 +125,32 @@ class EIGP114BarcodeScanResultTest extends TestCase '4L' => 'US', ]); - $this->assertEquals('596-777A1-ND', $barcode->customerPartNumber); - $this->assertEquals('XAF4444', $barcode->supplierPartNumber); - $this->assertEquals(3, $barcode->quantity); - $this->assertEquals('1452', $barcode->alternativeDateCode); - $this->assertEquals('BF1103', $barcode->lotCode); - $this->assertEquals('US', $barcode->countryOfOrigin); + $this->assertSame('596-777A1-ND', $barcode->customerPartNumber); + $this->assertSame('XAF4444', $barcode->supplierPartNumber); + $this->assertSame(3, $barcode->quantity); + $this->assertSame('1452', $barcode->alternativeDateCode); + $this->assertSame('BF1103', $barcode->lotCode); + $this->assertSame('US', $barcode->countryOfOrigin); } 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"); - $this->assertEquals('digikey', $barcode->guessBarcodeVendor()); + $this->assertSame('digikey', $barcode->guessBarcodeVendor()); - $this->assertEquals('Q1045-ND', $barcode->customerPartNumber); - $this->assertEquals('364019-01', $barcode->supplierPartNumber); - $this->assertEquals(3, $barcode->quantity); - $this->assertEquals('231013', $barcode->dateCode); - $this->assertEquals('QJ13P', $barcode->lotCode); - $this->assertEquals('TW', $barcode->countryOfOrigin); - $this->assertEquals('Q1045-ND', $barcode->digikeyPartNumber); - $this->assertEquals('85732873', $barcode->digikeySalesOrderNumber); - $this->assertEquals('103332956', $barcode->digikeyInvoiceNumber); - $this->assertEquals('PICK', $barcode->digikeyLabelType); - $this->assertEquals('7360988', $barcode->digikeyPartID); - $this->assertEquals('999999', $barcode->digikeyNA); - $this->assertEquals('0000000000000000000000000000000000000000000000000000000000000000000000000000000000000', $barcode->digikeyPadding); + $this->assertSame('Q1045-ND', $barcode->customerPartNumber); + $this->assertSame('364019-01', $barcode->supplierPartNumber); + $this->assertSame(3, $barcode->quantity); + $this->assertSame('231013', $barcode->dateCode); + $this->assertSame('QJ13P', $barcode->lotCode); + $this->assertSame('TW', $barcode->countryOfOrigin); + $this->assertSame('Q1045-ND', $barcode->digikeyPartNumber); + $this->assertSame('85732873', $barcode->digikeySalesOrderNumber); + $this->assertSame('103332956', $barcode->digikeyInvoiceNumber); + $this->assertSame('PICK', $barcode->digikeyLabelType); + $this->assertSame('7360988', $barcode->digikeyPartID); + $this->assertSame('999999', $barcode->digikeyNA); + $this->assertSame('0000000000000000000000000000000000000000000000000000000000000000000000000000000000000', $barcode->digikeyPadding); } } diff --git a/tests/Services/LogSystem/TimeTravelTest.php b/tests/Services/LogSystem/TimeTravelTest.php index f353cc12..f0068778 100644 --- a/tests/Services/LogSystem/TimeTravelTest.php +++ b/tests/Services/LogSystem/TimeTravelTest.php @@ -47,7 +47,7 @@ class TimeTravelTest extends KernelTestCase $undeletedCategory = $this->service->undeleteEntity(Category::class, 100); $this->assertInstanceOf(Category::class, $undeletedCategory); - $this->assertEquals(100, $undeletedCategory->getId()); + $this->assertSame(100, $undeletedCategory->getId()); } public function testApplyEntry(): void @@ -65,8 +65,8 @@ class TimeTravelTest extends KernelTestCase $this->service->applyEntry($category, $logEntry); - $this->assertEquals('Old Category', $category->getName()); - $this->assertEquals('Old Comment', $category->getComment()); + $this->assertSame('Old Category', $category->getName()); + $this->assertSame('Old Comment', $category->getComment()); } public function testRevertEntityToTimestamp(): void diff --git a/tests/Services/UserSystem/PermissionSchemaUpdaterTest.php b/tests/Services/UserSystem/PermissionSchemaUpdaterTest.php index 120fe075..1e41474c 100644 --- a/tests/Services/UserSystem/PermissionSchemaUpdaterTest.php +++ b/tests/Services/UserSystem/PermissionSchemaUpdaterTest.php @@ -90,9 +90,9 @@ class PermissionSchemaUpdaterTest extends WebTestCase //Do an upgrade and afterward the move, add, and withdraw permissions should be set to ALLOW self::assertTrue($this->service->upgradeSchema($user, 1)); - self::assertEquals(PermissionData::ALLOW, $user->getPermissions()->getPermissionValue('parts_stock', 'move')); - self::assertEquals(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', 'move')); + self::assertSame(PermissionData::ALLOW, $user->getPermissions()->getPermissionValue('parts_stock', 'add')); + self::assertSame(PermissionData::ALLOW, $user->getPermissions()->getPermissionValue('parts_stock', 'withdraw')); } 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 self::assertTrue($this->service->upgradeSchema($user, 2)); - self::assertEquals(PermissionData::ALLOW, $user->getPermissions()->getPermissionValue('projects', 'read')); - self::assertEquals(PermissionData::INHERIT, $user->getPermissions()->getPermissionValue('projects', 'edit')); - self::assertEquals(PermissionData::DISALLOW, $user->getPermissions()->getPermissionValue('projects', 'delete')); + self::assertSame(PermissionData::ALLOW, $user->getPermissions()->getPermissionValue('projects', 'read')); + self::assertSame(PermissionData::INHERIT, $user->getPermissions()->getPermissionValue('projects', 'edit')); + self::assertSame(PermissionData::DISALLOW, $user->getPermissions()->getPermissionValue('projects', 'delete')); } public function testUpgradeSchemaToVersion3(): void