Ejemplo n.º 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()));
     }
 }
Ejemplo n.º 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++]));
     }
 }
Ejemplo n.º 3
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;
}