Skip to content

Commit f3b2ad4

Browse files
committed
write unit test for utility methods and fix bugs
1 parent ad32e23 commit f3b2ad4

10 files changed

+960
-108
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
.vscode/
22
vendor/
3+
/.phpunit.cache
4+
.phpunit.result.cache
5+
lang/

composer.json

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,49 @@
11
{
2-
"name": "dvlpr1996/php-string-helpers",
3-
"description": "some useful php string helpers",
4-
"keywords": [
5-
"php",
6-
"string",
7-
"helpers",
8-
"php-string-helpers"
9-
],
10-
"homepage": "https://github.com/dvlpr1996/php-string-helpers",
11-
"license": "MIT",
12-
"type": "library",
13-
"authors": [
14-
{
15-
"name": "Nima",
16-
"email": "nimajahanbakhshian@gmail.com",
17-
"role": "Developer"
18-
}
19-
],
20-
"support": {
21-
"issues": "https://github.com/dvlpr1996/php-string-helpers/issues",
22-
"source": "https://github.com/dvlpr1996/php-string-helpers"
23-
},
24-
"require": {
25-
"php": "^8.0"
26-
},
27-
"require-dev": {
28-
"symfony/var-dumper": "^6.0",
29-
"phpunit/phpunit": "^9.5"
30-
},
31-
"autoload": {
32-
"psr-4": {
33-
"PhpStringHelpers\\": "src/"
34-
},
35-
"files": [
36-
"./src/PhpStringHelpers.php"
37-
]
38-
},
39-
"autoload-dev": {
40-
"psr-4": {
41-
"PhpStringHelpers\\Tests\\": "tests/"
42-
}
43-
},
44-
"scripts": {
45-
"test": "vendor/bin/phpunit",
46-
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
47-
}
2+
"name": "dvlpr1996/php-string-helpers",
3+
"description": "some useful php string helpers",
4+
"keywords": [
5+
"php",
6+
"string",
7+
"helpers",
8+
"php-string-helpers"
9+
],
10+
"homepage": "https://github.com/dvlpr1996/php-string-helpers",
11+
"license": "MIT",
12+
"type": "library",
13+
"authors": [
14+
{
15+
"name": "Nima",
16+
"email": "nimajahanbakhshian@gmail.com",
17+
"role": "Developer"
18+
}
19+
],
20+
"support": {
21+
"issues": "https://github.com/dvlpr1996/php-string-helpers/issues",
22+
"source": "https://github.com/dvlpr1996/php-string-helpers"
23+
},
24+
"require": {
25+
"php": "^8.0"
26+
},
27+
"require-dev": {
28+
"symfony/var-dumper": "^6.0",
29+
"phpunit/phpunit": "^9.5"
30+
},
31+
"autoload": {
32+
"psr-4": {
33+
"PhpStringHelpers\\": "src/"
34+
},
35+
"files": [
36+
"./src/PhpStringHelpers.php"
37+
]
38+
},
39+
"autoload-dev": {
40+
"psr-4": {
41+
"PhpStringHelpers\\Tests\\": "tests/"
42+
}
43+
},
44+
"scripts": {
45+
"test": "vendor/bin/phpunit",
46+
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
47+
},
48+
"minimum-stability": "dev"
4849
}

phpunit.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
cacheResultFile=".phpunit.cache/test-results"
6+
executionOrder="depends,defects"
7+
forceCoversAnnotation="true"
8+
beStrictAboutCoversAnnotation="true"
9+
beStrictAboutOutputDuringTests="true"
10+
beStrictAboutTodoAnnotatedTests="true"
11+
convertDeprecationsToExceptions="true"
12+
failOnRisky="true"
13+
failOnWarning="true"
14+
colors="true"
15+
testdox = "true"
16+
verbose="true">
17+
<testsuites>
18+
<testsuite name="default">
19+
<directory>tests</directory>
20+
</testsuite>
21+
</testsuites>
22+
23+
<coverage cacheDirectory=".phpunit.cache/code-coverage"
24+
processUncoveredFiles="true">
25+
<include>
26+
<directory suffix=".php">src</directory>
27+
</include>
28+
</coverage>
29+
</phpunit>

src/PhpStringHelpers.php

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
declare(strict_types=1);
43

54
use PhpStringHelpers\utility\StrUtility as strHelpers;
@@ -81,10 +80,10 @@ function toSlug(string $string): string
8180
}
8281
}
8382

84-
if (!function_exists('rmAllBlank')) {
85-
function rmAllBlank(string $words): string
83+
if (!function_exists('rmAllBlanks')) {
84+
function rmAllBlanks(string $words): string
8685
{
87-
return strHelpers::rmAllBlank($words);
86+
return strHelpers::rmAllBlanks($words);
8887
}
8988
}
9089

@@ -109,10 +108,10 @@ function wrapper(int|string $string, int|string $wrapper = '*'): string
109108
}
110109
}
111110

112-
if (!function_exists('path')) {
113-
function path(string $path, string $pathExtension = 'php'): string
111+
if (!function_exists('filePath')) {
112+
function filePath(string $path, string $pathExtension = 'php'): string
114113
{
115-
return strHelpers::path($path, $pathExtension);
114+
return strHelpers::filePath($path, $pathExtension);
116115
}
117116
}
118117

@@ -137,17 +136,10 @@ function pureString(string $data): string
137136
}
138137
}
139138

140-
if (!function_exists('randomWords')) {
141-
function randomWords(int $size = 5): string
142-
{
143-
return strHelpers::randomWords($size);
144-
}
145-
}
146-
147-
if (!function_exists('randomWords')) {
148-
function randomWords(int $size = 5): string
139+
if (!function_exists('randomChar')) {
140+
function randomChar(int $size = 5): string
149141
{
150-
return strHelpers::randomWords($size);
142+
return strHelpers::randomChar($size);
151143
}
152144
}
153145

@@ -266,10 +258,10 @@ function rmLeftChar(string $words, int $num): string
266258
}
267259
}
268260

269-
if (!function_exists('rmChar')) {
270-
function rmChar(string $words, int $num): string
261+
if (!function_exists('rmBothSideChar')) {
262+
function rmBothSideChar(string $words, int $num): string
271263
{
272-
return strHelpers::rmChar($words, $num);
264+
return strHelpers::rmBothSideChar($words, $num);
273265
}
274266
}
275267

@@ -329,10 +321,10 @@ function rmBeginningNumbers(string $string): string
329321
}
330322
}
331323

332-
if (!function_exists('rmFinalNumbers')) {
333-
function rmFinalNumbers(string $string): string
324+
if (!function_exists('rmEndingNumbers')) {
325+
function rmEndingNumbers(string $string): string
334326
{
335-
return strHelpers::rmFinalNumbers($string);
327+
return strHelpers::rmEndingNumbers($string);
336328
}
337329
}
338330

src/exceptions/FileDoesNotExistsException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace src\exceptions;
3+
namespace PhpStringHelpers\exceptions;
44

55
use Exception;
66

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace PhpStringHelpers\exceptions;
4+
5+
use Exception;
6+
7+
class LanguageFileIsNotArrayException extends Exception
8+
{
9+
public function __construct(string $message, int $statusCode = 500)
10+
{
11+
parent::__construct($message, $statusCode);
12+
}
13+
}

src/exceptions/UrlIsNotValidException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace src\exceptions;
3+
namespace PhpStringHelpers\exceptions;
44

55
use Exception;
66

0 commit comments

Comments
 (0)