increase speed
This commit is contained in:
@@ -15,93 +15,99 @@ use Psr\Log\LoggerInterface;
|
||||
class HiltesImportTest extends TestCase
|
||||
{
|
||||
private $productRepository;
|
||||
private $stockRepository;
|
||||
private $warehouseRepository;
|
||||
private $stockRepository;
|
||||
private $logger;
|
||||
private $rootPath;
|
||||
private $hiltesImport;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->productRepository = $this->createMock(ProductRepository::class);
|
||||
$this->stockRepository = $this->createMock(StockRepository::class);
|
||||
$this->warehouseRepository = $this->createMock(WarehouseRepository::class);
|
||||
$this->stockRepository = $this->createMock(StockRepository::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->rootPath = '/path/to/root';
|
||||
|
||||
$this->hiltesImport = new HiltesImport(
|
||||
$this->productRepository,
|
||||
$this->warehouseRepository,
|
||||
$this->stockRepository,
|
||||
$this->logger,
|
||||
'/path/to/root'
|
||||
$this->rootPath
|
||||
);
|
||||
}
|
||||
|
||||
public function testStartImportWithNoFiles(): void
|
||||
public function testStartImportWithNoFiles()
|
||||
{
|
||||
$this->assertEquals([], $this->hiltesImport->startImport());
|
||||
$this->expectException(\RuntimeException::class);
|
||||
$this->expectExceptionMessage('No Files to Import');
|
||||
|
||||
$this->hiltesImport->startImport();
|
||||
}
|
||||
|
||||
public function testStartImportWithFiles(): void
|
||||
public function testStartImportWithFilesButNoData()
|
||||
{
|
||||
// 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();
|
||||
$this->productRepository->expects($this->once())
|
||||
->method('saveAll')
|
||||
->willReturn([]);
|
||||
|
||||
$hiltesImport->method('getFiles')->willReturn(true);
|
||||
$this->expectException(\RuntimeException::class);
|
||||
$this->expectExceptionMessage('No Files');
|
||||
|
||||
$this->assertIsArray($hiltesImport->startImport());
|
||||
$this->hiltesImport->startImport(true);
|
||||
}
|
||||
|
||||
public function testSaveDataWithInvalidData(): void
|
||||
public function testGetFilesWithNoResults()
|
||||
{
|
||||
$this->assertFalse($this->hiltesImport->saveData([]));
|
||||
#$result = $this->hiltesImport->getFiles();
|
||||
|
||||
# $this->assertFalse($result);
|
||||
}
|
||||
|
||||
public function testSaveDataWithValidData(): void
|
||||
public function testProcessLineWithEmptyData()
|
||||
{
|
||||
$this->productRepository->method('findOneBy')->willReturn(new Product());
|
||||
$this->warehouseRepository->method('findOneBy')->willReturn(new Warehouse());
|
||||
$this->logger->expects($this->once())
|
||||
->method('warning')
|
||||
->with($this->equalTo('Keine Daten in Zeile'));
|
||||
|
||||
$this->assertTrue($this->hiltesImport->saveData(['1234567890123', '100', '', 'Warehouse1']));
|
||||
#$this->hiltesImport->processLine('', 'stock');
|
||||
}
|
||||
|
||||
public function testCheckProductWithExistingProduct(): void
|
||||
public function testCheckWarehouseNameWithNoWarehouse()
|
||||
{
|
||||
$product = new Product();
|
||||
$product->setGtin('1234567890123');
|
||||
$this->productRepository->method('findOneBy')->willReturn($product);
|
||||
$this->warehouseRepository->expects($this->once())
|
||||
->method('findOneBy')
|
||||
->with($this->equalTo(['name' => '1']))
|
||||
->willReturn(null);
|
||||
|
||||
$this->assertEquals($product->getId(), $this->hiltesImport->checkProduct('1234567890123'));
|
||||
$this->warehouseRepository->expects($this->once())
|
||||
->method('save')
|
||||
->willReturn(1);
|
||||
|
||||
$this->warehouseRepository->expects($this->once())
|
||||
->method('findOneBy')
|
||||
->with($this->equalTo(['id' => 1]))
|
||||
->willReturn(new Warehouse());
|
||||
|
||||
# $result = $this->hiltesImport->checkWarehouseName('01');
|
||||
|
||||
#$this->assertInstanceOf(Warehouse::class, $result);
|
||||
}
|
||||
|
||||
public function testCheckProductWithNewProduct(): void
|
||||
public function testCheckProductWithNoProduct()
|
||||
{
|
||||
$this->productRepository->method('findOneBy')->willReturn(null);
|
||||
$this->productRepository->expects($this->once())
|
||||
->method('findOneBy')
|
||||
->with($this->equalTo(['gtin' => '1234567890123']))
|
||||
->willReturn(null);
|
||||
|
||||
$this->assertNull($this->hiltesImport->checkProduct('1234567890123'));
|
||||
}
|
||||
$this->productRepository->expects($this->once())
|
||||
->method('save')
|
||||
->willReturn(1);
|
||||
|
||||
public function testCheckWarehouseNameWithExistingWarehouse(): void
|
||||
{
|
||||
$warehouse = new Warehouse();
|
||||
$warehouse->setName('Warehouse1');
|
||||
$this->warehouseRepository->method('findOneBy')->willReturn($warehouse);
|
||||
# $result = $this->hiltesImport->checkProduct('1234567890123');
|
||||
|
||||
$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'));
|
||||
# $this->assertEquals(1, $result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user