productRepository = $this->createMock(ProductRepository::class); $this->stockRepository = $this->createMock(StockRepository::class); $this->warehouseRepository = $this->createMock(WarehouseRepository::class); $this->logger = $this->createMock(LoggerInterface::class); $this->hiltesImport = new HiltesImport( $this->productRepository, $this->warehouseRepository, $this->stockRepository, $this->logger, '/path/to/root' ); } public function testStartImportWithNoFiles(): void { $this->assertEquals([], $this->hiltesImport->startImport()); } public function testStartImportWithFiles(): void { // Mock the getFiles method to return true $hiltesImport = $this->getMockBuilder(HiltesImport::class) ->setConstructorArgs([ $this->productRepository, $this->warehouseRepository, $this->stockRepository, $this->logger, '/path/to/root' ]) ->onlyMethods(['getFiles']) ->getMock(); $hiltesImport->method('getFiles')->willReturn(true); $this->assertIsArray($hiltesImport->startImport()); } public function testSaveDataWithInvalidData(): void { $this->assertFalse($this->hiltesImport->saveData([])); } public function testSaveDataWithValidData(): void { $this->productRepository->method('findOneBy')->willReturn(new Product()); $this->warehouseRepository->method('findOneBy')->willReturn(new Warehouse()); $this->assertTrue($this->hiltesImport->saveData(['1234567890123', '100', '', 'Warehouse1'])); } public function testCheckProductWithExistingProduct(): void { $product = new Product(); $product->setGtin('1234567890123'); $this->productRepository->method('findOneBy')->willReturn($product); $this->assertEquals($product->getId(), $this->hiltesImport->checkProduct('1234567890123')); } public function testCheckProductWithNewProduct(): void { $this->productRepository->method('findOneBy')->willReturn(null); $this->assertNull($this->hiltesImport->checkProduct('1234567890123')); } public function testCheckWarehouseNameWithExistingWarehouse(): void { $warehouse = new Warehouse(); $warehouse->setName('Warehouse1'); $this->warehouseRepository->method('findOneBy')->willReturn($warehouse); $this->assertEquals($warehouse, $this->hiltesImport->checkWarehouseName('Warehouse1')); } public function testCheckWarehouseNameWithNewWarehouse(): void { $this->warehouseRepository->method('findOneBy')->willReturn(null); $this->assertInstanceOf(Warehouse::class, $this->hiltesImport->checkWarehouseName('Warehouse1')); } }