| 1 | <?php |
||
| 19 | class FilterCollectionTest extends UnitTestCase |
||
| 20 | { |
||
| 21 | public function testFilterReturnsNewCollectionFilteredByPredicateCallback() |
||
| 22 | { |
||
| 23 | $predicate = function ($val, $key) { |
||
| 24 | return strlen($val) > 4; |
||
| 25 | }; |
||
| 26 | |||
| 27 | $coll = Factory::create($this->fixtures['names']); |
||
| 28 | |||
| 29 | $this->assertCount(10, $coll); |
||
| 30 | $filtered = $coll->filter($predicate); |
||
| 31 | $this->assertInstanceOf(Collection::class, $filtered); |
||
| 32 | $this->assertNotSame($coll, $filtered); |
||
| 33 | $this->assertCount(10, $coll); |
||
| 34 | $this->assertCount(6, $filtered); |
||
| 35 | $this->assertEquals( |
||
| 36 | [ |
||
| 37 | 0 => 'Chelsea', |
||
| 38 | 1 => 'Adella', |
||
| 39 | 2 => 'Monte', |
||
| 40 | 4 => 'Lottie', |
||
| 41 | 6 => 'Dayton', |
||
| 42 | 9 => 'Nakia', |
||
| 43 | ], |
||
| 44 | $filtered->toArray() |
||
| 45 | ); |
||
| 46 | } |
||
| 47 | } |
||
| 48 |