. */ namespace App\Tests\Services\ImportExportSystem; use App\Entity\ProjectSystem\Project; use App\Entity\ProjectSystem\ProjectBOMEntry; use App\Services\ImportExportSystem\BOMImporter; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Component\HttpFoundation\File\File; class BOMImporterTest extends WebTestCase { /** * @var BOMImporter */ protected $service; protected function setUp(): void { //Get a service instance. self::bootKernel(); $this->service = self::getContainer()->get(BOMImporter::class); } public function testImportFileIntoProject(): void { $input = <<createMock(File::class); $file->method('getContent')->willReturn($input); $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); //Check that the BOM entries are added to the project $this->assertCount(4, $project->getBOMEntries()); } public function testStringToBOMEntriesKiCADPCB(): void { //Test for german input $input = <<service->stringToBOMEntries($input, ['type' => 'kicad_pcbnew']); $this->assertContainsOnlyInstancesOf(ProjectBOMEntry::class, $bom); $this->assertCount(4, $bom); $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()); //Test for english input $input = <<service->stringToBOMEntries($input, ['type' => 'kicad_pcbnew']); $this->assertContainsOnlyInstancesOf(ProjectBOMEntry::class, $bom); $this->assertCount(4, $bom); $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()); } public function testStringToBOMEntriesKiCADPCBError(): void { $input = <<expectException(\UnexpectedValueException::class); $this->service->stringToBOMEntries($input, ['type' => 'kicad_pcbnew']); } }