diff --git a/src/Collections/OmniArray.php b/src/Collections/OmniArray.php index 30a60c1..d83676d 100644 --- a/src/Collections/OmniArray.php +++ b/src/Collections/OmniArray.php @@ -1,67 +1,69 @@ items = $items; return; } foreach ($items as $item) { $this->items[] = $item; } } - public static function explode (string $delimiter, string $string, int $limit = PHP_INT_MAX) : self { - return new OmniArray(explode($delimiter, $string, $limit)); + public static function explode (string $delimiter, string $string, + int $limit = PHP_INT_MAX) : self { + return (new OmniString($string)) + ->explode($delimiter, $limit); } /// /// Transformation methods /// public function toIntegers () : self { array_walk($this->items, ArrayUtilities::toIntegerCallback()); return $this; } public function map (callable $callable) : self { $items = array_map($callable, $this->items); return new self($items); } public function implode(string $delimiter) : OmniString { return new OmniString(implode($delimiter, $this->items)); } /// /// Getters methods /// public function toArray () : array { return $this->items; } } diff --git a/tests/Collections/OmniArrayTest.php b/tests/Collections/OmniArrayTest.php index 473a78c..9b587f1 100644 --- a/tests/Collections/OmniArrayTest.php +++ b/tests/Collections/OmniArrayTest.php @@ -1,35 +1,47 @@ map(function ($x) { return $x * $x; }) ->toArray(); $this->assertEquals([1, 4, 9, 16, 25], $actual); } public function testImplode() : void { $actual = (new OmniArray(["a", "b", "c"])) ->implode(".") ->__toString(); $this->assertEquals("a.b.c", $actual); } public function testImplodeWithoutDelimiter() : void { $actual = (new OmniArray(["a", "b", "c"])) ->implode("") ->__toString(); $this->assertEquals("abc", $actual); } + public function testExplode() : void { + $actual = OmniArray::explode(".", "a.b.c"); + + $this->assertEquals(["a", "b", "c"], $actual->toArray()); + } + + public function testExplodeWithoutDelimiter() : void { + $actual = OmniArray::explode("", "a.b.c"); + + $this->assertEquals(["a.b.c"], $actual->toArray()); + } + }