public function getNonEmptyCollections() { return ['array' => ['coll' => [1, 2], 'expected' => 2], 'array_with_keys' => ['coll' => ['one' => 1, 'two' => 2], 'expected' => 2], 'iterator' => ['coll' => new ArrayIterator([1, 2]), 'expected' => 2], 'generator' => ['coll' => apply(function () { (yield 1); (yield 2); }), 'expected' => 2]]; }
private function generator(...$items) { return apply(function () use($items) { foreach ($items as $item) { (yield $item); } }); }
public function getValidCollections() { return ['array' => ['coll' => [1, 2, 3, 4, 5, 6, 7], 'partitionSize' => 2, 'expected' => [[0 => 1, 1 => 2], [2 => 3, 3 => 4], [4 => 5, 5 => 6], [6 => 7]]], 'array_with_keys' => ['coll' => ['one' => 1, 'two' => 2, 'three' => 3], 'partitionSize' => 2, 'expected' => [['one' => 1, 'two' => 2], ['three' => 3]]], 'iterator' => ['coll' => new ArrayIterator([1, 2, 3, 4, 5, 6, 7]), 'partitionSize' => 2, 'expected' => [[0 => 1, 1 => 2], [2 => 3, 3 => 4], [4 => 5, 5 => 6], [6 => 7]]], 'generator' => ['coll' => apply(function () { (yield 1); (yield 2); (yield 3); (yield 4); (yield 5); (yield 6); (yield 7); }), 'partitionSize' => 2, 'expected' => [[0 => 1, 1 => 2], [2 => 3, 3 => 4], [4 => 5, 5 => 6], [6 => 7]]]]; }
/** * @test * @dataProvider calculatorProvider */ public function is_should_compose_a_functions_combination($a, $b, $result) { $calculator = pipe($this->multiplier(), $this->byTwoDivider()); $this->assertSame($result, apply($calculator, [$a, $b])); }
/** * @test * @dataProvider fibonacciValues */ public function it_should_call_fibonacci($number, $fibonacci) { $this->assertSame($fibonacci, apply($this->functionFibonacciMemoized(), [$number])); }
/** @test */ public function it_should_return_null_if_all_predicates_are_not_true() { $this->assertNull(apply(do_if($this->sumOne(), [$this->isGreaterThanOne(), $this->isOdd()]), [3])); }