| @@ 36-52 (lines=17) @@ | ||
| 33 | $collection->add($node); |
|
| 34 | } |
|
| 35 | ||
| 36 | public function testCallingApplyWillModifyTheContentsUsingReference() |
|
| 37 | { |
|
| 38 | $node = m::mock(NodeInterface::class); |
|
| 39 | $node->shouldReceive('someMethod') |
|
| 40 | ->once() |
|
| 41 | ->andReturn(null); |
|
| 42 | ||
| 43 | $collection = new NodeCollection(); |
|
| 44 | $collection->add($node); |
|
| 45 | ||
| 46 | $collection->apply(function ($item) { |
|
| 47 | $item->someMethod(); |
|
| 48 | }); |
|
| 49 | ||
| 50 | $item = $collection->getAll()[0]; |
|
| 51 | static::assertSame($node, $item); |
|
| 52 | } |
|
| 53 | ||
| 54 | public function testCallingApplyWillModifyTheContentsUsingReturnValue() |
|
| 55 | { |
|
| @@ 54-71 (lines=18) @@ | ||
| 51 | static::assertSame($node, $item); |
|
| 52 | } |
|
| 53 | ||
| 54 | public function testCallingApplyWillModifyTheContentsUsingReturnValue() |
|
| 55 | { |
|
| 56 | $node = m::mock(NodeInterface::class); |
|
| 57 | $node->shouldReceive('someMethod') |
|
| 58 | ->once() |
|
| 59 | ->andReturn(null); |
|
| 60 | ||
| 61 | $collection = new NodeCollection(); |
|
| 62 | $collection->add($node); |
|
| 63 | ||
| 64 | $collection->apply(function ($item) { |
|
| 65 | $item->someMethod(); |
|
| 66 | return $item; |
|
| 67 | }); |
|
| 68 | ||
| 69 | $item = $collection->getAll()[0]; |
|
| 70 | static::assertSame($node, $item); |
|
| 71 | } |
|
| 72 | ||
| 73 | public function testFirstWithNoCallbackWillReturnTheFirstEntry() |
|
| 74 | { |
|