Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Jul 6, 2024
1 parent 5561e8a commit 936402e
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 71 deletions.
6 changes: 3 additions & 3 deletions tests/swoole_coroutine/check.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ $map = [
Assert::assert(0); // never here
},
function () {
Co::fread(STDIN);
fread(STDIN);
Assert::assert(0); // never here
},
function () {
Co::fgets(fopen(__FILE__, 'r'));
fgets(fopen(__FILE__, 'r'));
Assert::assert(0); // never here
},
function () {
Co::fwrite(fopen(TEST_LOG_FILE, 'w+'), 'foo');
fwrite(fopen(TEST_LOG_FILE, 'w+'), 'foo');
Assert::assert(0); // never here
},
function () {
Expand Down
5 changes: 2 additions & 3 deletions tests/swoole_coroutine/output/in_nested_co.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ swoole_coroutine/output: use ob_* in nest co
--FILE--
<?php
require __DIR__ . '/../../include/bootstrap.php';
go(function () {
Co\run(function () {
ob_start();
echo "2\n"; // [#1] yield
go(function () {
echo "1\n"; // [#2] output: 1
co::fgets(fopen(__FILE__, 'r')); // yield
fgets(fopen(__FILE__, 'r')); // yield
// [#4] resume
ob_start(); // to buffer
echo "4\n";
}); // [#5] destroyed and output: 4
echo "3\n";
}); // [#3] destroyed and output: 2 3
Swoole\Event::wait();
?>
--EXPECT--
1
Expand Down
4 changes: 2 additions & 2 deletions tests/swoole_coroutine/output/ob_main.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ swoole_coroutine/output: main output global
require __DIR__ . '/../../include/bootstrap.php';
ob_start();
echo 'aaa';
go(function () {
Co\run(function () {
ob_start();
echo 'bbb';
co::fgets(fopen(__FILE__, 'r'));
fgets(fopen(__FILE__, 'r'));
Assert::same(ob_get_clean(), 'bbb');
});
Assert::same(ob_get_clean(), 'aaa');
Expand Down
21 changes: 6 additions & 15 deletions tests/swoole_coroutine_util/fgets.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,24 @@ swoole_coroutine_util: fgets
<?php
require __DIR__ . '/../include/bootstrap.php';

Co::set(['hook_flags' => 0]);

Co\run(function () {
$file = __DIR__ . '/../../examples/server/mixed.php';

$coroutine = '';
$fp = fopen($file, "r");
while (!feof($fp)) {
$coroutine .= co::fgets($fp);
}

$standard = '';
Swoole\Runtime::enableCoroutine(SWOOLE_HOOK_ALL);
$coroutine = [];
$fp = fopen($file, "r");
while (!feof($fp)) {
$standard .= fgets($fp);
$coroutine [] = fgets($fp);
}

Swoole\Runtime::enableCoroutine();
$runtime = '';
Swoole\Runtime::enableCoroutine(false);
$standard = [];
$fp = fopen($file, "r");
while (!feof($fp)) {
$runtime .= fgets($fp);
$standard [] = fgets($fp);
}

Assert::same($standard, $coroutine);
Assert::same($standard, $runtime);

echo "DONE\n";
});
?>
Expand Down
15 changes: 4 additions & 11 deletions tests/swoole_coroutine_util/fread.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,14 @@ swoole_coroutine_util: fread
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';

use Swoole\Coroutine as co;

co::create(function () {
Co\run(function () {
$fp = fopen(TEST_IMAGE, 'r');
if ($fp)
{
$data = co::fread($fp);
if ($fp) {
$data = fread($fp, 1024 * 1024);
Assert::same(md5($data), md5_file(TEST_IMAGE));
}
else
{
} else {
echo "ERROR\n";
}
});

?>
--EXPECT--
26 changes: 0 additions & 26 deletions tests/swoole_coroutine_util/fread_seek.phpt

This file was deleted.

15 changes: 4 additions & 11 deletions tests/swoole_coroutine_util/fwrite.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,20 @@ swoole_coroutine_util: fwrite
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';

use Swoole\Coroutine as co;

co::create(function () {
Co\run(function () {
$file = __DIR__ . '/tmp';
$fp = fopen($file, 'w+');
$data = RandStr::gen(8192 * 8);
if ($fp)
{
$ret = co::fwrite($fp, $data);
if ($ret)
{
if ($fp) {
$ret = fwrite($fp, $data);
if ($ret) {
Assert::same(md5($data), md5_file($file));
unlink($file);

return;
}
}
unlink($file);
echo "ERROR\n";
});

?>
--EXPECT--

0 comments on commit 936402e

Please sign in to comment.