Skip to content

Support proc_open(), exec(), passthru(), system() #596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Oct 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add unit tests for popen()
  • Loading branch information
adamziel committed Oct 24, 2023
commit bb891270a9ee586d84f7c19bf9fd1543d41b9713
35 changes: 34 additions & 1 deletion packages/php-wasm/node/src/test/php.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { existsSync, rmSync, readFileSync } from 'fs';
const testDirPath = '/__test987654321';
const testFilePath = '/__test987654321.txt';

// SupportedPHPVersions
describe.each(SupportedPHPVersions)('PHP %s', (phpVersion) => {
let php: NodePHP;
beforeEach(async () => {
Expand All @@ -29,6 +28,40 @@ describe.each(SupportedPHPVersions)('PHP %s', (phpVersion) => {
});
});

describe('popen()', () => {
it('popen("echo", "r")', async () => {
const result = await php.run({
code: `<?php
$fp = popen("echo WordPress", "r");
echo 'stdout: ' . fread($fp, 1024);
fclose($fp);
`,
});
expect(result.text).toEqual('stdout: WordPress\n');
});

it('popen("cat", "w")', async () => {
const result = await php.run({
code: `<?php
$path = __DIR__;
$fp = popen("cat > out", "w");
fwrite($fp, "WordPress\n");
fclose($fp);

// Yields back to JS event loop to give the child process a chance
// to process the input.
sleep(1);

$fp = popen("cat out", "r");
echo 'stdout: ' . fread($fp, 1024);
fclose($fp);
`,
});

expect(result.text).toEqual('stdout: WordPress\n');
});
});

describe('proc_open()', () => {
it('echo – stdin=file (empty), stdout=file, stderr=file', async () => {
const result = await php.run({
Expand Down