This commit is contained in:
web-devinition.de 2026-01-13 01:09:39 +06:00 committed by GitHub
commit 30840ac8b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
136 changed files with 23994 additions and 112 deletions

View file

@ -29,7 +29,7 @@ use App\Entity\ProjectSystem\ProjectBOMEntry;
use App\Services\ImportExportSystem\BOMImporter;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
class BOMImporterTest extends WebTestCase
{
@ -62,15 +62,17 @@ class BOMImporterTest extends WebTestCase
4;"C6";"CP_Radial_D6.3mm_P2.50mm";1;"47uF";;;
CSV;
$file = $this->createMock(File::class);
$file = $this->createMock(UploadedFile::class);
$file->method('getContent')->willReturn($input);
$file->method('getClientOriginalName')->willReturn('import.kicad_pcb');
$file->method('getClientOriginalExtension')->willReturn('kicad_pcb');
$project = new Project();
$this->assertCount(0, $project->getBOMEntries());
$bom_entries = $this->service->importFileIntoProject($file, $project, ['type' => 'kicad_pcbnew']);
$this->assertContainsOnlyInstancesOf(ProjectBOMEntry::class, $bom_entries);
$this->assertCount(4, $bom_entries);
$importerResult = $this->service->importFileIntoProject($file, $project, ['type' => 'kicad_pcbnew']);
$this->assertContainsOnlyInstancesOf(ProjectBOMEntry::class, $importerResult->getBomEntries());
$this->assertCount(4, $importerResult->getBomEntries());
//Check that the BOM entries are added to the project
$this->assertCount(4, $project->getBOMEntries());
@ -87,7 +89,8 @@ class BOMImporterTest extends WebTestCase
4;"C6";"CP_Radial_D6.3mm_P2.50mm";1;"47uF";;;
CSV;
$bom = $this->service->stringToBOMEntries($input, ['type' => 'kicad_pcbnew']);
$project = new Project();
$bom = $this->service->stringToBOMEntries($project, $input, ['type' => 'kicad_pcbnew']);
$this->assertContainsOnlyInstancesOf(ProjectBOMEntry::class, $bom);
$this->assertCount(4, $bom);
@ -106,7 +109,8 @@ class BOMImporterTest extends WebTestCase
4;"C6";"CP_Radial_D6.3mm_P2.50mm";1;"47uF";;;
CSV;
$bom = $this->service->stringToBOMEntries($input, ['type' => 'kicad_pcbnew']);
$project = new Project();
$bom = $this->service->stringToBOMEntries($project, $input, ['type' => 'kicad_pcbnew']);
$this->assertContainsOnlyInstancesOf(ProjectBOMEntry::class, $bom);
$this->assertCount(4, $bom);
@ -126,7 +130,8 @@ class BOMImporterTest extends WebTestCase
$this->expectException(\UnexpectedValueException::class);
$this->service->stringToBOMEntries($input, ['type' => 'kicad_pcbnew']);
$project = new Project();
$this->service->stringToBOMEntries($project, $input, ['type' => 'kicad_pcbnew']);
}
public function testDetectFields(): void
@ -370,7 +375,8 @@ class BOMImporterTest extends WebTestCase
'Mouser SPN' => 'Mouser SPN'
];
$bom_entries = $this->service->stringToBOMEntries($input, [
$project = new Project();
$bom_entries = $this->service->stringToBOMEntries($project, $input, [
'type' => 'kicad_schematic',
'field_mapping' => $field_mapping,
'delimiter' => ','
@ -413,7 +419,8 @@ class BOMImporterTest extends WebTestCase
'MPN2' => 2
];
$bom_entries = $this->service->stringToBOMEntries($input, [
$project = new Project();
$bom_entries = $this->service->stringToBOMEntries($project, $input, [
'type' => 'kicad_schematic',
'field_mapping' => $field_mapping,
'field_priorities' => $field_priorities,
@ -451,7 +458,8 @@ class BOMImporterTest extends WebTestCase
'Quantity' => 'Quantity'
];
$bom_entries = $this->service->stringToBOMEntries($input, [
$project = new Project();
$bom_entries = $this->service->stringToBOMEntries($project, $input, [
'type' => 'kicad_schematic',
'field_mapping' => $field_mapping,
'delimiter' => ','
@ -483,7 +491,8 @@ class BOMImporterTest extends WebTestCase
'Quantity' => 'Quantity'
];
$bom_entries = $this->service->stringToBOMEntries($input, [
$project = new Project();
$bom_entries = $this->service->stringToBOMEntries($project, $input, [
'type' => 'kicad_schematic',
'field_mapping' => $field_mapping,
'delimiter' => ','
@ -512,7 +521,8 @@ class BOMImporterTest extends WebTestCase
'Quantity' => 'Quantity'
];
$bom_entries = $this->service->stringToBOMEntries($input, [
$project = new Project();
$bom_entries = $this->service->stringToBOMEntries($project, $input, [
'type' => 'kicad_schematic',
'field_mapping' => $field_mapping,
'delimiter' => ','
@ -541,7 +551,8 @@ class BOMImporterTest extends WebTestCase
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('Required field "Designator" is missing or empty');
$this->service->stringToBOMEntries($input, [
$project = new Project();
$this->service->stringToBOMEntries($project, $input, [
'type' => 'kicad_schematic',
'field_mapping' => $field_mapping,
'delimiter' => ','
@ -564,7 +575,8 @@ class BOMImporterTest extends WebTestCase
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('Mismatch between quantity and component references');
$this->service->stringToBOMEntries($input, [
$project = new Project();
$this->service->stringToBOMEntries($project, $input, [
'type' => 'kicad_schematic',
'field_mapping' => $field_mapping,
'delimiter' => ','
@ -585,7 +597,8 @@ class BOMImporterTest extends WebTestCase
'Quantity' => 'Quantity'
];
$bom_entries = $this->service->stringToBOMEntries($input, [
$project = new Project();
$bom_entries = $this->service->stringToBOMEntries($project, $input, [
'type' => 'kicad_schematic',
'field_mapping' => $field_mapping,
'delimiter' => ','