This commit is contained in:
98
tests/Helper/HiltesImportTest.php
Normal file
98
tests/Helper/HiltesImportTest.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?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 = '/';
|
||||
|
||||
$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']));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user