示例#1
0
 /**
  * @test
  * @covers Cocur\Plum\Workflow::process()
  * @covers Cocur\Plum\Workflow::processItem()
  */
 public function processShouldApplyFilterToReadItems()
 {
     $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);
     $filter = $this->getMockFilter();
     $filter->shouldReceive('filter')->with('foobar')->once()->andReturn(false);
     $this->workflow->addFilter($filter);
     $result = $this->workflow->process($reader);
     $this->assertEquals(1, $result->getReadCount());
     $this->assertEquals(0, $result->getWriteCount());
 }
示例#2
0
文件: array-io.php 项目: cocur/plum
<?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());