| 1 | <?php |
||
| 8 | class MultipleOperationsTest extends PHPUnit_Framework_TestCase |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Example of a longer pipeline. If this was real code, you should probably split it into smaller chunks. |
||
| 12 | */ |
||
| 13 | public function testIt() |
||
| 14 | { |
||
| 15 | $array = [1, 2, 8, 3, 7, 5, 1, 4, 4,]; |
||
| 16 | $collection = new Collection($array); |
||
| 17 | |||
| 18 | $result = $collection |
||
| 19 | ->reject(function ($v) { |
||
| 20 | return $v > 2; |
||
| 21 | }) |
||
| 22 | ->filter(function ($k) { |
||
| 23 | return $k > 5; |
||
| 24 | }) |
||
| 25 | ->distinct() |
||
| 26 | ->concat([1, 2]) |
||
| 27 | ->map(function ($i) { |
||
| 28 | return [$i, $i + 1]; |
||
| 29 | }) |
||
| 30 | ->flatten() |
||
| 31 | ->sort(function ($a, $b) { |
||
| 32 | return $a > $b; |
||
| 33 | }) |
||
| 34 | ->slice(2, 5) |
||
| 35 | ->groupBy(function ($v) { |
||
| 36 | return $v % 2 == 0 ? 'even' : 'odd'; |
||
| 37 | }) |
||
| 38 | ->get('even') |
||
| 39 | ->toArray(); |
||
| 40 | |||
| 41 | $this->assertEquals([2], $result); |
||
| 42 | } |
||
| 43 | } |
||
| 44 |