Esempio n. 1
0
 /**
  * @test
  * @covers Cocur\Plum\Workflow::process()
  * @covers Cocur\Plum\Workflow::processItem()
  */
 public function processShouldCollectExceptions()
 {
     $iterator = m::mock('\\Iterator');
     $iterator->shouldReceive('rewind');
     $iterator->shouldReceive('valid')->andReturn(true)->once();
     $iterator->shouldReceive('current')->andReturn('foobar');
     $iterator->shouldReceive('next');
     $iterator->shouldReceive('valid')->andReturn(false)->once();
     $reader = $this->getMockReader();
     $reader->shouldReceive('getIterator')->andReturn($iterator);
     $exception = new \Exception();
     $converter = $this->getMockConverter();
     $converter->shouldReceive('convert')->with('foobar')->once()->andThrow($exception);
     $this->workflow->addConverter($converter);
     $result = $this->workflow->process($reader);
     $this->assertEquals(1, $result->getReadCount());
     $this->assertEquals(1, $result->getErrorCount());
     $this->assertContains($exception, $result->getExceptions());
 }
Esempio n. 2
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Cocur\Plum\Writer\ArrayWriter;
use Cocur\Plum\Workflow;
use Cocur\Plum\Reader\ArrayReader;
use Cocur\Plum\Converter\CallbackConverter;
use Cocur\Plum\Filter\CallbackFilter;
$reader = new ArrayReader(['foobar', 'qoobar', 'bazbaz']);
$writer1 = new ArrayWriter();
$writer2 = new ArrayWriter();
$workflow = new Workflow();
$workflow->addConverter(new CallbackConverter(function ($item) {
    return strtoupper($item);
}));
$workflow->addWriter($writer1);
$workflow->addFilter(new CallbackFilter(function ($item) {
    return $item != 'BAZBAZ';
}));
$workflow->addWriter($writer2);
$workflow->process($reader);
print_r($writer1->getData());
print_r($writer2->getData());
Esempio n. 3
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Cocur\Plum\Reader\ArrayReader;
use Cocur\Plum\Writer\ArrayWriter;
use Cocur\Plum\Workflow;
use Cocur\Plum\WorkflowConcatenator;
$reader = new ArrayReader(['foo', 'bar', 'baz', 'qoo']);
$writer = new ArrayWriter();
$concatenator = new WorkflowConcatenator();
$workflow1 = new Workflow();
$workflow1->addWriter($concatenator);
$workflow1->process($reader);
$workflow2 = new Workflow();
$workflow2->addWriter($writer);
$workflow2->process($concatenator);
print_r($writer->getData());