Skip to content

Commit 173530e

Browse files
committed
Add string formats and validation tests
1 parent 26114f4 commit 173530e

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/Format/Str.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,14 @@ public function compare(string|int|float|bool|null $compare): bool
153153
}
154154

155155
/**
156-
* Checks if a string ends with a given substring
156+
* Checks if a string contains a given substring
157157
*
158158
* @param string $needle
159159
* @return bool
160160
*/
161-
public function endsWith(string $needle): bool
161+
public function contains(string $needle): bool
162162
{
163-
return str_ends_with($this->raw, $needle);
163+
return str_contains($this->raw, $needle);
164164
}
165165

166166
/**
@@ -173,6 +173,17 @@ public function startsWith(string $needle): bool
173173
{
174174
return str_starts_with($this->raw, $needle);
175175
}
176+
177+
/**
178+
* Checks if a string ends with a given substring
179+
*
180+
* @param string $needle
181+
* @return bool
182+
*/
183+
public function endsWith(string $needle): bool
184+
{
185+
return str_ends_with($this->raw, $needle);
186+
}
176187

177188
// Return self -->
178189

@@ -313,7 +324,7 @@ public function clearWhitespace(): self
313324
* @param bool $double_encode
314325
* @return self
315326
*/
316-
public function entityEncode(int $flags = ENT_QUOTES|ENT_SUBSTITUTE, ?string $encoding, bool $double_encode = true): self
327+
public function entityEncode(int $flags = ENT_QUOTES|ENT_SUBSTITUTE, ?string $encoding = null, bool $double_encode = true): self
317328
{
318329
$this->raw = htmlentities($this->strVal(), $flags, $encoding, $double_encode);
319330
return $this;
@@ -326,7 +337,7 @@ public function entityEncode(int $flags = ENT_QUOTES|ENT_SUBSTITUTE, ?string $en
326337
* @param string|null $encoding
327338
* @return self
328339
*/
329-
public function entityDecode(int $flags = ENT_QUOTES|ENT_SUBSTITUTE, ?string $encoding): self
340+
public function entityDecode(int $flags = ENT_QUOTES|ENT_SUBSTITUTE, ?string $encoding = null): self
330341
{
331342
$this->raw = html_entity_decode($this->strVal(), $flags, $encoding);
332343
return $this;

tests/unitary-dto-string.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
"equal" => 'doe'
3030
], "toLower: Failed");
3131

32-
$this->add($obj->content->str()->excerpt(50, "...")->get(), [
33-
"equal" => 'doe'
34-
], "toLower: Failed");
35-
32+
$this->add($obj->content->str()->excerpt(50, "---")->get(), [
33+
"length" => [53, 53],
34+
"endsWith" => ['---'],
35+
], "excerpt: Failed");
3636

3737

3838
});

0 commit comments

Comments
 (0)