Skip to content

Commit 5561e8a

Browse files
committed
Optimize tests
1 parent 862ddaf commit 5561e8a

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

examples/thread/map.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
use Swoole\Thread;
3+
$args = Thread::getArguments();
4+
5+
if (empty($args)) {
6+
$array = [
7+
'a' => random_int(1, 999999999999999999),
8+
'b' => random_bytes(128),
9+
'c' => uniqid(),
10+
'd' => time(),
11+
];
12+
13+
$map = new Thread\Map($array);
14+
$thread = new Thread(__FILE__, $map);
15+
} else {
16+
$map = $args[0];
17+
var_dump($map->toArray());
18+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
swoole_runtime/file_hook: fgets
3+
--SKIPIF--
4+
<?php
5+
require __DIR__ . '/../../include/skipif.inc';
6+
?>
7+
--FILE--
8+
<?php
9+
require __DIR__ . '/../../include/bootstrap.php';
10+
11+
$testFn = function () {
12+
$fp = fopen(__FILE__, 'r');
13+
$lines[] = fgets($fp);
14+
fclose($fp);
15+
return $lines;
16+
};
17+
18+
Swoole\Runtime::enableCoroutine(false);
19+
$lines = $testFn();
20+
21+
Co\run(function () use ($testFn, $lines) {
22+
Swoole\Runtime::enableCoroutine();
23+
$lines_2 = $testFn();
24+
Swoole\Runtime::enableCoroutine(false);
25+
Assert::eq($lines, $lines_2);
26+
});
27+
?>
28+
--EXPECT--

tests/swoole_runtime/file_hook/co_fread.phpt renamed to tests/swoole_runtime/file_hook/fread.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Swoole\Runtime::enableCoroutine();
1313
go(function () {
1414
$fp = fopen(__FILE__, 'r');
1515
echo "open\n";
16-
$data = Co::fread($fp, 1024);
16+
$data = fread($fp, 1024);
1717
echo "read\n";
1818
Swoole\Runtime::enableCoroutine(false);
1919
Assert::assert(!empty($data));

tests/swoole_thread/arraylist.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ $array = [
1919
];
2020

2121
$l = new ArrayList($array);
22+
Assert::eq(count($l), count($array));
2223
Assert::eq($l->toArray(), $array);
2324

2425
for ($i = 0; $i < count($array); $i++) {
@@ -31,6 +32,7 @@ $array2 = [
3132
];
3233
$l[] = $array2;
3334

35+
Assert::eq(count($l), 5);
3436
Assert::eq($l[4]->toArray(), $array2);
3537

3638
try {

tests/swoole_thread/map.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ $array = [
2020

2121
$m = new Map($array);
2222
Assert::eq($m->toArray(), $array);
23+
Assert::eq(count($m), count($array));
2324

2425
foreach ($array as $k => $v) {
2526
Assert::eq($m[$k], $array[$k]);
@@ -30,8 +31,9 @@ $array2 = [
3031
'hello' => 'world',
3132
];
3233
$m['map'] = $array2;
33-
34+
Assert::eq(count($m), 5);
3435
Assert::eq($m['map']->toArray(), $array2);
36+
Assert::eq(count($m['map']), count($array2));
3537
Assert::eq($m['map']->values(), array_values($array2));
3638
?>
3739
--EXPECTF--

0 commit comments

Comments
 (0)