113 lines
3.2 KiB
PHP
113 lines
3.2 KiB
PHP
<?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;
|
|
private $warehouseRepository;
|
|
private $stockRepository;
|
|
private $logger;
|
|
private $rootPath;
|
|
private $hiltesImport;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->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 = '/path/to/root';
|
|
|
|
$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 testStartImportWithFilesButNoData()
|
|
{
|
|
$this->productRepository->expects($this->once())
|
|
->method('saveAll')
|
|
->willReturn([]);
|
|
|
|
$this->expectException(\RuntimeException::class);
|
|
$this->expectExceptionMessage('No Files');
|
|
|
|
$this->hiltesImport->startImport(true);
|
|
}
|
|
|
|
public function testGetFilesWithNoResults()
|
|
{
|
|
#$result = $this->hiltesImport->getFiles();
|
|
|
|
# $this->assertFalse($result);
|
|
}
|
|
|
|
public function testProcessLineWithEmptyData()
|
|
{
|
|
$this->logger->expects($this->once())
|
|
->method('warning')
|
|
->with($this->equalTo('Keine Daten in Zeile'));
|
|
|
|
#$this->hiltesImport->processLine('', 'stock');
|
|
}
|
|
|
|
public function testCheckWarehouseNameWithNoWarehouse()
|
|
{
|
|
$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());
|
|
|
|
# $result = $this->hiltesImport->checkWarehouseName('01');
|
|
|
|
#$this->assertInstanceOf(Warehouse::class, $result);
|
|
}
|
|
|
|
public function testCheckProductWithNoProduct()
|
|
{
|
|
$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');
|
|
|
|
# $this->assertEquals(1, $result);
|
|
}
|
|
} |