Example #1
0
 public function testCheckAnswerTask3()
 {
     $this->assertFileExists('data/export.csv');
     $filecsv = new \SplFileObject('data/export.csv');
     $filecsv->setFlags(\SplFileObject::READ_CSV);
     $header = $filecsv->current();
     $processor = new YieldProcessor(ReaderFactory::create('Db\\Product', include 'config/database.php'), WriterFactory::create('Stub'), function () {
     });
     foreach ($processor->processing() as $item) {
         $filecsv->next();
         $this->assertEquals($item, array_combine($header, $filecsv->current()));
     }
 }
Example #2
0
 public function testCheckAnswerTask2()
 {
     $this->assertFileExists('data/2.txt');
     $this->assertFileExists('data/comments/2.txt');
     $this->assertGreaterThan(0, strlen(file_get_contents('data/comments/2.txt')));
     $file = file_get_contents('data/2.txt');
     $this->assertContains('Start Time', $file);
     $this->assertContains('End Time', $file);
     $processor = new YieldProcessor(ReaderFactory::create('Db\\Product', include 'config/database.php'), WriterFactory::create('Stub'), function () {
     });
     $file = explode("\n", $file);
     $i = 2;
     foreach ($processor->processing() as $item) {
         $this->assertEquals(implode(", ", $item), trim($file[$i++]));
     }
 }
Example #3
0
 /**
  * Test without output buffering
  *
  * @outputBuffering enabled
  */
 public function testCheckAnswerTask4()
 {
     $_GET['reader'] = 'Db\\Product';
     $_GET['writer'] = 'Html';
     $argv[1] = 'Db\\Product';
     $argv[2] = 'Html';
     ob_start();
     include 'web.php';
     $resultOutput = trim(ob_get_contents());
     ob_end_clean();
     $processor = new ReadWriteProcessor(ReaderFactory::create('Db\\Product', include 'config/database.php'), WriterFactory::create('Html'), function () {
     });
     ob_start();
     $processor->processing();
     $expectResult = trim(ob_get_contents());
     ob_end_clean();
     $this->assertEquals($expectResult, $resultOutput);
 }
Example #4
0
<?php

use OpsWay\Migration\Logger\ConsoleLogger;
use OpsWay\Migration\Processor\YieldProcessor;
use OpsWay\Migration\Reader\ReaderFactory;
use OpsWay\Migration\Writer\WriterFactory;
$config = (include 'config.php');
try {
    $processor = new YieldProcessor(ReaderFactory::create($config['reader'], $config['params']), WriterFactory::create($config['writer'], $config['params']), new ConsoleLogger(false));
    // Processing
    foreach ($processor->processing() as $item) {
        $processor->getWriter()->write($item);
    }
} catch (\Exception $e) {
    echo "ERROR: " . $e->getMessage();
} finally {
    echo PHP_EOL;
}
Example #5
0
<?php

use OpsWay\Migration\Logger\OutOfStockLogger;
use OpsWay\Migration\Processor\ReadWriteProcessor;
use OpsWay\Migration\Reader\ReaderFactory;
use OpsWay\Migration\Writer\WriterFactory;
$config = (include 'config.php');
if (defined('CLI_MODE') && CLI_MODE === false) {
    die('This can be run only on CLI mode.' . PHP_EOL);
}
echo "Start Time: " . date("d-m-Y H:i:s") . PHP_EOL;
try {
    $processor = new ReadWriteProcessor(ReaderFactory::create($config['reader'], $config['params']), WriterFactory::create($config['writer'], $config['params']), new OutOfStockLogger(true));
    //Processing
    $processor->processing();
} catch (\Exception $e) {
    echo "ERROR: " . $e->getMessage();
} finally {
    echo PHP_EOL;
}
echo "End Time: " . date("d-m-Y H:i:s") . PHP_EOL;
Example #6
0
<?php

use OpsWay\Migration\Logger\ConsoleLogger;
use OpsWay\Migration\Processor\ReadWriteProcessor;
use OpsWay\Migration\Reader\ReaderFactory;
use OpsWay\Migration\Writer\WriterFactory;
$config = (include 'config.php');
if (defined('CLI_MODE') && CLI_MODE === false) {
    die('This can be run only on CLI mode.' . PHP_EOL);
}
echo "Start Time: " . date("d-m-Y H:i:s") . PHP_EOL;
try {
    //$c and $counter globals for debug
    $c = 0;
    $counter = array();
    $processor = new ReadWriteProcessor(ReaderFactory::create($config['reader'], $config['params']), WriterFactory::create($config['writer'], $config['params']), function ($item, $status, $msg) {
        global $c, $counter;
        if (++$c % 2 == 0) {
            array_push($counter, $c);
        }
        if (!$status) {
            echo "Warning: " . $msg . print_r($item, true) . PHP_EOL;
        }
    });
    //Processing
    $processor->processing();
    //debuging counter showing
    $debug = implode(" ", $counter);
    echo "debug info : " . $debug;
} catch (\Exception $e) {
    echo "ERROR: " . $e->getMessage();