productRepository = $this->createMock(ProductRepository::class); $this->warehouseRepository = $this->createMock(WarehouseRepository::class); $this->stockRepository = $this->createMock(StockRepository::class); $this->logger = $this->createMock(LoggerInterface::class); $this->rootPath = '/'; $this->hiltesImport = new HiltesImport( $this->productRepository, $this->warehouseRepository, $this->stockRepository, $this->logger, $this->rootPath ); } public function testStartImportWithNoFiles() { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('No Files to Import'); $this->hiltesImport->startImport(); } public function testStartImportWithFiles() { // Mock the getFiles method to return true $hiltesImport = $this->getMockBuilder(HiltesImport::class) ->setConstructorArgs([ $this->productRepository, $this->warehouseRepository, $this->stockRepository, $this->logger, $this->rootPath ]) ->onlyMethods(['getFiles']) ->getMock(); $hiltesImport->method('getFiles')->willReturn(true); $this->assertNull($hiltesImport->startImport()); } public function testGetFilesWithNoResults() { $this->assertFalse($this->hiltesImport->getFiles()); } public function testSaveDataWithNoWarehouse() { $this->logger->expects($this->once()) ->method('error') ->with('No Warehouse'); $this->assertFalse($this->hiltesImport->saveData(['product1', '100'])); } public function testSaveDataWithValidData() { $warehouse = new Warehouse(); $warehouse->setName('Warehouse1'); $product = new Product(); $product->setGtin('product1'); $this->warehouseRepository->method('findOneBy')->willReturn($warehouse); $this->productRepository->method('findOneBy')->willReturn($product); $this->stockRepository->expects($this->once()) ->method('save'); $this->assertTrue($this->hiltesImport->saveData(['product1', '100', '', 'Warehouse1'])); } }