CdsConnector/tests/Helper/HiltesImportTest.php

113 lines
3.2 KiB
PHP
Raw Permalink Normal View History

2023-12-15 17:51:24 +01:00
<?php
namespace App\Tests\Helper;
use App\Entity\Product;
use App\Entity\Stock;
use App\Entity\Warehouse;
use App\Helper\HiltesImport;
use App\Repository\ProductRepository;
use App\Repository\StockRepository;
use App\Repository\WarehouseRepository;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
class HiltesImportTest extends TestCase
{
private $productRepository;
2024-03-01 10:15:12 +01:00
private $warehouseRepository;
2024-03-14 11:53:11 +01:00
private $stockRepository;
2023-12-15 17:51:24 +01:00
private $logger;
2024-03-14 11:53:11 +01:00
private $rootPath;
2023-12-15 17:51:24 +01:00
private $hiltesImport;
protected function setUp(): void
{
$this->productRepository = $this->createMock(ProductRepository::class);
2024-03-01 10:15:12 +01:00
$this->warehouseRepository = $this->createMock(WarehouseRepository::class);
2024-03-14 11:53:11 +01:00
$this->stockRepository = $this->createMock(StockRepository::class);
2023-12-15 17:51:24 +01:00
$this->logger = $this->createMock(LoggerInterface::class);
2024-03-14 11:53:11 +01:00
$this->rootPath = '/path/to/root';
2023-12-15 17:51:24 +01:00
$this->hiltesImport = new HiltesImport(
$this->productRepository,
$this->warehouseRepository,
$this->stockRepository,
$this->logger,
2024-03-14 11:53:11 +01:00
$this->rootPath
2023-12-15 17:51:24 +01:00
);
}
2024-03-14 11:53:11 +01:00
public function testStartImportWithNoFiles()
2023-12-15 17:51:24 +01:00
{
2024-03-14 11:53:11 +01:00
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('No Files to Import');
2023-12-15 17:51:24 +01:00
2024-03-14 11:53:11 +01:00
$this->hiltesImport->startImport();
2023-12-15 17:51:24 +01:00
}
2024-03-14 11:53:11 +01:00
public function testStartImportWithFilesButNoData()
2023-12-15 17:51:24 +01:00
{
2024-03-14 11:53:11 +01:00
$this->productRepository->expects($this->once())
->method('saveAll')
->willReturn([]);
2023-12-15 17:51:24 +01:00
2024-03-14 11:53:11 +01:00
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('No Files');
2023-12-15 17:51:24 +01:00
2024-03-14 11:53:11 +01:00
$this->hiltesImport->startImport(true);
2023-12-15 17:51:24 +01:00
}
2024-03-14 11:53:11 +01:00
public function testGetFilesWithNoResults()
2023-12-15 17:51:24 +01:00
{
2024-03-14 11:53:11 +01:00
#$result = $this->hiltesImport->getFiles();
2024-03-01 10:15:12 +01:00
2024-03-14 11:53:11 +01:00
# $this->assertFalse($result);
2024-03-01 10:15:12 +01:00
}
2023-12-15 17:51:24 +01:00
2024-03-14 11:53:11 +01:00
public function testProcessLineWithEmptyData()
2024-03-01 10:15:12 +01:00
{
2024-03-14 11:53:11 +01:00
$this->logger->expects($this->once())
->method('warning')
->with($this->equalTo('Keine Daten in Zeile'));
2024-03-01 10:15:12 +01:00
2024-03-14 11:53:11 +01:00
#$this->hiltesImport->processLine('', 'stock');
2024-03-01 10:15:12 +01:00
}
2024-03-14 11:53:11 +01:00
public function testCheckWarehouseNameWithNoWarehouse()
2024-03-01 10:15:12 +01:00
{
2024-03-14 11:53:11 +01:00
$this->warehouseRepository->expects($this->once())
->method('findOneBy')
->with($this->equalTo(['name' => '1']))
->willReturn(null);
$this->warehouseRepository->expects($this->once())
->method('save')
->willReturn(1);
$this->warehouseRepository->expects($this->once())
->method('findOneBy')
->with($this->equalTo(['id' => 1]))
->willReturn(new Warehouse());
2023-12-15 17:51:24 +01:00
2024-03-14 11:53:11 +01:00
# $result = $this->hiltesImport->checkWarehouseName('01');
#$this->assertInstanceOf(Warehouse::class, $result);
2024-03-01 10:15:12 +01:00
}
2024-03-14 11:53:11 +01:00
public function testCheckProductWithNoProduct()
2024-03-01 10:15:12 +01:00
{
2024-03-14 11:53:11 +01:00
$this->productRepository->expects($this->once())
->method('findOneBy')
->with($this->equalTo(['gtin' => '1234567890123']))
->willReturn(null);
$this->productRepository->expects($this->once())
->method('save')
->willReturn(1);
# $result = $this->hiltesImport->checkProduct('1234567890123');
2023-12-15 17:51:24 +01:00
2024-03-14 11:53:11 +01:00
# $this->assertEquals(1, $result);
2023-12-15 17:51:24 +01:00
}
}