Skip to content

Commit

Permalink
Optimize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Jul 6, 2024
1 parent 862ddaf commit 5561e8a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
18 changes: 18 additions & 0 deletions examples/thread/map.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
use Swoole\Thread;
$args = Thread::getArguments();

if (empty($args)) {
$array = [
'a' => random_int(1, 999999999999999999),
'b' => random_bytes(128),
'c' => uniqid(),
'd' => time(),
];

$map = new Thread\Map($array);
$thread = new Thread(__FILE__, $map);
} else {
$map = $args[0];
var_dump($map->toArray());
}
28 changes: 28 additions & 0 deletions tests/swoole_runtime/file_hook/fgets.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
swoole_runtime/file_hook: fgets
--SKIPIF--
<?php
require __DIR__ . '/../../include/skipif.inc';
?>
--FILE--
<?php
require __DIR__ . '/../../include/bootstrap.php';

$testFn = function () {
$fp = fopen(__FILE__, 'r');
$lines[] = fgets($fp);
fclose($fp);
return $lines;
};

Swoole\Runtime::enableCoroutine(false);
$lines = $testFn();

Co\run(function () use ($testFn, $lines) {
Swoole\Runtime::enableCoroutine();
$lines_2 = $testFn();
Swoole\Runtime::enableCoroutine(false);
Assert::eq($lines, $lines_2);
});
?>
--EXPECT--
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Swoole\Runtime::enableCoroutine();
go(function () {
$fp = fopen(__FILE__, 'r');
echo "open\n";
$data = Co::fread($fp, 1024);
$data = fread($fp, 1024);
echo "read\n";
Swoole\Runtime::enableCoroutine(false);
Assert::assert(!empty($data));
Expand Down
2 changes: 2 additions & 0 deletions tests/swoole_thread/arraylist.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ $array = [
];

$l = new ArrayList($array);
Assert::eq(count($l), count($array));
Assert::eq($l->toArray(), $array);

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

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

try {
Expand Down
4 changes: 3 additions & 1 deletion tests/swoole_thread/map.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ $array = [

$m = new Map($array);
Assert::eq($m->toArray(), $array);
Assert::eq(count($m), count($array));

foreach ($array as $k => $v) {
Assert::eq($m[$k], $array[$k]);
Expand All @@ -30,8 +31,9 @@ $array2 = [
'hello' => 'world',
];
$m['map'] = $array2;

Assert::eq(count($m), 5);
Assert::eq($m['map']->toArray(), $array2);
Assert::eq(count($m['map']), count($array2));
Assert::eq($m['map']->values(), array_values($array2));
?>
--EXPECTF--

0 comments on commit 5561e8a

Please sign in to comment.