Page MenuHomeDevCentral

No OneTemporary

diff --git a/src/Collections/OmniArray.php b/src/Collections/OmniArray.php
index d83676d..5ed44ff 100644
--- a/src/Collections/OmniArray.php
+++ b/src/Collections/OmniArray.php
@@ -1,69 +1,69 @@
<?php
declare(strict_types=1);
namespace Keruald\OmniTools\Collections;
use Keruald\OmniTools\Strings\Multibyte\OmniString;
class OmniArray {
/**
* @var array
*/
private $items = [];
///
/// Constructors
///
- public function __construct (?iterable $items) {
+ public function __construct (?iterable $items = null) {
if ($items === null) {
return;
}
if (is_array($items)) {
$this->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 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/Strings/Multibyte/OmniStringTest.php b/tests/Strings/Multibyte/OmniStringTest.php
index 5005ef3..cf7d364 100644
--- a/tests/Strings/Multibyte/OmniStringTest.php
+++ b/tests/Strings/Multibyte/OmniStringTest.php
@@ -1,117 +1,124 @@
<?php
declare(strict_types=1);
namespace Keruald\OmniTools\Tests\Strings\Multibyte;
use Keruald\OmniTools\Strings\Multibyte\OmniString;
use PHPUnit\Framework\TestCase;
class OmniStringTest extends TestCase {
/**
* @var OmniString
*/
private $string;
protected function setUp () : void {
$this->string = new OmniString("foo");
}
public function testToString () : void {
$this->assertEquals("foo", (string)$this->string);
$this->assertEquals("foo", $this->string->__toString());
}
public function testPad () : void {
$paddedString = $this->string->pad(9, '-=-', STR_PAD_BOTH);
$this->assertEquals("-=-foo-=-", $paddedString);
}
public function testStartsWith () : void {
$this->assertTrue($this->string->startsWith("fo"));
$this->assertTrue($this->string->startsWith(""));
$this->assertTrue($this->string->startsWith("foo"));
$this->assertFalse($this->string->startsWith("Fo"));
$this->assertFalse($this->string->startsWith("bar"));
}
public function testEndsWith () : void {
$this->assertTrue($this->string->endsWith("oo"));
$this->assertTrue($this->string->endsWith(""));
$this->assertTrue($this->string->endsWith("foo"));
$this->assertFalse($this->string->endsWith("oO"));
$this->assertFalse($this->string->endsWith("bar"));
}
public function testLen () : void {
$this->assertEquals(3, $this->string->len());
}
/**
* @dataProvider provideCharactersArrays
*/
public function testGetChars (string $string, array $expectedCharacters) : void {
$actualCharacters = (new OmniString($string))->getChars();
$this->assertEquals($expectedCharacters, $actualCharacters);
}
/**
* @dataProvider provideCharactersBigrams
*/
public function testBigrams (string $string, array $expectedBigrams) : void {
$actualBigrams = (new OmniString($string))->getBigrams();
$this->assertEquals($expectedBigrams, $actualBigrams);
}
/**
* @dataProvider provideExplosions
*/
public function testExplode (string $delimiter, string $imploded, array $exploded) : void {
$actual = (new OmniString($imploded))
->explode($delimiter)
->toArray();
$this->assertEquals($exploded, $actual);
}
+ public function testExplodeWithEmptyOmniArray () : void {
+ $array = (new OmniString("foo"))
+ ->explode("", -1);
+
+ $this->assertEquals(0, count($array->toArray()));
+ }
+
///
/// Data providers
///
public function provideCharactersArrays () : iterable {
yield ["foo", ['f', 'o', 'o']];
yield [
'àèòàFOOàèòà',
['à', 'è', 'ò', 'à', 'F', 'O', 'O', 'à', 'è', 'ò', 'à']
];
yield ["🇩🇪", ["🇩", "🇪"]];
yield ["", []];
}
public function provideCharactersBigrams () : iterable {
yield ["foo", ['fo', 'oo']];
yield ["night", ['ni', 'ig', 'gh', 'ht']];
yield ["🇩🇪", ["🇩🇪"]];
yield ["", []];
}
public function provideExplosions () : iterable {
yield ["/", "a/b/c", ['a', 'b', 'c']];
yield ["/", "abc", ['abc']];
yield ["/", "/b/c", ['', 'b', 'c']];
yield ["/", "a/b/", ['a', 'b', '']];
yield ["", "a/b/c", ['a/b/c']];
yield ["x", "a/b/c", ['a/b/c']];
}
}

File Metadata

Mime Type
text/x-diff
Expires
Thu, Sep 18, 16:53 (17 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2990829
Default Alt Text
(5 KB)

Event Timeline