示例#1
0
 /**
  * @covers \Tivie\Command\Chain::add
  * @covers \Tivie\Command\Chain::run
  */
 public function testRunPipedArgument()
 {
     $chain = new Chain();
     $xArg = 'foo';
     $result1 = $this->getResultMock($xArg, 0);
     $cmd1 = $this->getCmdMock();
     $cmd1->expects($this->once())->method('run')->willReturn($result1);
     $chain->add($cmd1);
     $cmd2 = $this->getCmdMock();
     $arg1 = $this->getArgumentMock('bar', array(PIPE_PH));
     $arg1->expects($this->once())->method('replaceValue')->with(0, $xArg);
     $cmd2->addArgument($arg1);
     $chain->add($cmd2, RUN_IF_PREVIOUS_SUCCEEDS, true);
     $chain->run();
 }
示例#2
0
 function testRunDoesNotNeedArgs()
 {
     Chain::add('test1', function () {
         return 1;
     });
     $this->assertEquals([1], Chain::run('test1')->realize());
 }
示例#3
0
 /**
  * @test
  */
 function it_passes_previous_result_to_next_filter_and_returns_the_last_filter_result()
 {
     $filterChain = new Chain();
     $someDataToFilter = array();
     $filterResultA = 'filter result A';
     $filterResultB = 'filter result B';
     $filterResultC = 'filter result C';
     $filterA = $this->getFilter($someDataToFilter, $filterResultA);
     $filterB = $this->getFilter($filterResultA, $filterResultB);
     $filterC = $this->getFilter($filterResultB, $filterResultC);
     $filterChain->add($filterA)->add($filterB)->add($filterC);
     $this->assertSame($filterResultC, $filterChain->filter($someDataToFilter));
 }
 public function test_delete_behaviour()
 {
     $chain = new Chain();
     $chain->add('fred')->add('wilma')->add('betty')->add('barney');
     assertThat($chain->getTokens(), contains(array('fred', 'wilma', 'betty', 'barney')));
     $chain->delete('wilma');
     assertThat($chain->getTokens(), contains(array('fred', 'betty', 'barney')));
     $chain->delete('barney');
     assertThat($chain->getTokens(), contains(array('fred', 'betty')));
     $chain->delete('fred');
     assertThat($chain->getTokens(), contains(array('betty')));
     $chain->delete('betty');
     assertThat($chain->getTokens(), contains(array()));
 }
示例#5
0
文件: pad.php 项目: wemash/hooray
<?php

Chain::add('pad', function ($data, $size, $value) {
    return array_pad($data, $size, $value);
});
示例#6
0
文件: shuffle.php 项目: wemash/hooray
<?php

Chain::add('shuffle', function ($data, $seed = null) {
    mt_srand($seed || microtime());
    $data = array_values($data);
    for ($i = count($data) - 1; $i > 0; $i--) {
        $j = mt_rand(0, $i);
        $tmp = $data[$i];
        $data[$i] = $data[$j];
        $data[$j] = $tmp;
    }
    return $data;
});
示例#7
0
文件: flatmap.php 项目: wemash/hooray
<?php

Chain::add('flatmap', function ($data, $action) {
    return hooray($data)->reduce(function ($carry, $datum) use($action) {
        $result = $action($datum);
        if (!is_array($result)) {
            $result = [$result];
        }
        return array_merge($carry, $result);
    }, []);
});
示例#8
0
文件: take.php 项目: wemash/hooray
<?php

Chain::add('take', function ($data, $count) {
    return array_slice($data, 0, $count);
});
示例#9
0
<?php

Chain::add('growKeys', function ($data) {
    return array_change_key_case($data, CASE_UPPER);
});
示例#10
0
文件: push.php 项目: wemash/hooray
<?php

Chain::add('push', function () {
    $args = func_get_args();
    $data = array_shift($args);
    foreach ($args as $arg) {
        $data[] = $arg;
    }
    return $data;
});
示例#11
0
文件: map.php 项目: wemash/hooray
<?php

Chain::add('map', function ($data, $action) {
    return array_map($action, $data);
});
示例#12
0
文件: flip.php 项目: wemash/hooray
<?php

Chain::add('flip', function ($data) {
    return array_flip($data);
});
示例#13
0
文件: column.php 项目: wemash/hooray
<?php

Chain::add('column', function ($data, $column) {
    return array_column($data, $column);
});
示例#14
0
文件: unshift.php 项目: wemash/hooray
<?php

Chain::add('unshift', function ($data, $element) {
    array_unshift($data, $element);
    return $data;
});
示例#15
0
文件: drop.php 项目: wemash/hooray
<?php

Chain::add('drop', function ($data, $number) {
    return array_slice($data, $number);
});
示例#16
0
<?php

Chain::add('intersect', function ($data, $other) {
    return array_intersect($data, Hooray::unwrap([$other]));
});
示例#17
0
文件: values.php 项目: wemash/hooray
<?php

Chain::add('values', function ($data) {
    return array_values($data);
});
示例#18
0
文件: unique.php 项目: wemash/hooray
<?php

Chain::add('unique', function ($data) {
    return hooray(array_unique($data, SORT_REGULAR))->values()->realize();
});
示例#19
0
文件: keys.php 项目: wemash/hooray
<?php

Chain::add('keys', function ($data) {
    return array_keys($data);
});
示例#20
0
<?php

Chain::add('countValues', function ($data) {
    return array_count_values($data);
});
示例#21
0
文件: chunk.php 项目: wemash/hooray
<?php

Chain::add('chunk', function ($data, $chunkSize, $preserveKeys = false) {
    return array_chunk($data, $chunkSize, $preserveKeys);
});
示例#22
0
文件: splice.php 项目: wemash/hooray
<?php

// This bad boy seems off. Why not decompose this into
// remove(offset, length) and insert(position, values)?
Chain::add('splice', function ($data, $offset, $length, $replacement) {
    array_splice($data, $offset, $length, $replacement);
    return $data;
});
示例#23
0
文件: filter.php 项目: wemash/hooray
<?php

Chain::add('filter', function ($data, $action) {
    return array_filter($data, $action);
});
示例#24
0
<?php

Chain::add('shrinkKeys', function ($data) {
    return array_change_key_case($data, CASE_LOWER);
});