1 | <?php |
||
18 | class EachCollectionTest extends UnitTestCase |
||
19 | { |
||
20 | public function testEachLoopsOverEveryItemInCollectionCallingCallback() |
||
21 | { |
||
22 | $coll = Factory::create($this->fixtures['names']); |
||
23 | $namesCount = count($this->fixtures['names']); |
||
24 | $recorder = $this->getMethodCallRecorderForCount($namesCount); |
||
25 | |||
26 | // this will test that touch() is called $namesCount times |
||
27 | $return = $coll->each( |
||
28 | function ($val, $key, $iter = null) use ($recorder, $coll) { |
||
29 | $this->assertTrue(is_string($val)); |
||
30 | $this->assertTrue(is_numeric($key)); |
||
31 | |||
32 | if (!$coll instanceof \Novactive\Tests\Perfs\ArrayMethodCollection) { |
||
33 | $this->assertTrue(is_numeric($iter)); |
||
34 | } |
||
35 | |||
36 | $recorder->touch(); |
||
37 | } |
||
38 | ); |
||
39 | $this->assertSame($coll, $return, 'Collection::each() should return the collection itself.'); |
||
40 | } |
||
41 | } |
||
42 |