forked from mirror/Part-DB.Part-DB-server
Applied rectors phpunit 9 migrations to tests
This commit is contained in:
parent
684334ba22
commit
fcbb1849ec
22 changed files with 162 additions and 187 deletions
|
@ -38,15 +38,13 @@ class AttachmentURLGeneratorTest extends WebTestCase
|
|||
self::$service = self::getContainer()->get(AttachmentURLGenerator::class);
|
||||
}
|
||||
|
||||
public function dataProvider(): array
|
||||
public function dataProvider(): \Iterator
|
||||
{
|
||||
return [
|
||||
['/public/test.jpg', 'test.jpg'],
|
||||
['/public/folder/test.jpg', 'folder/test.jpg'],
|
||||
['/not/public/test.jpg', null],
|
||||
['/public/', ''],
|
||||
['not/absolute/test.jpg', null],
|
||||
];
|
||||
yield ['/public/test.jpg', 'test.jpg'];
|
||||
yield ['/public/folder/test.jpg', 'folder/test.jpg'];
|
||||
yield ['/not/public/test.jpg', null];
|
||||
yield ['/public/', ''];
|
||||
yield ['not/absolute/test.jpg', null];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -43,20 +43,15 @@ class BuiltinAttachmentsFinderTest extends WebTestCase
|
|||
self::$service = self::getContainer()->get(BuiltinAttachmentsFinder::class);
|
||||
}
|
||||
|
||||
public function dataProvider(): array
|
||||
public function dataProvider(): \Iterator
|
||||
{
|
||||
return [
|
||||
//No value should return empty array
|
||||
['', [], []],
|
||||
['', ['empty_returns_all' => true], static::$mock_list],
|
||||
//Basic search for keyword
|
||||
['test', [], ['%FOOTPRINTS%/test/test.jpg', '%FOOTPRINTS%/test/test.png', '%FOOTPRINTS_3D%/test.jpg']],
|
||||
['%FOOTPRINTS_3D%', [], ['%FOOTPRINTS_3D%/test.jpg', '%FOOTPRINTS_3D%/hallo.txt']],
|
||||
['.txt', [], ['%FOOTPRINTS_3D%/hallo.txt']],
|
||||
//Filter extensions
|
||||
//['test', ['allowed_extensions' => ['jpeg', 'jpg']], ['%FOOTPRINTS%/test/test.jpg', '%FOOTPRINTS%/123.jpeg', '%FOOTPRINTS_3D%/test.jpg']],
|
||||
//['test.jpg', ['allowed_extensions' => ['jpeg', 'jpg']], ['%FOOTPRINTS%/test/test.jpg', '%FOOTPRINTS_3D%/test.jpg']]
|
||||
];
|
||||
//No value should return empty array
|
||||
yield ['', [], []];
|
||||
yield ['', ['empty_returns_all' => true], static::$mock_list];
|
||||
//Basic search for keyword
|
||||
yield ['test', [], ['%FOOTPRINTS%/test/test.jpg', '%FOOTPRINTS%/test/test.png', '%FOOTPRINTS_3D%/test.jpg']];
|
||||
yield ['%FOOTPRINTS_3D%', [], ['%FOOTPRINTS_3D%/test.jpg', '%FOOTPRINTS_3D%/hallo.txt']];
|
||||
yield ['.txt', [], ['%FOOTPRINTS_3D%/hallo.txt']];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -81,8 +81,8 @@ class BOMImporterTest extends WebTestCase
|
|||
$this->assertContainsOnlyInstancesOf(ProjectBOMEntry::class, $bom);
|
||||
$this->assertCount(4, $bom);
|
||||
|
||||
$this->assertEquals('R19,R17', $bom[0]->getMountnames());
|
||||
$this->assertEquals(2.0, $bom[0]->getQuantity());
|
||||
$this->assertSame('R19,R17', $bom[0]->getMountnames());
|
||||
$this->assertSame(2.0, $bom[0]->getQuantity());
|
||||
$this->assertSame('4.7k (R_0805_2012Metric_Pad1.20x1.40mm_HandSolder)', $bom[0]->getName());
|
||||
$this->assertSame('Test', $bom[0]->getComment());
|
||||
|
||||
|
@ -100,8 +100,8 @@ class BOMImporterTest extends WebTestCase
|
|||
$this->assertContainsOnlyInstancesOf(ProjectBOMEntry::class, $bom);
|
||||
$this->assertCount(4, $bom);
|
||||
|
||||
$this->assertEquals('R19,R17', $bom[0]->getMountnames());
|
||||
$this->assertEquals(2.0, $bom[0]->getQuantity());
|
||||
$this->assertSame('R19,R17', $bom[0]->getMountnames());
|
||||
$this->assertSame(2.0, $bom[0]->getQuantity());
|
||||
$this->assertSame('4.7k (R_0805_2012Metric_Pad1.20x1.40mm_HandSolder)', $bom[0]->getName());
|
||||
$this->assertSame('Test', $bom[0]->getComment());
|
||||
}
|
||||
|
|
|
@ -57,33 +57,31 @@ class BarcodeNormalizerTest extends WebTestCase
|
|||
$this->service = self::getContainer()->get(BarcodeNormalizer::class);
|
||||
}
|
||||
|
||||
public function dataProvider(): array
|
||||
public function dataProvider(): \Iterator
|
||||
{
|
||||
return [
|
||||
//QR URL content:
|
||||
[['lot', 1], 'https://localhost:8000/scan/lot/1'],
|
||||
[['part', 123], 'https://localhost:8000/scan/part/123'],
|
||||
[['location', 4], 'http://foo.bar/part-db/scan/location/4'],
|
||||
[['under_score', 10], 'http://test/part-db/sub/scan/under_score/10/'],
|
||||
//Current Code39 format:
|
||||
[['lot', 10], 'L0010'],
|
||||
[['lot', 123], 'L0123'],
|
||||
[['lot', 123456], 'L123456'],
|
||||
[['part', 2], 'P0002'],
|
||||
//Development phase Code39 barcodes:
|
||||
[['lot', 10], 'L-000010'],
|
||||
[['lot', 10], 'Lß000010'],
|
||||
[['part', 123], 'P-000123'],
|
||||
[['location', 123], 'S-000123'],
|
||||
[['lot', 12_345_678], 'L-12345678'],
|
||||
//Legacy storelocation format
|
||||
[['location', 336], '$L00336'],
|
||||
[['location', 12_345_678], '$L12345678'],
|
||||
//Legacy Part format
|
||||
[['part', 123], '0000123'],
|
||||
[['part', 123], '00001236'],
|
||||
[['part', 1_234_567], '12345678'],
|
||||
];
|
||||
//QR URL content:
|
||||
yield [['lot', 1], 'https://localhost:8000/scan/lot/1'];
|
||||
yield [['part', 123], 'https://localhost:8000/scan/part/123'];
|
||||
yield [['location', 4], 'http://foo.bar/part-db/scan/location/4'];
|
||||
yield [['under_score', 10], 'http://test/part-db/sub/scan/under_score/10/'];
|
||||
//Current Code39 format:
|
||||
yield [['lot', 10], 'L0010'];
|
||||
yield [['lot', 123], 'L0123'];
|
||||
yield [['lot', 123456], 'L123456'];
|
||||
yield [['part', 2], 'P0002'];
|
||||
//Development phase Code39 barcodes:
|
||||
yield [['lot', 10], 'L-000010'];
|
||||
yield [['lot', 10], 'Lß000010'];
|
||||
yield [['part', 123], 'P-000123'];
|
||||
yield [['location', 123], 'S-000123'];
|
||||
yield [['lot', 12_345_678], 'L-12345678'];
|
||||
//Legacy storelocation format
|
||||
yield [['location', 336], '$L00336'];
|
||||
yield [['location', 12_345_678], '$L12345678'];
|
||||
//Legacy Part format
|
||||
yield [['part', 123], '0000123'];
|
||||
yield [['part', 123], '00001236'];
|
||||
yield [['part', 1_234_567], '12345678'];
|
||||
}
|
||||
|
||||
public function invalidDataProvider(): array
|
||||
|
|
|
@ -63,11 +63,9 @@ class AbstractElementProviderTest extends WebTestCase
|
|||
};
|
||||
}
|
||||
|
||||
public function dataProvider(): array
|
||||
public function dataProvider(): \Iterator
|
||||
{
|
||||
return [
|
||||
['123', '[[ID]]'],
|
||||
];
|
||||
yield ['123', '[[ID]]'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -61,12 +61,10 @@ class GlobalProvidersTest extends WebTestCase
|
|||
$this->target = new Part();
|
||||
}
|
||||
|
||||
public function dataProvider(): array
|
||||
public function dataProvider(): \Iterator
|
||||
{
|
||||
return [
|
||||
['Part-DB', '[[INSTALL_NAME]]'],
|
||||
['anonymous', '[[USERNAME]]'],
|
||||
];
|
||||
yield ['Part-DB', '[[INSTALL_NAME]]'];
|
||||
yield ['anonymous', '[[USERNAME]]'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -66,11 +66,9 @@ class NamedElementProviderTest extends WebTestCase
|
|||
};
|
||||
}
|
||||
|
||||
public function dataProvider(): array
|
||||
public function dataProvider(): \Iterator
|
||||
{
|
||||
return [
|
||||
['This is my Name', '[[NAME]]'],
|
||||
];
|
||||
yield ['This is my Name', '[[NAME]]'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -85,22 +85,20 @@ class PartLotProviderTest extends WebTestCase
|
|||
$this->target->setOwner($user);
|
||||
}
|
||||
|
||||
public function dataProvider(): array
|
||||
public function dataProvider(): \Iterator
|
||||
{
|
||||
return [
|
||||
['unknown', '[[LOT_ID]]'],
|
||||
['Lot description', '[[LOT_NAME]]'],
|
||||
['Lot comment', '[[LOT_COMMENT]]'],
|
||||
['4/13/99', '[[EXPIRATION_DATE]]'],
|
||||
['?', '[[AMOUNT]]'],
|
||||
['Location', '[[LOCATION]]'],
|
||||
['Parent → Location', '[[LOCATION_FULL]]'],
|
||||
//Test part inheritance
|
||||
['Part', '[[NAME]]'],
|
||||
['Part description', '[[DESCRIPTION]]'],
|
||||
['John Doe', '[[OWNER]]'],
|
||||
['user', '[[OWNER_USERNAME]]'],
|
||||
];
|
||||
yield ['unknown', '[[LOT_ID]]'];
|
||||
yield ['Lot description', '[[LOT_NAME]]'];
|
||||
yield ['Lot comment', '[[LOT_COMMENT]]'];
|
||||
yield ['4/13/99', '[[EXPIRATION_DATE]]'];
|
||||
yield ['?', '[[AMOUNT]]'];
|
||||
yield ['Location', '[[LOCATION]]'];
|
||||
yield ['Parent → Location', '[[LOCATION_FULL]]'];
|
||||
//Test part inheritance
|
||||
yield ['Part', '[[NAME]]'];
|
||||
yield ['Part description', '[[DESCRIPTION]]'];
|
||||
yield ['John Doe', '[[OWNER]]'];
|
||||
yield ['user', '[[OWNER_USERNAME]]'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -86,25 +86,22 @@ class PartProviderTest extends WebTestCase
|
|||
$this->target->setComment('<b>Bold</b> *Italic*');
|
||||
}
|
||||
|
||||
public function dataProvider(): array
|
||||
public function dataProvider(): \Iterator
|
||||
{
|
||||
return [
|
||||
['Node 2.1', '[[CATEGORY]]'],
|
||||
['Node 2 → Node 2.1', '[[CATEGORY_FULL]]'],
|
||||
['Node 2.1', '[[FOOTPRINT]]'],
|
||||
['Node 2 → Node 2.1', '[[FOOTPRINT_FULL]]'],
|
||||
['', '[[MANUFACTURER]]'],
|
||||
['', '[[MANUFACTURER_FULL]]'],
|
||||
|
||||
['1.2 kg', '[[MASS]]'],
|
||||
['MPN123', '[[MPN]]'],
|
||||
['SMD, Tag1, Tag2', '[[TAGS]]'],
|
||||
['Active', '[[M_STATUS]]'],
|
||||
['<b>Bold</b> <em>Italic</em>', '[[DESCRIPTION]]'],
|
||||
['Bold Italic', '[[DESCRIPTION_T]]'],
|
||||
['<b>Bold</b> <em>Italic</em>', '[[COMMENT]]'],
|
||||
['Bold Italic', '[[COMMENT_T]]'],
|
||||
];
|
||||
yield ['Node 2.1', '[[CATEGORY]]'];
|
||||
yield ['Node 2 → Node 2.1', '[[CATEGORY_FULL]]'];
|
||||
yield ['Node 2.1', '[[FOOTPRINT]]'];
|
||||
yield ['Node 2 → Node 2.1', '[[FOOTPRINT_FULL]]'];
|
||||
yield ['', '[[MANUFACTURER]]'];
|
||||
yield ['', '[[MANUFACTURER_FULL]]'];
|
||||
yield ['1.2 kg', '[[MASS]]'];
|
||||
yield ['MPN123', '[[MPN]]'];
|
||||
yield ['SMD, Tag1, Tag2', '[[TAGS]]'];
|
||||
yield ['Active', '[[M_STATUS]]'];
|
||||
yield ['<b>Bold</b> <em>Italic</em>', '[[DESCRIPTION]]'];
|
||||
yield ['Bold Italic', '[[DESCRIPTION_T]]'];
|
||||
yield ['<b>Bold</b> <em>Italic</em>', '[[COMMENT]]'];
|
||||
yield ['Bold Italic', '[[COMMENT_T]]'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -74,14 +74,11 @@ class TimestampableElementProviderTest extends WebTestCase
|
|||
};
|
||||
}
|
||||
|
||||
public function dataProvider(): array
|
||||
public function dataProvider(): \Iterator
|
||||
{
|
||||
\Locale::setDefault('en');
|
||||
|
||||
return [
|
||||
['1/1/00, 12:00 AM', '[[LAST_MODIFIED]]'],
|
||||
['1/1/00, 12:00 AM', '[[CREATION_DATE]]'],
|
||||
];
|
||||
yield ['1/1/00, 12:00 AM', '[[LAST_MODIFIED]]'];
|
||||
yield ['1/1/00, 12:00 AM', '[[CREATION_DATE]]'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -57,30 +57,28 @@ class RangeParserTest extends WebTestCase
|
|||
$this->service = self::getContainer()->get(RangeParser::class);
|
||||
}
|
||||
|
||||
public function dataProvider(): array
|
||||
public function dataProvider(): \Iterator
|
||||
{
|
||||
return [
|
||||
[[], ''],
|
||||
[[], ' '],
|
||||
[[], "\t"],
|
||||
[[1], '1'],
|
||||
[[1, 2, 3], '1,2, 3'],
|
||||
[[1, 2, 3], '1-3'],
|
||||
[[1, 2, 3, 4], '1- 3, 4'],
|
||||
[[1, 2, 3, 4], '1, 2,3 - 4'],
|
||||
[[1, 2, 3], ' 1; 2, 3'],
|
||||
[[-1, 0, 1, 2], '-1; 0; 1, 2'],
|
||||
[[4, 3, 1, 2], '4,3, 1;2'],
|
||||
[[1, 2, 3, 4], '2-1, 3-4'],
|
||||
[[1], '1-1'],
|
||||
[[-3, -2, -1], '-3--1'],
|
||||
[[1, 2, 3], '1,,2;;,,3'],
|
||||
[[100, 1000, 1], '100, 1000, 1'],
|
||||
[[], 'test', true],
|
||||
[[], '1-2-3-4,5', true],
|
||||
[[], '1 2 3, 455, 23', true],
|
||||
[[], '1, 2, test', true],
|
||||
];
|
||||
yield [[], ''];
|
||||
yield [[], ' '];
|
||||
yield [[], "\t"];
|
||||
yield [[1], '1'];
|
||||
yield [[1, 2, 3], '1,2, 3'];
|
||||
yield [[1, 2, 3], '1-3'];
|
||||
yield [[1, 2, 3, 4], '1- 3, 4'];
|
||||
yield [[1, 2, 3, 4], '1, 2,3 - 4'];
|
||||
yield [[1, 2, 3], ' 1; 2, 3'];
|
||||
yield [[-1, 0, 1, 2], '-1; 0; 1, 2'];
|
||||
yield [[4, 3, 1, 2], '4,3, 1;2'];
|
||||
yield [[1, 2, 3, 4], '2-1, 3-4'];
|
||||
yield [[1], '1-1'];
|
||||
yield [[-3, -2, -1], '-3--1'];
|
||||
yield [[1, 2, 3], '1,,2;;,,3'];
|
||||
yield [[100, 1000, 1], '100, 1000, 1'];
|
||||
yield [[], 'test', true];
|
||||
yield [[], '1-2-3-4,5', true];
|
||||
yield [[], '1 2 3, 455, 23', true];
|
||||
yield [[], '1, 2, test', true];
|
||||
}
|
||||
|
||||
public function validDataProvider(): array
|
||||
|
|
|
@ -117,15 +117,15 @@ class PartLotWithdrawAddHelperTest extends WebTestCase
|
|||
{
|
||||
//Add 5 to lot 1
|
||||
$this->service->add($this->partLot1, 5, "Test");
|
||||
$this->assertEquals(15, $this->partLot1->getAmount());
|
||||
$this->assertSame(15, $this->partLot1->getAmount());
|
||||
|
||||
//Add 3.2 to lot 2
|
||||
$this->service->add($this->partLot2, 3.2, "Test");
|
||||
$this->assertEquals(5, $this->partLot2->getAmount());
|
||||
$this->assertSame(5, $this->partLot2->getAmount());
|
||||
|
||||
//Add 1.5 to lot 3
|
||||
$this->service->add($this->partLot3, 1.5, "Test");
|
||||
$this->assertEquals(2, $this->partLot3->getAmount());
|
||||
$this->assertSame(2, $this->partLot3->getAmount());
|
||||
|
||||
}
|
||||
|
||||
|
@ -133,23 +133,23 @@ class PartLotWithdrawAddHelperTest extends WebTestCase
|
|||
{
|
||||
//Withdraw 5 from lot 1
|
||||
$this->service->withdraw($this->partLot1, 5, "Test");
|
||||
$this->assertEquals(5, $this->partLot1->getAmount());
|
||||
$this->assertSame(5, $this->partLot1->getAmount());
|
||||
|
||||
//Withdraw 2.2 from lot 2
|
||||
$this->service->withdraw($this->partLot2, 2.2, "Test");
|
||||
$this->assertEquals(0, $this->partLot2->getAmount());
|
||||
$this->assertSame(0, $this->partLot2->getAmount());
|
||||
}
|
||||
|
||||
public function testMove(): void
|
||||
{
|
||||
//Move 5 from lot 1 to lot 2
|
||||
$this->service->move($this->partLot1, $this->partLot2, 5, "Test");
|
||||
$this->assertEquals(5, $this->partLot1->getAmount());
|
||||
$this->assertEquals(7, $this->partLot2->getAmount());
|
||||
$this->assertSame(5, $this->partLot1->getAmount());
|
||||
$this->assertSame(7, $this->partLot2->getAmount());
|
||||
|
||||
//Move 2.2 from lot 2 to lot 3
|
||||
$this->service->move($this->partLot2, $this->partLot3, 2.2, "Test");
|
||||
$this->assertEquals(5, $this->partLot2->getAmount());
|
||||
$this->assertEquals(2, $this->partLot3->getAmount());
|
||||
$this->assertSame(5, $this->partLot2->getAmount());
|
||||
$this->assertSame(2, $this->partLot3->getAmount());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,12 +65,12 @@ class ProjectBuildHelperTest extends WebTestCase
|
|||
$project_bom_entry->setPart($part);
|
||||
|
||||
//We have 125 parts in stock, so we can build 12 times the project (125 / 10 = 12.5)
|
||||
$this->assertEquals(12, $this->service->getMaximumBuildableCountForBOMEntry($project_bom_entry));
|
||||
$this->assertSame(12, $this->service->getMaximumBuildableCountForBOMEntry($project_bom_entry));
|
||||
|
||||
|
||||
$lot1->setAmount(0);
|
||||
//We have 5 parts in stock, so we can build 0 times the project (5 / 10 = 0.5)
|
||||
$this->assertEquals(0, $this->service->getMaximumBuildableCountForBOMEntry($project_bom_entry));
|
||||
$this->assertSame(0, $this->service->getMaximumBuildableCountForBOMEntry($project_bom_entry));
|
||||
}
|
||||
|
||||
public function testGetMaximumBuildableCount(): void
|
||||
|
@ -101,15 +101,15 @@ class ProjectBuildHelperTest extends WebTestCase
|
|||
$project->addBomEntry((new ProjectBOMEntry())->setName('Non part entry')->setQuantity(1));
|
||||
|
||||
//Restricted by the few parts in stock of part2
|
||||
$this->assertEquals(2, $this->service->getMaximumBuildableCount($project));
|
||||
$this->assertSame(2, $this->service->getMaximumBuildableCount($project));
|
||||
|
||||
$lot3->setAmount(1000);
|
||||
//Now the build count is restricted by the few parts in stock of part1
|
||||
$this->assertEquals(12, $this->service->getMaximumBuildableCount($project));
|
||||
$this->assertSame(12, $this->service->getMaximumBuildableCount($project));
|
||||
|
||||
$lot3->setAmount(0);
|
||||
//Now the build count must be 0, as we have no parts in stock
|
||||
$this->assertEquals(0, $this->service->getMaximumBuildableCount($project));
|
||||
$this->assertSame(0, $this->service->getMaximumBuildableCount($project));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ class PermissionSchemaUpdaterTest extends WebTestCase
|
|||
|
||||
//With schema version 0, an update should be done and the schema version should be updated
|
||||
self::assertTrue($this->service->upgradeSchema($user));
|
||||
self::assertEquals(PermissionData::CURRENT_SCHEMA_VERSION, $user->getPermissions()->getSchemaVersion());
|
||||
self::assertSame(PermissionData::CURRENT_SCHEMA_VERSION, $user->getPermissions()->getSchemaVersion());
|
||||
|
||||
//If we redo it with the same schema version, no update should be done
|
||||
self::assertFalse($this->service->upgradeSchema($user));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue