Skip to content

Commit c1d63ab

Browse files
committed
add some tests for str len
1 parent 6c549f1 commit c1d63ab

File tree

3 files changed

+60
-8
lines changed

3 files changed

+60
-8
lines changed

phpunit.xml.dist

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit backupGlobals="false"
4+
backupStaticAttributes="false"
5+
bootstrap="test/bootstrap.php"
6+
colors="false"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
stopOnFailure="false"
11+
12+
>
13+
<testsuites>
14+
<testsuite name="Php Library Test Suite">
15+
<directory>test</directory>
16+
</testsuite>
17+
</testsuites>
18+
19+
<filter>
20+
<whitelist>
21+
<directory suffix=".php">src</directory>
22+
</whitelist>
23+
</filter>
24+
</phpunit>

test/Str/StringHelperTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Toolkit\StdlibTest\Str;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Toolkit\Stdlib\Str;
7+
8+
/**
9+
* Class StringHelperTest
10+
*
11+
* @package Toolkit\StdlibTest\Str
12+
*/
13+
class StringHelperTest extends TestCase
14+
{
15+
public function testStrLen(): void
16+
{
17+
$tests = [
18+
['abc', 3],
19+
[123, 3],
20+
[123.4, 5],
21+
['23ab', 4],
22+
];
23+
24+
foreach ($tests as [$case, $want]) {
25+
$this->assertSame($want, Str::strlen($case));
26+
}
27+
}
28+
}

test/bootstrap.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
date_default_timezone_set('Asia/Shanghai');
1212

1313
spl_autoload_register(static function ($class): void {
14-
$file = null;
14+
$file = '';
1515

16-
if (0 === strpos($class, 'Inhere\Console\Examples\\')) {
17-
$path = str_replace('\\', '/', substr($class, strlen('Inhere\Console\Examples\\')));
18-
$file = dirname(__DIR__) . "/examples/{$path}.php";
19-
} elseif (0 === strpos($class, 'Inhere\ConsoleTest\\')) {
20-
$path = str_replace('\\', '/', substr($class, strlen('Inhere\ConsoleTest\\')));
16+
if (0 === strpos($class, 'Toolkit\Stdlib\Example\\')) {
17+
$path = str_replace('\\', '/', substr($class, strlen('Toolkit\Stdlib\Example\\')));
18+
$file = dirname(__DIR__) . "/example/{$path}.php";
19+
} elseif (0 === strpos($class, 'Toolkit\StdlibTest\\')) {
20+
$path = str_replace('\\', '/', substr($class, strlen('Toolkit\StdlibTest\\')));
2121
$file = __DIR__ . "/{$path}.php";
22-
} elseif (0 === strpos($class, 'Inhere\Console\\')) {
23-
$path = str_replace('\\', '/', substr($class, strlen('Inhere\Console\\')));
22+
} elseif (0 === strpos($class, 'Toolkit\Stdlib\\')) {
23+
$path = str_replace('\\', '/', substr($class, strlen('Toolkit\Stdlib\\')));
2424
$file = dirname(__DIR__) . "/src/{$path}.php";
2525
}
2626

0 commit comments

Comments
 (0)