| @@ 20-46 (lines=27) @@ | ||
| 17 | */ |
|
| 18 | class CombineKeysCollectionTest extends UnitTestCase |
|
| 19 | { |
|
| 20 | public function testCombineKeysUsesIncomingTraversableAsKeysForCollectionsValues() |
|
| 21 | { |
|
| 22 | $coll = Factory::create($this->fixtures['names']); |
|
| 23 | $orig = $coll->toArray(); |
|
| 24 | $newkeys = $coll->combineKeys($this->fixtures['emails']); |
|
| 25 | $this->assertEquals( |
|
| 26 | [ |
|
| 27 | '[email protected]' => 'Chelsea', |
|
| 28 | '[email protected]' => 'Adella', |
|
| 29 | '[email protected]' => 'Monte', |
|
| 30 | '[email protected]' => 'Maye', |
|
| 31 | '[email protected]' => 'Lottie', |
|
| 32 | '[email protected]' => 'Don', |
|
| 33 | '[email protected]' => 'Dayton', |
|
| 34 | '[email protected]' => 'Kirk', |
|
| 35 | '[email protected]' => 'Troy', |
|
| 36 | '[email protected]' => 'Nakia', |
|
| 37 | ], |
|
| 38 | $newkeys->toArray() |
|
| 39 | ); |
|
| 40 | $this->assertNotSame($newkeys->toArray(), $orig); |
|
| 41 | $this->assertSame( |
|
| 42 | $coll->toArray(), |
|
| 43 | $orig, |
|
| 44 | 'The original collection should not be affected by Collection::combineKeys().' |
|
| 45 | ); |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * @expectedException \InvalidArgumentException |
|
| @@ 68-94 (lines=27) @@ | ||
| 65 | $coll->combineKeys([1, 2, 3]); |
|
| 66 | } |
|
| 67 | ||
| 68 | public function testCombineKeysAcceptsTraversable() |
|
| 69 | { |
|
| 70 | $coll = Factory::create($this->fixtures['names']); |
|
| 71 | $orig = $coll->toArray(); |
|
| 72 | $iter = $this->getIteratorForArray($this->fixtures['emails']); |
|
| 73 | $keycombined = $coll->combineKeys($iter); |
|
| 74 | $this->assertSame( |
|
| 75 | [ |
|
| 76 | '[email protected]' => 'Chelsea', |
|
| 77 | '[email protected]' => 'Adella', |
|
| 78 | '[email protected]' => 'Monte', |
|
| 79 | '[email protected]' => 'Maye', |
|
| 80 | '[email protected]' => 'Lottie', |
|
| 81 | '[email protected]' => 'Don', |
|
| 82 | '[email protected]' => 'Dayton', |
|
| 83 | '[email protected]' => 'Kirk', |
|
| 84 | '[email protected]' => 'Troy', |
|
| 85 | '[email protected]' => 'Nakia', |
|
| 86 | ], |
|
| 87 | $keycombined->toArray() |
|
| 88 | ); |
|
| 89 | $this->assertSame( |
|
| 90 | $orig, |
|
| 91 | $coll->toArray(), |
|
| 92 | 'Ensure that Collection::combineKeys does not change the original collection.' |
|
| 93 | ); |
|
| 94 | } |
|
| 95 | } |
|
| 96 | ||