public function testSplitGenerateOutputFiles()
 {
     $outputDir = '/tmp/';
     $outputName = 'output';
     $items = array(array('sku', 'qty'), array('teste', '4'), array('teste1', '5'), array('teste2', '6'), array('teste3', '7'), array('teste4', '8'), array('teste5', '9'), array('teste6', '4'), array('teste7', '7'));
     $currentFilename = '/tmp/' . $outputName;
     $csvFile = $this->getMockBuilder('Keboola\\Csv\\CsvFile')->disableOriginalConstructor()->getMock();
     $csvFile->expects($this->at(0))->method('getHeader')->will($this->returnValue($items[0]));
     $csvFileMock = $this->iteratorHelper($csvFile, $items, 1);
     $csvFileHandlerMock = m::mock('Helpers\\CSV\\CsvHandler');
     $csvFileHandlerMock->shouldReceive('writeRow')->with($currentFilename . '1.csv', $items[0]);
     $csvFileHandlerMock->shouldReceive('writeRow')->with($currentFilename . '1.csv', $items[1]);
     $csvFileHandlerMock->shouldReceive('writeRow')->with($currentFilename . '2.csv', $items[0]);
     $csvFileHandlerMock->shouldReceive('writeRow')->with($currentFilename . '2.csv', $items[2]);
     $csvFileHandlerMock->shouldReceive('writeRow')->with($currentFilename . '2.csv', $items[3]);
     $csvFileHandlerMock->shouldReceive('writeRow')->with($currentFilename . '3.csv', $items[0]);
     $csvFileHandlerMock->shouldReceive('writeRow')->with($currentFilename . '3.csv', $items[4]);
     $csvFileHandlerMock->shouldReceive('writeRow')->with($currentFilename . '3.csv', $items[5]);
     $csvFileHandlerMock->shouldReceive('writeRow')->with($currentFilename . '4.csv', $items[0]);
     $csvFileHandlerMock->shouldReceive('writeRow')->with($currentFilename . '4.csv', $items[6]);
     $csvFileHandlerMock->shouldReceive('writeRow')->with($currentFilename . '4.csv', $items[7]);
     $csvFileHandlerMock->shouldReceive('writeRow')->with($currentFilename . '5.csv', $items[0]);
     $csvFileHandlerMock->shouldReceive('writeRow')->with($currentFilename . '5.csv', $items[8]);
     $fileHandlerMock = m::mock('stdClass');
     $fileHandlerMock->shouldReceive('exists')->andReturn(true);
     $fileHandlerMock->shouldReceive('touch')->with($currentFilename . '1.csv');
     $fileHandlerMock->shouldReceive('touch')->with($currentFilename . '2.csv');
     $fileHandlerMock->shouldReceive('touch')->with($currentFilename . '3.csv');
     $fileHandlerMock->shouldReceive('touch')->with($currentFilename . '4.csv');
     $fileHandlerMock->shouldReceive('touch')->with($currentFilename . '5.csv');
     $csvSplitter = new CsvSplitter($csvFileMock, $outputDir);
     $csvSplitter->setCsvHandler($csvFileHandlerMock);
     $csvSplitter->setFileHandler($fileHandlerMock);
     $csvSplitter->split(2);
 }
<?php

require_once __DIR__ . '/../config/config.php';
use Helpers\CSV\CsvSplitter;
use Keboola\Csv\CsvFile;
$splitter = new CsvSplitter(new CsvFile(__DIR__ . '/../../sample.csv'), __DIR__ . '/tmp/output/');
$splitter->split(5);
$splitter->clearOutputFiles();
    $fileName = $app->request()->params('filename');
    $locker = new ProcessLocker($config['lock_file']);
    if (!$locker->isLocked()) {
        $splitter = new CsvSplitter(new CsvFile($fileName), $config['output_csv_path']);
        $splitter->split($config['split_size']);
        $command = $config['nohup_path'] . ' ' . $config['php_path'] . ' ' . __DIR__ . '/src/shell/csv_importer.php ' . $config['output_csv_path'] . '  > /dev/null 2>&1 &';
        $process = new Process($command, $config['proc_working_path']);
        $process->run();
    }
    $app->redirect('/csv_batch_process/index.php');
});
use Helpers\Magento\MageWrapper;
use Repositories\Magento\CatalogRepository;
use Repositories\Magento\EavCatalogProductRepository;
use Processors\Magento\ProductImporter;
$app->get('/test/', function () use($app, $config) {
    ini_set('max_execution_time', -1);
    Mage::app('admin', 'store', array('global_ban_use_cache' => true))->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
    $mageWrapper = new MageWrapper(Mage);
    $eavRepository = new EavCatalogProductRepository($mageWrapper);
    $catalogRepository = new CatalogRepository($mageWrapper, $eavRepository);
    $magentoProcessor = new ProductImporter($catalogRepository);
    $magentoProcessor->process(new CsvFile('sample.csv'), 'sample.csv');
});
$app->get('/test_splitter/', function () use($app, $config) {
    $splitter = new CsvSplitter(new CsvFile('sample.csv'), $config['output_csv_path']);
    $splitter->setCsvHandler(new CsvHandler());
    $splitter->setFileHandler(new Filesystem());
    $splitter->split(5);
});
$app->run();