mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-01-13 05:39:33 +00:00
Assemblies einführen
This commit is contained in:
parent
e1418dfdc1
commit
6fa960df42
107 changed files with 14101 additions and 96 deletions
|
|
@ -24,6 +24,8 @@ namespace App\Tests\Entity\Attachments;
|
|||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Depends;
|
||||
use App\Entity\AssemblySystem\Assembly;
|
||||
use App\Entity\Attachments\AssemblyAttachment;
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use App\Entity\Attachments\AttachmentType;
|
||||
use App\Entity\Attachments\AttachmentTypeAttachment;
|
||||
|
|
@ -81,6 +83,7 @@ class AttachmentTest extends TestCase
|
|||
yield [CategoryAttachment::class, Category::class];
|
||||
yield [CurrencyAttachment::class, Currency::class];
|
||||
yield [ProjectAttachment::class, Project::class];
|
||||
yield [AssemblyAttachment::class, Assembly::class];
|
||||
yield [FootprintAttachment::class, Footprint::class];
|
||||
yield [GroupAttachment::class, Group::class];
|
||||
yield [ManufacturerAttachment::class, Manufacturer::class];
|
||||
|
|
|
|||
177
tests/Helpers/Assemblies/AssemblyBuildRequestTest.php
Normal file
177
tests/Helpers/Assemblies/AssemblyBuildRequestTest.php
Normal file
|
|
@ -0,0 +1,177 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2023 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* 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\Helpers\Assemblies;
|
||||
|
||||
use App\Entity\Parts\MeasurementUnit;
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Entity\Parts\PartLot;
|
||||
use App\Entity\AssemblySystem\Assembly;
|
||||
use App\Entity\AssemblySystem\AssemblyBOMEntry;
|
||||
use App\Helpers\Assemblies\AssemblyBuildRequest;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AssemblyBuildRequestTest extends TestCase
|
||||
{
|
||||
|
||||
/** @var MeasurementUnit $float_unit */
|
||||
private MeasurementUnit $float_unit;
|
||||
|
||||
/** @var Assembly */
|
||||
private Assembly $assembly1;
|
||||
/** @var AssemblyBOMEntry */
|
||||
private AssemblyBOMEntry $bom_entry1a;
|
||||
/** @var AssemblyBOMEntry */
|
||||
private AssemblyBOMEntry $bom_entry1b;
|
||||
/** @var AssemblyBOMEntry */
|
||||
private AssemblyBOMEntry $bom_entry1c;
|
||||
|
||||
private PartLot $lot1a;
|
||||
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);
|
||||
|
||||
//Setup some example parts and part lots
|
||||
$this->part1 = new Part();
|
||||
$this->part1->setName('Part 1');
|
||||
$this->lot1a = new class extends PartLot {
|
||||
public function getID(): ?int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
$this->part1->addPartLot($this->lot1a);
|
||||
$this->lot1a->setAmount(10);
|
||||
$this->lot1a->setDescription('Lot 1a');
|
||||
|
||||
$this->lot1b = new class extends PartLot {
|
||||
public function getID(): ?int
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
$this->part1->addPartLot($this->lot1b);
|
||||
$this->lot1b->setAmount(20);
|
||||
$this->lot1b->setDescription('Lot 1b');
|
||||
|
||||
$this->part2 = new Part();
|
||||
|
||||
$this->part2->setName('Part 2');
|
||||
$this->part2->setPartUnit($this->float_unit);
|
||||
$this->lot2 = new PartLot();
|
||||
$this->part2->addPartLot($this->lot2);
|
||||
$this->lot2->setAmount(2.5);
|
||||
$this->lot2->setDescription('Lot 2');
|
||||
|
||||
$this->bom_entry1a = new AssemblyBOMEntry();
|
||||
$this->bom_entry1a->setPart($this->part1);
|
||||
$this->bom_entry1a->setQuantity(2);
|
||||
|
||||
$this->bom_entry1b = new AssemblyBOMEntry();
|
||||
$this->bom_entry1b->setPart($this->part2);
|
||||
$this->bom_entry1b->setQuantity(1.5);
|
||||
|
||||
$this->bom_entry1c = new AssemblyBOMEntry();
|
||||
$this->bom_entry1c->setName('Non-part BOM entry');
|
||||
$this->bom_entry1c->setQuantity(4);
|
||||
|
||||
|
||||
$this->assembly1 = new Assembly();
|
||||
$this->assembly1->setName('Assembly 1');
|
||||
$this->assembly1->addBomEntry($this->bom_entry1a);
|
||||
$this->assembly1->addBomEntry($this->bom_entry1b);
|
||||
$this->assembly1->addBomEntry($this->bom_entry1c);
|
||||
}
|
||||
|
||||
public function testInitialization(): void
|
||||
{
|
||||
//The values should be already prefilled correctly
|
||||
$request = new AssemblyBuildRequest($this->assembly1, 10);
|
||||
//We need totally 20: Take 10 from the first (maximum 10) and 10 from the second (maximum 20)
|
||||
$this->assertEqualsWithDelta(10.0, $request->getLotWithdrawAmount($this->lot1a), PHP_FLOAT_EPSILON);
|
||||
$this->assertEqualsWithDelta(10.0, $request->getLotWithdrawAmount($this->lot1b), PHP_FLOAT_EPSILON);
|
||||
|
||||
//If the needed amount is higher than the maximum, we should get the maximum
|
||||
$this->assertEqualsWithDelta(2.5, $request->getLotWithdrawAmount($this->lot2), PHP_FLOAT_EPSILON);
|
||||
}
|
||||
|
||||
public function testGetNumberOfBuilds(): void
|
||||
{
|
||||
$build_request = new AssemblyBuildRequest($this->assembly1, 5);
|
||||
$this->assertSame(5, $build_request->getNumberOfBuilds());
|
||||
}
|
||||
|
||||
public function testGetAssembly(): void
|
||||
{
|
||||
$build_request = new AssemblyBuildRequest($this->assembly1, 5);
|
||||
$this->assertEquals($this->assembly1, $build_request->getAssembly());
|
||||
}
|
||||
|
||||
public function testGetNeededAmountForBOMEntry(): void
|
||||
{
|
||||
$build_request = new AssemblyBuildRequest($this->assembly1, 5);
|
||||
$this->assertEqualsWithDelta(10.0, $build_request->getNeededAmountForBOMEntry($this->bom_entry1a), PHP_FLOAT_EPSILON);
|
||||
$this->assertEqualsWithDelta(7.5, $build_request->getNeededAmountForBOMEntry($this->bom_entry1b), PHP_FLOAT_EPSILON);
|
||||
$this->assertEqualsWithDelta(20.0, $build_request->getNeededAmountForBOMEntry($this->bom_entry1c), PHP_FLOAT_EPSILON);
|
||||
}
|
||||
|
||||
public function testGetSetLotWithdrawAmount(): void
|
||||
{
|
||||
$build_request = new AssemblyBuildRequest($this->assembly1, 5);
|
||||
|
||||
//We can set the amount for a lot either via the lot object or via the ID
|
||||
$build_request->setLotWithdrawAmount($this->lot1a, 2);
|
||||
$build_request->setLotWithdrawAmount($this->lot1b->getID(), 3);
|
||||
|
||||
//And it should be possible to get the amount via the lot object or via the ID
|
||||
$this->assertEqualsWithDelta(2.0, $build_request->getLotWithdrawAmount($this->lot1a->getID()), PHP_FLOAT_EPSILON);
|
||||
$this->assertEqualsWithDelta(3.0, $build_request->getLotWithdrawAmount($this->lot1b), PHP_FLOAT_EPSILON);
|
||||
}
|
||||
|
||||
public function testGetWithdrawAmountSum(): void
|
||||
{
|
||||
//The sum of all withdraw amounts for an BOM entry (over all lots of the associated part) should be correct
|
||||
$build_request = new AssemblyBuildRequest($this->assembly1, 5);
|
||||
|
||||
$build_request->setLotWithdrawAmount($this->lot1a, 2);
|
||||
$build_request->setLotWithdrawAmount($this->lot1b, 3);
|
||||
|
||||
$this->assertEqualsWithDelta(5.0, $build_request->getWithdrawAmountSum($this->bom_entry1a), PHP_FLOAT_EPSILON);
|
||||
$build_request->setLotWithdrawAmount($this->lot2, 1.5);
|
||||
$this->assertEqualsWithDelta(1.5, $build_request->getWithdrawAmountSum($this->bom_entry1b), PHP_FLOAT_EPSILON);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
117
tests/Services/AssemblySystem/AssemblyBuildHelperTest.php
Normal file
117
tests/Services/AssemblySystem/AssemblyBuildHelperTest.php
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2023 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* 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\AssemblySystem;
|
||||
|
||||
use App\Entity\AssemblySystem\Assembly;
|
||||
use App\Entity\AssemblySystem\AssemblyBOMEntry;
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Entity\Parts\PartLot;
|
||||
use App\Services\AssemblySystem\AssemblyBuildHelper;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class AssemblyBuildHelperTest extends WebTestCase
|
||||
{
|
||||
/** @var AssemblyBuildHelper */
|
||||
protected $service;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
$this->service = self::getContainer()->get(AssemblyBuildHelper::class);
|
||||
}
|
||||
|
||||
public function testGetMaximumBuildableCountForBOMEntryNonPartBomEntry(): void
|
||||
{
|
||||
$bom_entry = new AssemblyBOMEntry();
|
||||
$bom_entry->setPart(null);
|
||||
$bom_entry->setQuantity(10);
|
||||
$bom_entry->setName('Test');
|
||||
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->service->getMaximumBuildableCountForBOMEntry($bom_entry);
|
||||
}
|
||||
|
||||
public function testGetMaximumBuildableCountForBOMEntry(): void
|
||||
{
|
||||
$assembly_bom_entry = new AssemblyBOMEntry();
|
||||
$assembly_bom_entry->setQuantity(10);
|
||||
|
||||
$part = new Part();
|
||||
$lot1 = new PartLot();
|
||||
$lot1->setAmount(120);
|
||||
$lot2 = new PartLot();
|
||||
$lot2->setAmount(5);
|
||||
$part->addPartLot($lot1);
|
||||
$part->addPartLot($lot2);
|
||||
|
||||
$assembly_bom_entry->setPart($part);
|
||||
|
||||
//We have 125 parts in stock, so we can build 12 times the assembly (125 / 10 = 12.5)
|
||||
$this->assertSame(12, $this->service->getMaximumBuildableCountForBOMEntry($assembly_bom_entry));
|
||||
|
||||
|
||||
$lot1->setAmount(0);
|
||||
//We have 5 parts in stock, so we can build 0 times the assembly (5 / 10 = 0.5)
|
||||
$this->assertSame(0, $this->service->getMaximumBuildableCountForBOMEntry($assembly_bom_entry));
|
||||
}
|
||||
|
||||
public function testGetMaximumBuildableCount(): void
|
||||
{
|
||||
$assembly = new Assembly();
|
||||
|
||||
$assembly_bom_entry1 = new AssemblyBOMEntry();
|
||||
$assembly_bom_entry1->setQuantity(10);
|
||||
$part = new Part();
|
||||
$lot1 = new PartLot();
|
||||
$lot1->setAmount(120);
|
||||
$lot2 = new PartLot();
|
||||
$lot2->setAmount(5);
|
||||
$part->addPartLot($lot1);
|
||||
$part->addPartLot($lot2);
|
||||
$assembly_bom_entry1->setPart($part);
|
||||
$assembly->addBomEntry($assembly_bom_entry1);
|
||||
|
||||
$assembly_bom_entry2 = new AssemblyBOMEntry();
|
||||
$assembly_bom_entry2->setQuantity(5);
|
||||
$part2 = new Part();
|
||||
$lot3 = new PartLot();
|
||||
$lot3->setAmount(10);
|
||||
$part2->addPartLot($lot3);
|
||||
$assembly_bom_entry2->setPart($part2);
|
||||
$assembly->addBomEntry($assembly_bom_entry2);
|
||||
|
||||
$assembly->addBomEntry((new AssemblyBOMEntry())->setName('Non part entry')->setQuantity(1));
|
||||
|
||||
//Restricted by the few parts in stock of part2
|
||||
$this->assertSame(2, $this->service->getMaximumBuildableCount($assembly));
|
||||
|
||||
$lot3->setAmount(1000);
|
||||
//Now the build count is restricted by the few parts in stock of part1
|
||||
$this->assertSame(12, $this->service->getMaximumBuildableCount($assembly));
|
||||
|
||||
$lot3->setAmount(0);
|
||||
//Now the build count must be 0, as we have no parts in stock
|
||||
$this->assertSame(0, $this->service->getMaximumBuildableCount($assembly));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2023 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* 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\AssemblySystem;
|
||||
|
||||
use App\Entity\AssemblySystem\Assembly;
|
||||
use App\Services\AssemblySystem\AssemblyBuildPartHelper;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class AssemblyBuildPartHelperTest extends WebTestCase
|
||||
{
|
||||
/** @var AssemblyBuildPartHelper */
|
||||
protected $service;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
$this->service = self::getContainer()->get(AssemblyBuildPartHelper::class);
|
||||
}
|
||||
|
||||
public function testGetPartInitialization(): void
|
||||
{
|
||||
$assembly = new Assembly();
|
||||
$assembly->setName('Assembly 1');
|
||||
$assembly->setDescription('Description 1');
|
||||
|
||||
$part = $this->service->getPartInitialization($assembly);
|
||||
$this->assertSame('Assembly 1', $part->getName());
|
||||
$this->assertSame('Description 1', $part->getDescription());
|
||||
$this->assertSame($assembly, $part->getBuiltAssembly());
|
||||
$this->assertSame($part, $assembly->getBuildPart());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue