diff --git a/tests/EdgeCasesTest.php b/tests/EdgeCasesTest.php index eef714a..5023e24 100644 --- a/tests/EdgeCasesTest.php +++ b/tests/EdgeCasesTest.php @@ -78,6 +78,28 @@ public function testFilterAnyFalseValueCustomCallback() $this->assertCount(0, $pipeline->toArray()); } + public function testNonUniqueKeys() + { + $pipeline = \Pipeline\map(function () { + yield 'foo' => 'bar'; + yield 'foo' => 'baz'; + }); + + $this->assertSame([ + 'foo' => 'baz', + ], iterator_to_array($pipeline)); + + $pipeline = \Pipeline\map(function () { + yield 'foo' => 'bar'; + yield 'foo' => 'baz'; + }); + + $this->assertSame([ + 'bar', + 'baz', + ], $pipeline->toArray()); + } + public function testMapUnprimed() { $pipeline = new Standard(); diff --git a/tests/ErrorsTest.php b/tests/ErrorsTest.php index 83fbc02..5f1c547 100644 --- a/tests/ErrorsTest.php +++ b/tests/ErrorsTest.php @@ -71,4 +71,21 @@ public function testPipelineInPipelineUsesSelf() $pipeline->reduce(); } + + /** + * @covers \Pipeline\Standard::unpack() + */ + public function testUnpackNonIterable() + { + $pipeline = new \Pipeline\Standard(); + + $pipeline->map(function () { + yield 1; + yield [2, 3]; + })->unpack(); + + $this->expectException(Warning::class); + $this->expectExceptionMessage('Only arrays and Traversables can be unpacked'); + $pipeline->toArray(); + } }