Skip to content

Commit e902c97

Browse files
committed
update some for test boot file
1 parent 874be92 commit e902c97

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

src/File.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,17 @@ public static function streamOpen(string $path)
301301
* @param string $content The content to write.
302302
* @param string $path The path to the file (for exception printing only).
303303
*
304+
* @return int
304305
* @throws IOException
305306
*/
306-
public static function streamWrite($stream, string $content, string $path = ''): void
307+
public static function streamWrite($stream, string $content, string $path = ''): int
307308
{
308309
// self::assertWritableStream($stream);
309-
310-
if (($result = fwrite($stream, $content)) === false || ($result < strlen($content))) {
310+
if (($result = fwrite($stream, $content)) === false) {
311311
throw new IOException('The file "' . $path . '" could not be written to. Check your disk space and file permissions.');
312312
}
313+
314+
return $result;
313315
}
314316

315317
/**

test/bootstrap.php

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
1-
<?php
1+
<?php declare(strict_types=1);
22
/**
3-
* phpunit
3+
* phpunit --bootstrap tests/boot.php tests
44
*/
55

6-
error_reporting(E_ALL);
7-
ini_set('display_errors', 'On');
6+
error_reporting(E_ALL | E_STRICT);
87
date_default_timezone_set('Asia/Shanghai');
98

10-
spl_autoload_register(static function ($class) {
11-
$file = null;
9+
$libDir = dirname(__DIR__);
10+
$npMap = [
11+
'Toolkit\\FsUtil\\Example\\' => $libDir . '/example/',
12+
'Toolkit\\FsUtilTest\\' => $libDir . '/test/',
13+
'Toolkit\\FsUtil\\' => $libDir . '/src/',
14+
];
1215

13-
if (0 === strpos($class, 'Toolkit\FsUtil\Example\\')) {
14-
$path = str_replace('\\', '/', substr($class, strlen('Toolkit\FsUtil\Example\\')));
15-
$file = dirname(__DIR__) . "/example/{$path}.php";
16-
} elseif (0 === strpos($class, 'Toolkit\FsUtilTest\\')) {
17-
$path = str_replace('\\', '/', substr($class, strlen('Toolkit\FsUtilTest\\')));
18-
$file = __DIR__ . "/{$path}.php";
19-
} elseif (0 === strpos($class, 'Toolkit\FsUtil\\')) {
20-
$path = str_replace('\\', '/', substr($class, strlen('Toolkit\FsUtil\\')));
21-
$file = dirname(__DIR__) . "/src/{$path}.php";
22-
}
16+
spl_autoload_register(static function ($class) use ($npMap) {
17+
foreach ($npMap as $np => $dir) {
18+
$file = $dir . str_replace('\\', '/', substr($class, strlen($np))) . '.php';
2319

24-
if ($file && is_file($file)) {
25-
include $file;
20+
if (file_exists($file)) {
21+
include $file;
22+
}
2623
}
2724
});
2825

@@ -31,4 +28,3 @@
3128
} elseif (is_file(dirname(__DIR__) . '/vendor/autoload.php')) {
3229
require dirname(__DIR__) . '/vendor/autoload.php';
3330
}
34-

0 commit comments

Comments
 (0)