Applied rector suggestions

This commit is contained in:
Jan Böhmer 2024-06-22 00:31:43 +02:00
parent 4106bcef5f
commit 20f32c7f12
170 changed files with 808 additions and 761 deletions

View file

@ -69,7 +69,7 @@ class AttachmentPathResolverTest extends WebTestCase
$this->assertNull($this->service->parameterToAbsolutePath('/./this/one/too'));
}
public function placeholderDataProvider(): array
public function placeholderDataProvider(): \Iterator
{
//We need to do initialization (again), as dataprovider is called before setUp()
self::bootKernel();
@ -77,28 +77,28 @@ class AttachmentPathResolverTest extends WebTestCase
$this->projectDir = str_replace('\\', '/', $this->projectDir_orig);
$this->media_path = $this->projectDir.'/public/media';
$this->footprint_path = $this->projectDir.'/public/img/footprints';
return [
['%FOOTPRINTS%/test/test.jpg', $this->footprint_path.'/test/test.jpg'],
['%FOOTPRINTS%/test/', $this->footprint_path.'/test/'],
['%MEDIA%/test', $this->media_path.'/test'],
['%MEDIA%', $this->media_path],
['%FOOTPRINTS%', $this->footprint_path],
//Footprints 3D are disabled
['%FOOTPRINTS_3D%', null],
//Check that invalid pathes return null
['/no/placeholder', null],
['%INVALID_PLACEHOLDER%', null],
['%FOOTPRINTS/test/', null], //Malformed placeholder
['/wrong/%FOOTRPINTS%/', null], //Placeholder not at beginning
['%FOOTPRINTS%/%MEDIA%', null], //No more than one placholder
['%FOOTPRINTS%/%FOOTPRINTS%', null],
['%FOOTPRINTS%/../../etc/passwd', null],
['%FOOTPRINTS%/0\..\test', null],
];
yield ['%FOOTPRINTS%/test/test.jpg', $this->footprint_path.'/test/test.jpg'];
yield ['%FOOTPRINTS%/test/', $this->footprint_path.'/test/'];
yield ['%MEDIA%/test', $this->media_path.'/test'];
yield ['%MEDIA%', $this->media_path];
yield ['%FOOTPRINTS%', $this->footprint_path];
//Footprints 3D are disabled
yield ['%FOOTPRINTS_3D%', null];
//Check that invalid pathes return null
yield ['/no/placeholder', null];
yield ['%INVALID_PLACEHOLDER%', null];
yield ['%FOOTPRINTS/test/', null];
//Malformed placeholder
yield ['/wrong/%FOOTRPINTS%/', null];
//Placeholder not at beginning
yield ['%FOOTPRINTS%/%MEDIA%', null];
//No more than one placholder
yield ['%FOOTPRINTS%/%FOOTPRINTS%', null];
yield ['%FOOTPRINTS%/../../etc/passwd', null];
yield ['%FOOTPRINTS%/0\..\test', null];
}
public function realPathDataProvider(): array
public function realPathDataProvider(): \Iterator
{
//We need to do initialization (again), as dataprovider is called before setUp()
self::bootKernel();
@ -106,20 +106,17 @@ class AttachmentPathResolverTest extends WebTestCase
$this->projectDir = str_replace('\\', '/', $this->projectDir_orig);
$this->media_path = $this->projectDir.'/public/media';
$this->footprint_path = $this->projectDir.'/public/img/footprints';
return [
[$this->media_path.'/test/img.jpg', '%MEDIA%/test/img.jpg'],
[$this->media_path.'/test/img.jpg', '%BASE%/data/media/test/img.jpg', true],
[$this->footprint_path.'/foo.jpg', '%FOOTPRINTS%/foo.jpg'],
[$this->footprint_path.'/foo.jpg', '%FOOTPRINTS%/foo.jpg', true],
//Every kind of absolute path, that is not based with our placeholder dirs must be invald
['/etc/passwd', null],
['C:\\not\\existing.txt', null],
//More than one placeholder is not allowed
[$this->footprint_path.'/test/'.$this->footprint_path, null],
//Path must begin with path
['/not/root'.$this->footprint_path, null],
];
yield [$this->media_path.'/test/img.jpg', '%MEDIA%/test/img.jpg'];
yield [$this->media_path.'/test/img.jpg', '%BASE%/data/media/test/img.jpg', true];
yield [$this->footprint_path.'/foo.jpg', '%FOOTPRINTS%/foo.jpg'];
yield [$this->footprint_path.'/foo.jpg', '%FOOTPRINTS%/foo.jpg', true];
//Every kind of absolute path, that is not based with our placeholder dirs must be invald
yield ['/etc/passwd', null];
yield ['C:\\not\\existing.txt', null];
//More than one placeholder is not allowed
yield [$this->footprint_path.'/test/'.$this->footprint_path, null];
//Path must begin with path
yield ['/not/root'.$this->footprint_path, null];
}
/**

View file

@ -35,56 +35,52 @@ class FileTypeFilterToolsTest extends WebTestCase
self::$service = self::getContainer()->get(FileTypeFilterTools::class);
}
public function validateDataProvider(): array
public function validateDataProvider(): \Iterator
{
return [
['', true], //Empty string is valid
['.jpeg,.png, .gif', true], //Only extensions are valid
['image/*, video/*, .mp4, video/x-msvideo, application/vnd.amazon.ebook', true],
['application/vnd.amazon.ebook, audio/opus', true],
['*.notvalid, .png', false], //No stars in extension
['test.png', false], //No full filename
['application/*', false], //Only certain placeholders are allowed
['.png;.png,.jpg', false], //Wrong separator
['.png .jpg .gif', false],
];
yield ['', true];
//Empty string is valid
yield ['.jpeg,.png, .gif', true];
//Only extensions are valid
yield ['image/*, video/*, .mp4, video/x-msvideo, application/vnd.amazon.ebook', true];
yield ['application/vnd.amazon.ebook, audio/opus', true];
yield ['*.notvalid, .png', false];
//No stars in extension
yield ['test.png', false];
//No full filename
yield ['application/*', false];
//Only certain placeholders are allowed
yield ['.png;.png,.jpg', false];
//Wrong separator
yield ['.png .jpg .gif', false];
}
public function normalizeDataProvider(): array
public function normalizeDataProvider(): \Iterator
{
return [
['', ''],
['.jpeg,.png,.gif', '.jpeg,.png,.gif'],
['.jpeg, .png, .gif,', '.jpeg,.png,.gif'],
['jpg, *.gif', '.jpg,.gif'],
['video, image/', 'video/*,image/*'],
['video/*', 'video/*'],
['video/x-msvideo,.jpeg', 'video/x-msvideo,.jpeg'],
['.video', '.video'],
//Remove duplicate entries
['png, .gif, .png,', '.png,.gif'],
];
yield ['', ''];
yield ['.jpeg,.png,.gif', '.jpeg,.png,.gif'];
yield ['.jpeg, .png, .gif,', '.jpeg,.png,.gif'];
yield ['jpg, *.gif', '.jpg,.gif'];
yield ['video, image/', 'video/*,image/*'];
yield ['video/*', 'video/*'];
yield ['video/x-msvideo,.jpeg', 'video/x-msvideo,.jpeg'];
yield ['.video', '.video'];
//Remove duplicate entries
yield ['png, .gif, .png,', '.png,.gif'];
}
public function extensionAllowedDataProvider(): array
public function extensionAllowedDataProvider(): \Iterator
{
return [
['', 'txt', true],
['', 'everything_should_match', true],
['.jpg,.png', 'jpg', true],
['.jpg,.png', 'png', true],
['.jpg,.png', 'txt', false],
['image/*', 'jpeg', true],
['image/*', 'png', true],
['image/*', 'txt', false],
['application/pdf,.txt', 'pdf', true],
['application/pdf,.txt', 'txt', true],
['application/pdf,.txt', 'jpg', false],
];
yield ['', 'txt', true];
yield ['', 'everything_should_match', true];
yield ['.jpg,.png', 'jpg', true];
yield ['.jpg,.png', 'png', true];
yield ['.jpg,.png', 'txt', false];
yield ['image/*', 'jpeg', true];
yield ['image/*', 'png', true];
yield ['image/*', 'txt', false];
yield ['application/pdf,.txt', 'pdf', true];
yield ['application/pdf,.txt', 'txt', true];
yield ['application/pdf,.txt', 'jpg', false];
}
/**

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\EntityMergers\Mergers;
use App\Entity\Parts\Part;

View file

@ -37,7 +37,7 @@ class MergeTestClass
public Collection $collection;
public ?Category $category;
public ?Category $category = null;
public function __construct()
{

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\EntityMergers\Mergers;
use App\Entity\Parts\AssociationType;

View file

@ -84,7 +84,7 @@ class BOMImporterTest extends WebTestCase
$this->assertCount(4, $bom);
$this->assertSame('R19,R17', $bom[0]->getMountnames());
$this->assertSame(2.0, $bom[0]->getQuantity());
$this->assertEqualsWithDelta(2.0, $bom[0]->getQuantity(), PHP_FLOAT_EPSILON);
$this->assertSame('4.7k (R_0805_2012Metric_Pad1.20x1.40mm_HandSolder)', $bom[0]->getName());
$this->assertSame('Test', $bom[0]->getComment());
@ -103,7 +103,7 @@ class BOMImporterTest extends WebTestCase
$this->assertCount(4, $bom);
$this->assertSame('R19,R17', $bom[0]->getMountnames());
$this->assertSame(2.0, $bom[0]->getQuantity());
$this->assertEqualsWithDelta(2.0, $bom[0]->getQuantity(), PHP_FLOAT_EPSILON);
$this->assertSame('4.7k (R_0805_2012Metric_Pad1.20x1.40mm_HandSolder)', $bom[0]->getName());
$this->assertSame('Test', $bom[0]->getComment());
}

View file

@ -172,16 +172,14 @@ EOT;
$this->assertSame($longName, $errors[0]['entity']->getName());
}
public function formatDataProvider(): array
public function formatDataProvider(): \Iterator
{
return [
['csv', 'csv'],
['csv', 'CSV'],
['xml', 'Xml'],
['json', 'json'],
['yaml', 'yml'],
['yaml', 'YAML'],
];
yield ['csv', 'csv'];
yield ['csv', 'CSV'];
yield ['xml', 'Xml'];
yield ['json', 'json'];
yield ['yaml', 'yml'];
yield ['yaml', 'YAML'];
}
/**

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\Services\InfoProviderSystem\DTOs\ParameterDTO;
@ -241,18 +243,18 @@ class ParameterDTOTest extends TestCase
public function testSplitIntoValueAndUnit(): void
{
$this->assertEquals(['1.0', 'kg'], ParameterDTO::splitIntoValueAndUnit('1.0 kg'));
$this->assertEquals(['1.0', 'kg'], ParameterDTO::splitIntoValueAndUnit('1.0kg'));
$this->assertEquals(['1', 'kg'], ParameterDTO::splitIntoValueAndUnit('1 kg'));
$this->assertSame(['1.0', 'kg'], ParameterDTO::splitIntoValueAndUnit('1.0 kg'));
$this->assertSame(['1.0', 'kg'], ParameterDTO::splitIntoValueAndUnit('1.0kg'));
$this->assertSame(['1', 'kg'], ParameterDTO::splitIntoValueAndUnit('1 kg'));
$this->assertEquals(['1.0', '°C'], ParameterDTO::splitIntoValueAndUnit('1.0°C'));
$this->assertEquals(['1.0', '°C'], ParameterDTO::splitIntoValueAndUnit('1.0 °C'));
$this->assertSame(['1.0', '°C'], ParameterDTO::splitIntoValueAndUnit('1.0°C'));
$this->assertSame(['1.0', '°C'], ParameterDTO::splitIntoValueAndUnit('1.0 °C'));
$this->assertEquals(['1.0', 'C_m'], ParameterDTO::splitIntoValueAndUnit('1.0C_m'));
$this->assertEquals(["70", ""], ParameterDTO::splitIntoValueAndUnit("70℃"));
$this->assertSame(['1.0', 'C_m'], ParameterDTO::splitIntoValueAndUnit('1.0C_m'));
$this->assertSame(["70", ""], ParameterDTO::splitIntoValueAndUnit("70℃"));
$this->assertEquals(["-5.0", "kg"], ParameterDTO::splitIntoValueAndUnit("-5.0 kg"));
$this->assertEquals(["-5.0", "µg"], ParameterDTO::splitIntoValueAndUnit("-5.0 µg"));
$this->assertSame(["-5.0", "kg"], ParameterDTO::splitIntoValueAndUnit("-5.0 kg"));
$this->assertSame(["-5.0", "µg"], ParameterDTO::splitIntoValueAndUnit("-5.0 µg"));
$this->assertNull(ParameterDTO::splitIntoValueAndUnit('kg'));
$this->assertNull(ParameterDTO::splitIntoValueAndUnit('Test'));

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\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;

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\Services\InfoProviderSystem\DTOs\SearchResultDTO;
@ -45,8 +47,8 @@ class SearchResultDTOTest extends TestCase
'description',
preview_image_url: 'https://invalid.com/preview_image_url.jpg'
);
$this->assertEquals('https://invalid.com/preview_image_url.jpg', $searchResultDTO->preview_image_url);
$this->assertEquals('https://invalid.com/preview_image_url.jpg', $searchResultDTO->preview_image_file->url);
$this->assertSame('https://invalid.com/preview_image_url.jpg', $searchResultDTO->preview_image_url);
$this->assertSame('https://invalid.com/preview_image_url.jpg', $searchResultDTO->preview_image_file->url);
//Invalid url characters should be replaced with their URL encoded version (similar to FileDTO)
$searchResultDTO = new SearchResultDTO(
@ -56,7 +58,7 @@ class SearchResultDTOTest extends TestCase
'description',
preview_image_url: 'https://invalid.com/preview_image^url.jpg?param1=1&param2=2'
);
$this->assertEquals('https://invalid.com/preview_image%5Eurl.jpg?param1=1&param2=2', $searchResultDTO->preview_image_url);
$this->assertEquals('https://invalid.com/preview_image%5Eurl.jpg?param1=1&param2=2', $searchResultDTO->preview_image_file->url);
$this->assertSame('https://invalid.com/preview_image%5Eurl.jpg?param1=1&param2=2', $searchResultDTO->preview_image_url);
$this->assertSame('https://invalid.com/preview_image%5Eurl.jpg?param1=1&param2=2', $searchResultDTO->preview_image_file->url);
}
}

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;
use App\Entity\Attachments\AttachmentType;
@ -53,7 +55,7 @@ class DTOtoEntityConverterTest extends WebTestCase
$entity = $this->service->convertParameter($dto);
$this->assertEquals($dto->name, $entity->getName());
$this->assertSame($dto->name, $entity->getName());
$this->assertEquals($dto->value_text, $entity->getValueText());
$this->assertEquals($dto->value_typ, $entity->getValueTypical());
$this->assertEquals($dto->value_min, $entity->getValueMin());
@ -74,8 +76,8 @@ class DTOtoEntityConverterTest extends WebTestCase
);
$entity = $this->service->convertPrice($dto);
$this->assertEquals($dto->minimum_discount_amount, $entity->getMinDiscountQuantity());
$this->assertEquals((float) $dto->price, (float) (string) $entity->getPrice());
$this->assertSame($dto->minimum_discount_amount, $entity->getMinDiscountQuantity());
$this->assertSame((float) $dto->price, (float) (string) $entity->getPrice());
$this->assertEquals($dto->price_related_quantity, $entity->getPriceRelatedQuantity());
//For non-base currencies, a new currency entity is created
@ -114,8 +116,8 @@ class DTOtoEntityConverterTest extends WebTestCase
$entity = $this->service->convertPurchaseInfo($dto);
$this->assertEquals($dto->distributor_name, $entity->getSupplier()->getName());
$this->assertEquals($dto->order_number, $entity->getSupplierPartNr());
$this->assertSame($dto->distributor_name, $entity->getSupplier()->getName());
$this->assertSame($dto->order_number, $entity->getSupplierPartNr());
$this->assertEquals($dto->product_url, $entity->getSupplierProductUrl());
}
@ -128,7 +130,7 @@ class DTOtoEntityConverterTest extends WebTestCase
$entity = $this->service->convertFile($dto, $type);
$this->assertEquals($dto->name, $entity->getName());
$this->assertEquals($dto->url, $entity->getUrl());
$this->assertSame($dto->url, $entity->getUrl());
$this->assertEquals($type, $entity->getAttachmentType());
}
@ -141,8 +143,8 @@ class DTOtoEntityConverterTest extends WebTestCase
$entity = $this->service->convertFile($dto, $type);
//If no name is given, the name is derived from the url
$this->assertEquals('file.pdf', $entity->getName());
$this->assertEquals($dto->url, $entity->getUrl());
$this->assertSame('file.pdf', $entity->getName());
$this->assertSame($dto->url, $entity->getUrl());
$this->assertEquals($type, $entity->getAttachmentType());
}
@ -184,11 +186,11 @@ class DTOtoEntityConverterTest extends WebTestCase
$this->assertCount(3, $entity->getAttachments());
//The attachments should have the name of the named duplicate file
$image1 = $entity->getAttachments()[0];
$this->assertEquals('Main image', $image1->getName());
$this->assertSame('Main image', $image1->getName());
$image1 = $entity->getAttachments()[1];
$datasheet = $entity->getAttachments()[2];
$this->assertEquals('TestFile', $datasheet->getName());
$this->assertSame('TestFile', $datasheet->getName());
}
}

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;
use App\Services\InfoProviderSystem\ProviderRegistry;

View file

@ -57,22 +57,18 @@ class BarcodeContentGeneratorTest extends KernelTestCase
$this->service = self::getContainer()->get(BarcodeContentGenerator::class);
}
public function Barcode1DDataProvider(): array
public function Barcode1DDataProvider(): \Iterator
{
return [
['P0000', Part::class],
['L0000', PartLot::class],
['S0000', StorageLocation::class],
];
yield ['P0000', Part::class];
yield ['L0000', PartLot::class];
yield ['S0000', StorageLocation::class];
}
public function Barcode2DDataProvider(): array
public function Barcode2DDataProvider(): \Iterator
{
return [
['/scan/part/0', Part::class],
['/scan/lot/0', PartLot::class],
['/scan/location/0', StorageLocation::class],
];
yield ['/scan/part/0', Part::class];
yield ['/scan/lot/0', PartLot::class];
yield ['/scan/location/0', StorageLocation::class];
}
/**

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\LabelSystem\Barcodes;
use App\Entity\LabelSystem\BarcodeType;

View file

@ -58,14 +58,12 @@ final class BarcodeRedirectorTest extends KernelTestCase
$this->service = self::getContainer()->get(BarcodeRedirector::class);
}
public static function urlDataProvider(): array
public static function urlDataProvider(): \Iterator
{
return [
[new BarcodeScanResult(LabelSupportedElement::PART, 1, BarcodeSourceType::INTERNAL), '/en/part/1'],
//Part lot redirects to Part info page (Part lot 1 is associated with part 3)
[new BarcodeScanResult(LabelSupportedElement::PART_LOT, 1, BarcodeSourceType::INTERNAL), '/en/part/3'],
[new BarcodeScanResult(LabelSupportedElement::STORELOCATION, 1, BarcodeSourceType::INTERNAL), '/en/store_location/1/parts'],
];
yield [new BarcodeScanResult(LabelSupportedElement::PART, 1, BarcodeSourceType::INTERNAL), '/en/part/1'];
//Part lot redirects to Part info page (Part lot 1 is associated with part 3)
yield [new BarcodeScanResult(LabelSupportedElement::PART_LOT, 1, BarcodeSourceType::INTERNAL), '/en/part/3'];
yield [new BarcodeScanResult(LabelSupportedElement::STORELOCATION, 1, BarcodeSourceType::INTERNAL), '/en/store_location/1/parts'];
}
/**

View file

@ -113,16 +113,19 @@ class BarcodeScanHelperTest extends WebTestCase
'lot2_vendor_barcode'];
}
public static function invalidDataProvider(): array
public static function invalidDataProvider(): \Iterator
{
return [
['https://localhost/part/1'], //Without scan
['L-'], //Without number
['L-123'], //Too short
['X-123456'], //Unknown prefix
['XXXWADSDF sdf'], //Garbage
[''], //Empty
];
yield ['https://localhost/part/1'];
//Without scan
yield ['L-'];
//Without number
yield ['L-123'];
//Too short
yield ['X-123456'];
//Unknown prefix
yield ['XXXWADSDF sdf'];
//Garbage
yield [''];
}
/**

View file

@ -63,13 +63,11 @@ class LabelGeneratorTest extends WebTestCase
$this->service = self::getContainer()->get(LabelGenerator::class);
}
public static function supportsDataProvider(): array
public static function supportsDataProvider(): \Iterator
{
return [
[LabelSupportedElement::PART, Part::class],
[LabelSupportedElement::PART_LOT, PartLot::class],
[LabelSupportedElement::STORELOCATION, StorageLocation::class],
];
yield [LabelSupportedElement::PART, Part::class];
yield [LabelSupportedElement::PART_LOT, PartLot::class];
yield [LabelSupportedElement::STORELOCATION, StorageLocation::class];
}
/**

View file

@ -70,32 +70,28 @@ class LabelTextReplacerTest extends WebTestCase
$this->target->setComment('P Comment');
}
public function handlePlaceholderDataProvider(): array
public function handlePlaceholderDataProvider(): \Iterator
{
return [
['Part 1', '[[NAME]]'],
['P Description', '[[DESCRIPTION]]'],
['[[UNKNOWN]]', '[[UNKNOWN]]', '[[UNKNOWN]]'],
['[[INVALID', '[[INVALID'],
['[[', '[['],
['NAME', 'NAME'],
['[[NAME', '[[NAME'],
['Test [[NAME]]', 'Test [[NAME]]', 'Test [[NAME]]'],
];
yield ['Part 1', '[[NAME]]'];
yield ['P Description', '[[DESCRIPTION]]'];
yield ['[[UNKNOWN]]', '[[UNKNOWN]]', '[[UNKNOWN]]'];
yield ['[[INVALID', '[[INVALID'];
yield ['[[', '[['];
yield ['NAME', 'NAME'];
yield ['[[NAME', '[[NAME'];
yield ['Test [[NAME]]', 'Test [[NAME]]', 'Test [[NAME]]'];
}
public function replaceDataProvider(): array
public function replaceDataProvider(): \Iterator
{
return [
['Part 1', '[[NAME]]'],
['TestPart 1', 'Test[[NAME]]'],
["P Description\nPart 1", "[[DESCRIPTION_T]]\n[[NAME]]"],
['Part 1 Part 1', '[[NAME]] [[NAME]]'],
['[[UNKNOWN]] Test', '[[UNKNOWN]] Test'],
["[[NAME\n]] [[NAME ]]", "[[NAME\n]] [[NAME ]]"],
['[[]]', '[[]]'],
['TEST[[ ]]TEST', 'TEST[[ ]]TEST'],
];
yield ['Part 1', '[[NAME]]'];
yield ['TestPart 1', 'Test[[NAME]]'];
yield ["P Description\nPart 1", "[[DESCRIPTION_T]]\n[[NAME]]"];
yield ['Part 1 Part 1', '[[NAME]] [[NAME]]'];
yield ['[[UNKNOWN]] Test', '[[UNKNOWN]] Test'];
yield ["[[NAME\n]] [[NAME ]]", "[[NAME\n]] [[NAME ]]"];
yield ['[[]]', '[[]]'];
yield ['TEST[[ ]]TEST', 'TEST[[ ]]TEST'];
}
/**

View file

@ -61,50 +61,46 @@ class SandboxedTwigFactoryTest extends WebTestCase
$this->service = self::getContainer()->get(SandboxedTwigFactory::class);
}
public function twigDataProvider(): array
public function twigDataProvider(): \Iterator
{
return [
[' {% for i in range(1, 3) %}
yield [' {% for i in range(1, 3) %}
{{ part.id }}
{{ part.name }}
{{ part.lastModified | format_datetime }}
{% endfor %}
'],
[' {% if part.category %}
'];
yield [' {% if part.category %}
{{ part.category }}
{% endif %}
'],
[' {% set a = random(1, 3) %}
'];
yield [' {% set a = random(1, 3) %}
{{ 1 + 2 | abs }}
{{ "test" | capitalize | escape | lower | raw }}
{{ "\n" | nl2br | trim | title | url_encode | reverse }}
'],
['
'];
yield ['
{{ location.isRoot}} {{ location.isChildOf(location) }} {{ location.comment }} {{ location.level }}
{{ location.fullPath }} {% set arr = location.pathArray %} {% set child = location.children %} {{location.childrenNotSelectable}}
'],
['
'];
yield ['
{{ part.reviewNeeded }} {{ part.tags }} {{ part.mass }}
'],
['
'];
yield ['
{{ entity_type(part) is object }}
'],
['
'];
yield ['
{% apply placeholders(part) %}[[NAME]]{% endapply %}</br>
{{ placeholder("[[NAME]]", part) }}
']
];
'];
}
public function twigNotAllowedDataProvider(): array
public function twigNotAllowedDataProvider(): \Iterator
{
return [
['{% block test %} {% endblock %}'],
['{% deprecated test %}'],
['{% flush %}'],
["{{ part.setName('test') }}"],
['{{ part.setCategory(null) }}'],
];
yield ['{% block test %} {% endblock %}'];
yield ['{% deprecated test %}'];
yield ['{% flush %}'];
yield ["{{ part.setName('test') }}"];
yield ['{{ part.setCategory(null) }}'];
}
/**

View file

@ -41,60 +41,58 @@ class FAIconGeneratorTest extends WebTestCase
$this->service = self::getContainer()->get(FAIconGenerator::class);
}
public function fileExtensionDataProvider(): array
public function fileExtensionDataProvider(): \Iterator
{
return [
['pdf', 'fa-file-pdf'],
['jpeg','fa-file-image'],
['txt', 'fa-file-lines'],
['doc', 'fa-file-word'],
['zip', 'fa-file-zipper'],
['png', 'fa-file-image'],
['jpg', 'fa-file-image'],
['gif', 'fa-file-image'],
['svg', 'fa-file-image'],
['xls', 'fa-file-excel'],
['xlsx', 'fa-file-excel'],
['ppt', 'fa-file-powerpoint'],
['pptx', 'fa-file-powerpoint'],
['docx', 'fa-file-word'],
['odt', 'fa-file-word'],
['ods', 'fa-file-excel'],
['odp', 'fa-file-powerpoint'],
['py', 'fa-file-code'],
['js', 'fa-file-code'],
['html', 'fa-file-code'],
['css', 'fa-file-code'],
['xml', 'fa-file-code'],
['json', 'fa-file-code'],
['yml', 'fa-file-code'],
['yaml', 'fa-file-code'],
['csv', 'fa-file-csv'],
['sql', 'fa-file-code'],
['sh', 'fa-file-code'],
['bat', 'fa-file-code'],
['exe', 'fa-file-code'],
['dll', 'fa-file-code'],
['lib', 'fa-file-code'],
['so', 'fa-file-code'],
['a', 'fa-file-code'],
['o', 'fa-file-code'],
['class', 'fa-file-code'],
['jar', 'fa-file-code'],
['rar', 'fa-file-zipper'],
['7z', 'fa-file-zipper'],
['tar', 'fa-file-zipper'],
['gz', 'fa-file-zipper'],
['tgz', 'fa-file-zipper'],
['bz2', 'fa-file-zipper'],
['tbz', 'fa-file-zipper'],
['xz', 'fa-file-zipper'],
['txz', 'fa-file-zipper'],
['zip', 'fa-file-zipper'],
['php', 'fa-file-code'],
['tmp', 'fa-file'],
['fgd', 'fa-file'],
];
yield ['pdf', 'fa-file-pdf'];
yield ['jpeg','fa-file-image'];
yield ['txt', 'fa-file-lines'];
yield ['doc', 'fa-file-word'];
yield ['zip', 'fa-file-zipper'];
yield ['png', 'fa-file-image'];
yield ['jpg', 'fa-file-image'];
yield ['gif', 'fa-file-image'];
yield ['svg', 'fa-file-image'];
yield ['xls', 'fa-file-excel'];
yield ['xlsx', 'fa-file-excel'];
yield ['ppt', 'fa-file-powerpoint'];
yield ['pptx', 'fa-file-powerpoint'];
yield ['docx', 'fa-file-word'];
yield ['odt', 'fa-file-word'];
yield ['ods', 'fa-file-excel'];
yield ['odp', 'fa-file-powerpoint'];
yield ['py', 'fa-file-code'];
yield ['js', 'fa-file-code'];
yield ['html', 'fa-file-code'];
yield ['css', 'fa-file-code'];
yield ['xml', 'fa-file-code'];
yield ['json', 'fa-file-code'];
yield ['yml', 'fa-file-code'];
yield ['yaml', 'fa-file-code'];
yield ['csv', 'fa-file-csv'];
yield ['sql', 'fa-file-code'];
yield ['sh', 'fa-file-code'];
yield ['bat', 'fa-file-code'];
yield ['exe', 'fa-file-code'];
yield ['dll', 'fa-file-code'];
yield ['lib', 'fa-file-code'];
yield ['so', 'fa-file-code'];
yield ['a', 'fa-file-code'];
yield ['o', 'fa-file-code'];
yield ['class', 'fa-file-code'];
yield ['jar', 'fa-file-code'];
yield ['rar', 'fa-file-zipper'];
yield ['7z', 'fa-file-zipper'];
yield ['tar', 'fa-file-zipper'];
yield ['gz', 'fa-file-zipper'];
yield ['tgz', 'fa-file-zipper'];
yield ['bz2', 'fa-file-zipper'];
yield ['tbz', 'fa-file-zipper'];
yield ['xz', 'fa-file-zipper'];
yield ['txz', 'fa-file-zipper'];
yield ['zip', 'fa-file-zipper'];
yield ['php', 'fa-file-code'];
yield ['tmp', 'fa-file'];
yield ['fgd', 'fa-file'];
}
/**

View file

@ -81,21 +81,19 @@ class RangeParserTest extends WebTestCase
yield [[], '1, 2, test', true];
}
public function validDataProvider(): array
public function validDataProvider(): \Iterator
{
return [
[true, ''],
[true, ' '],
[true, '1, 2, 3'],
[true, '1-2,3, 4- 5'],
[true, '1 -2, 3- 4, 6'],
[true, '1--2'],
[true, '1- -2'],
[true, ',,12,33'],
[false, 'test'],
[false, '1-2-3'],
[false, '1, 2 test'],
];
yield [true, ''];
yield [true, ' '];
yield [true, '1, 2, 3'];
yield [true, '1-2,3, 4- 5'];
yield [true, '1 -2, 3- 4, 6'];
yield [true, '1--2'];
yield [true, '1- -2'];
yield [true, ',,12,33'];
yield [false, 'test'];
yield [false, '1-2-3'];
yield [false, '1, 2 test'];
}
/**

View file

@ -56,19 +56,17 @@ class ParameterExtractorTest extends WebTestCase
$this->service = self::getContainer()->get(ParameterExtractor::class);
}
public function emptyDataProvider(): array
public function emptyDataProvider(): \Iterator
{
return [
[''],
[' '],
["\t\n"],
[':;'],
['NPN Transistor'],
['=BC547 rewr'],
['<i>For good</i>, [b]bad[/b], evil'],
['Param:; Test'],
['A [link](https://demo.part-db.de) should not be matched']
];
yield [''];
yield [' '];
yield ["\t\n"];
yield [':;'];
yield ['NPN Transistor'];
yield ['=BC547 rewr'];
yield ['<i>For good</i>, [b]bad[/b], evil'];
yield ['Param:; Test'];
yield ['A [link](https://demo.part-db.de) should not be matched'];
}
/**

View file

@ -119,15 +119,15 @@ class PartLotWithdrawAddHelperTest extends WebTestCase
{
//Add 5 to lot 1
$this->service->add($this->partLot1, 5, "Test");
$this->assertSame(15.0, $this->partLot1->getAmount());
$this->assertEqualsWithDelta(15.0, $this->partLot1->getAmount(), PHP_FLOAT_EPSILON);
//Add 3.2 to lot 2
$this->service->add($this->partLot2, 3.2, "Test");
$this->assertSame(5.0, $this->partLot2->getAmount());
$this->assertEqualsWithDelta(5.0, $this->partLot2->getAmount(), PHP_FLOAT_EPSILON);
//Add 1.5 to lot 3
$this->service->add($this->partLot3, 1.5, "Test");
$this->assertSame(2.0, $this->partLot3->getAmount());
$this->assertEqualsWithDelta(2.0, $this->partLot3->getAmount(), PHP_FLOAT_EPSILON);
}
@ -135,23 +135,23 @@ class PartLotWithdrawAddHelperTest extends WebTestCase
{
//Withdraw 5 from lot 1
$this->service->withdraw($this->partLot1, 5, "Test");
$this->assertSame(5.0, $this->partLot1->getAmount());
$this->assertEqualsWithDelta(5.0, $this->partLot1->getAmount(), PHP_FLOAT_EPSILON);
//Withdraw 2.2 from lot 2
$this->service->withdraw($this->partLot2, 2.2, "Test");
$this->assertSame(0.0, $this->partLot2->getAmount());
$this->assertEqualsWithDelta(0.0, $this->partLot2->getAmount(), PHP_FLOAT_EPSILON);
}
public function testMove(): void
{
//Move 5 from lot 1 to lot 2
$this->service->move($this->partLot1, $this->partLot2, 5, "Test");
$this->assertSame(5.0, $this->partLot1->getAmount());
$this->assertSame(7.0, $this->partLot2->getAmount());
$this->assertEqualsWithDelta(5.0, $this->partLot1->getAmount(), PHP_FLOAT_EPSILON);
$this->assertEqualsWithDelta(7.0, $this->partLot2->getAmount(), PHP_FLOAT_EPSILON);
//Move 2.2 from lot 2 to lot 3
$this->service->move($this->partLot2, $this->partLot3, 2.2, "Test");
$this->assertSame(5.0, $this->partLot2->getAmount());
$this->assertSame(2.0, $this->partLot3->getAmount());
$this->assertEqualsWithDelta(5.0, $this->partLot2->getAmount(), PHP_FLOAT_EPSILON);
$this->assertEqualsWithDelta(2.0, $this->partLot3->getAmount(), PHP_FLOAT_EPSILON);
}
}

View file

@ -91,16 +91,14 @@ class PermissionManagerTest extends WebTestCase
$this->group->method('getParent')->willReturn($parent_group);
}
public function getPermissionNames(): array
public function getPermissionNames(): \Iterator
{
//List some permission names
return [
['parts'],
['system'],
['footprints'],
['suppliers'],
['tools']
];
yield ['parts'];
yield ['system'];
yield ['footprints'];
yield ['suppliers'];
yield ['tools'];
}
/**

View file

@ -46,9 +46,12 @@ class BackupCodeGeneratorTest extends TestCase
new BackupCodeGenerator(4, 10);
}
public function codeLengthDataProvider(): array
public function codeLengthDataProvider(): \Iterator
{
return [[6], [8], [10], [16]];
yield [6];
yield [8];
yield [10];
yield [16];
}
/**
@ -60,9 +63,11 @@ class BackupCodeGeneratorTest extends TestCase
$this->assertMatchesRegularExpression("/^([a-f0-9]){{$code_length}}\$/", $generator->generateSingleCode());
}
public function codeCountDataProvider(): array
public function codeCountDataProvider(): \Iterator
{
return [[2], [8], [10]];
yield [2];
yield [8];
yield [10];
}
/**

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\UserSystem;
use App\Entity\UserSystem\ApiToken;