diff --git a/src/Incoming/Structure/StructureFactory.php b/src/Incoming/Structure/StructureFactory.php index 329d0b7..50cd892 100644 --- a/src/Incoming/Structure/StructureFactory.php +++ b/src/Incoming/Structure/StructureFactory.php @@ -81,7 +81,7 @@ protected static function buildFromTraversable(Traversable $data) // Traverse through the data, but only check the first item's key foreach ($data as $key => &$val) { - $is_map = !is_int($key); + $is_map = $is_map || !is_int($key); $val = self::attemptBuildTraversableLike($val); } diff --git a/tests/Incoming/Test/Structure/StructureFactoryTest.php b/tests/Incoming/Test/Structure/StructureFactoryTest.php index 13f2338..cfdad4f 100644 --- a/tests/Incoming/Test/Structure/StructureFactoryTest.php +++ b/tests/Incoming/Test/Structure/StructureFactoryTest.php @@ -122,4 +122,19 @@ public function testBuildWithInvalidStructuralType() $structure = (new StructureFactory)->build($data); } + + /** + * @link https://github.com/Rican7/incoming/pull/3 + */ + public function testBuildWithTraversableAndMixedKeys() + { + $data = new ArrayIterator([ + 'name' => 'markus', + 0 => 'a crazy mixed-in key' + ]); + + $structure = (new StructureFactory)->build($data); + + $this->assertTrue($structure instanceof Map); + } }