From 988c2179089d542b9dee4d38b1990c666d67da59 Mon Sep 17 00:00:00 2001 From: Sean Morris <640101+seanmorris@users.noreply.github.com> Date: Fri, 6 Dec 2024 14:25:04 -0500 Subject: [PATCH] Fixing url_fopen for 8.4 Static & Shared builds --- packages/vrzno/test/basic.mjs | 674 +++++++++++++++++----------------- 1 file changed, 336 insertions(+), 338 deletions(-) diff --git a/packages/vrzno/test/basic.mjs b/packages/vrzno/test/basic.mjs index edd1c118..ada7e50c 100644 --- a/packages/vrzno/test/basic.mjs +++ b/packages/vrzno/test/basic.mjs @@ -2,464 +2,464 @@ import { test, describe } from 'node:test'; import { strict as assert } from 'node:assert'; import { PhpNode } from '../../../packages/php-wasm/PhpNode.mjs'; -// test('Can access JS integers via php.r function.', async () => { +test('Can access JS integers via php.r function.', async () => { -// const php = new PhpNode(); + const php = new PhpNode(); -// let stdOut = '', stdErr = ''; + let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// await php.binary; + await php.binary; -// const scalarInt = 321; + const scalarInt = 321; -// const exitCode = await php.r` { +test('Can access JS floats via php.r function.', async () => { -// const php = new PhpNode(); + const php = new PhpNode(); -// let stdOut = '', stdErr = ''; + let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// await php.binary; + await php.binary; -// const scalarInt = 321.123; + const scalarInt = 321.123; -// const exitCode = await php.r` { +test('Can access JS strings via php.r function.', async () => { -// const php = new PhpNode(); + const php = new PhpNode(); -// let stdOut = '', stdErr = ''; + let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// await php.binary; + await php.binary; -// const scalarString = "this is a string"; + const scalarString = "this is a string"; -// const exitCode = await php.r` { -// const php = new PhpNode(); +test('Can access PHP strings via php.x function.', async () => { + const php = new PhpNode(); -// let stdOut = '', stdErr = ''; + let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// await php.binary; + await php.binary; -// const scalarString = "this is a string"; + const scalarString = "this is a string"; -// const returnValue = await php.x`${scalarString}`; -// const returnValueIFFE = await php.x`(function() { return ${scalarString} ; })()`; + const returnValue = await php.x`${scalarString}`; + const returnValueIFFE = await php.x`(function() { return ${scalarString} ; })()`; -// assert.equal(returnValue, `this is a string`); -// assert.equal(returnValueIFFE, `this is a string`); -// assert.equal(stdErr, ''); -// }); + assert.equal(returnValue, `this is a string`); + assert.equal(returnValueIFFE, `this is a string`); + assert.equal(stdErr, ''); +}); -// test('Can access PHP integers via php.x function.', async () => { -// const php = new PhpNode(); +test('Can access PHP integers via php.x function.', async () => { + const php = new PhpNode(); -// let stdOut = '', stdErr = ''; + let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// await php.binary; + await php.binary; -// const scalarInt = 321; + const scalarInt = 321; -// const returnValue = await php.x`${scalarInt}`; -// const returnValueIFFE = await php.x`(function() { return ${scalarInt} ; })()`; + const returnValue = await php.x`${scalarInt}`; + const returnValueIFFE = await php.x`(function() { return ${scalarInt} ; })()`; -// assert.equal(returnValue, scalarInt); -// assert.equal(returnValueIFFE, scalarInt); -// assert.equal(stdErr, ''); -// }); + assert.equal(returnValue, scalarInt); + assert.equal(returnValueIFFE, scalarInt); + assert.equal(stdErr, ''); +}); -// describe('Can access PHP floats via php.x function.', async () => { -// test('One float', async () => { -// const php = new PhpNode(); +describe('Can access PHP floats via php.x function.', async () => { + test('One float', async () => { + const php = new PhpNode(); -// let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + let stdOut = '', stdErr = ''; + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// await php.binary; + await php.binary; -// const scalarFloat = 321.123; + const scalarFloat = 321.123; -// const returnValue = await php.x`${scalarFloat}`; -// assert.equal(returnValue, scalarFloat); + const returnValue = await php.x`${scalarFloat}`; + assert.equal(returnValue, scalarFloat); -// const returnValueIFFE = await php.x`(function() { return ${scalarFloat} ; })()`; -// assert.equal(returnValueIFFE, scalarFloat); + const returnValueIFFE = await php.x`(function() { return ${scalarFloat} ; })()`; + assert.equal(returnValueIFFE, scalarFloat); -// assert.equal(stdErr, ''); -// }); + assert.equal(stdErr, ''); + }); -// test('Two floats', async () => { -// const php = new PhpNode(); + test('Two floats', async () => { + const php = new PhpNode(); -// let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + let stdOut = '', stdErr = ''; + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// await php.binary; + await php.binary; -// const scalarFloatA = 1.5; -// const scalarFloatB = 2.1; + const scalarFloatA = 1.5; + const scalarFloatB = 2.1; -// const returnValue = await php.x`${scalarFloatA} + ${scalarFloatB}`; -// assert.equal(returnValue, scalarFloatA + scalarFloatB); + const returnValue = await php.x`${scalarFloatA} + ${scalarFloatB}`; + assert.equal(returnValue, scalarFloatA + scalarFloatB); -// const returnValueIFFE = await php.x`(function() { return ${scalarFloatA} + ${scalarFloatB} ; })()`; -// assert.equal(returnValueIFFE, scalarFloatA + scalarFloatB); + const returnValueIFFE = await php.x`(function() { return ${scalarFloatA} + ${scalarFloatB} ; })()`; + assert.equal(returnValueIFFE, scalarFloatA + scalarFloatB); -// assert.equal(stdErr, ''); -// }); -// }); + assert.equal(stdErr, ''); + }); +}); -// test('Can access JS callbacks via php.r function.', async () => { +test('Can access JS callbacks via php.r function.', async () => { -// const php = new PhpNode(); + const php = new PhpNode(); -// let stdOut = '', stdErr = ''; + let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// await php.binary; + await php.binary; -// class Thing { getString(){ return "This is a value." } }; // This is a Javascript class + class Thing { getString(){ return "This is a value." } }; // This is a Javascript class -// const exitCode = await php.r`getString() );`; + const exitCode = await php.r`getString() );`; -// assert.equal(exitCode, 0); -// assert.equal(stdOut, `string(16) "This is a value."\n`); -// assert.equal(stdErr, ''); -// }); + assert.equal(exitCode, 0); + assert.equal(stdOut, `string(16) "This is a value."\n`); + assert.equal(stdErr, ''); +}); -// describe('Can access JS classes via php.r function.', async () => { +describe('Can access JS classes via php.r function.', async () => { -// test('Can access native JS classes via php.r function.', async () => { -// const php = new PhpNode(); + test('Can access native JS classes via php.r function.', async () => { + const php = new PhpNode(); -// let stdOut = '', stdErr = ''; + let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// await php.binary; + await php.binary; -// const exitCode = await php.r`getFullYear() );`; + const exitCode = await php.r`getFullYear() );`; -// assert.equal(exitCode, 0); -// assert.equal(stdOut, `int(${ (new Date).getFullYear() })\n`); -// assert.equal(stdErr, ''); -// }); + assert.equal(exitCode, 0); + assert.equal(stdOut, `int(${ (new Date).getFullYear() })\n`); + assert.equal(stdErr, ''); + }); -// test('Can access JS user-classes via php.r function.', async () => { -// const php = new PhpNode(); -// await php.binary; + test('Can access JS user-classes via php.r function.', async () => { + const php = new PhpNode(); + await php.binary; -// let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + let stdOut = '', stdErr = ''; + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// class Thing { getString(){ return "This is a value." } }; // This is a Javascript class + class Thing { getString(){ return "This is a value." } }; // This is a Javascript class -// const exitCode = await php.r`getString() );`; + const exitCode = await php.r`getString() );`; -// assert.equal(exitCode, 0); -// assert.equal(stdOut, `string(16) "This is a value."\n`); -// assert.equal(stdErr, ''); -// }); -// }); + assert.equal(exitCode, 0); + assert.equal(stdOut, `string(16) "This is a value."\n`); + assert.equal(stdErr, ''); + }); +}); -// describe('Can access JS classes via php.x function.', async () => { +describe('Can access JS classes via php.x function.', async () => { -// test('Can access native JS classes via php.x function.', async () => { -// const php = new PhpNode(); + test('Can access native JS classes via php.x function.', async () => { + const php = new PhpNode(); -// let stdOut = '', stdErr = ''; + let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// await php.binary; + await php.binary; -// const returnValue = await php.x`(new ${ Date })->getFullYear()`; + const returnValue = await php.x`(new ${ Date })->getFullYear()`; -// assert.equal(returnValue, (new Date).getFullYear()); -// assert.equal(stdOut, ''); -// assert.equal(stdErr, ''); -// }); + assert.equal(returnValue, (new Date).getFullYear()); + assert.equal(stdOut, ''); + assert.equal(stdErr, ''); + }); -// test('Can access JS user-classes via php.x function.', async () => { -// const php = new PhpNode(); + test('Can access JS user-classes via php.x function.', async () => { + const php = new PhpNode(); -// let stdOut = '', stdErr = ''; + let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// await php.binary; + await php.binary; -// class Thing { getString(){ return "This is a value." } }; // This is a Javascript class + class Thing { getString(){ return "This is a value." } }; // This is a Javascript class -// const returnValue = await php.x`(new ${ Thing })->getString()`; + const returnValue = await php.x`(new ${ Thing })->getString()`; -// assert.equal(returnValue, 'This is a value.'); -// assert.equal(stdOut, ''); -// assert.equal(stdErr, ''); -// }); -// }); + assert.equal(returnValue, 'This is a value.'); + assert.equal(stdOut, ''); + assert.equal(stdErr, ''); + }); +}); -// test('Can access PHP callbacks that return integers via php.x function.', async () => { -// const php = new PhpNode(); +test('Can access PHP callbacks that return integers via php.x function.', async () => { + const php = new PhpNode(); -// let stdOut = '', stdErr = ''; + let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// await php.binary; + await php.binary; -// const callback = await php.x`function() { return 321; }`; + const callback = await php.x`function() { return 321; }`; -// const returnValue = callback(); + const returnValue = callback(); -// assert.equal(returnValue, 321); -// assert.equal(stdErr, ''); -// }); + assert.equal(returnValue, 321); + assert.equal(stdErr, ''); +}); -// describe('Can access PHP callbacks that return floats via php.x function.', async () => { -// test('One callback.', async () => { -// const php = new PhpNode(); +describe('Can access PHP callbacks that return floats via php.x function.', async () => { + test('One callback.', async () => { + const php = new PhpNode(); -// let stdOut = '', stdErr = ''; + let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// await php.binary; + await php.binary; -// const callback = await php.x`function() { return 321.123; }`; + const callback = await php.x`function() { return 321.123; }`; -// const returnValue = callback(); + const returnValue = callback(); -// assert.equal(returnValue, 321.123); -// assert.equal(stdErr, ''); -// }); + assert.equal(returnValue, 321.123); + assert.equal(stdErr, ''); + }); -// test('Two callbacks.', async () => { -// const php = new PhpNode(); + test('Two callbacks.', async () => { + const php = new PhpNode(); -// let stdOut = '', stdErr = ''; + let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// await php.binary; + await php.binary; -// const callbackB = await php.x`function($a) { return $a + 2; }`; -// assert.equal(stdOut, ''); -// assert.equal(stdErr, ''); + const callbackB = await php.x`function($a) { return $a + 2; }`; + assert.equal(stdOut, ''); + assert.equal(stdErr, ''); -// const callbackA = await php.x`function($a) { return $a + 1; }`; -// assert.equal(stdOut, ''); -// assert.equal(stdErr, ''); + const callbackA = await php.x`function($a) { return $a + 1; }`; + assert.equal(stdOut, ''); + assert.equal(stdErr, ''); -// const returnValueA = callbackA(0); -// const returnValueB = callbackB(returnValueA); + const returnValueA = callbackA(0); + const returnValueB = callbackB(returnValueA); -// assert.equal(returnValueA, 1); -// assert.equal(returnValueB, 3); -// }); -// }); + assert.equal(returnValueA, 1); + assert.equal(returnValueB, 3); + }); +}); -// test('Can access PHP callbacks that return single-character strings via php.x function.', async () => { -// const php = new PhpNode(); +test('Can access PHP callbacks that return single-character strings via php.x function.', async () => { + const php = new PhpNode(); -// let stdOut = '', stdErr = ''; + let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// await php.binary; + await php.binary; -// const callback = await php.x`function() { return "a"; }`; + const callback = await php.x`function() { return "a"; }`; -// const returnValue = callback(); + const returnValue = callback(); -// assert.equal(returnValue, "a"); -// assert.equal(stdErr, ''); -// }); + assert.equal(returnValue, "a"); + assert.equal(stdErr, ''); +}); -// test('Can access PHP callbacks that return multi-character strings via php.x function.', async () => { -// const php = new PhpNode(); +test('Can access PHP callbacks that return multi-character strings via php.x function.', async () => { + const php = new PhpNode(); -// let stdOut = '', stdErr = ''; + let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// await php.binary; + await php.binary; -// const callback = await php.x`function() { return "abcdefg hijklmn op"; }`; + const callback = await php.x`function() { return "abcdefg hijklmn op"; }`; -// const returnValue = callback(); + const returnValue = callback(); -// assert.equal(returnValue, "abcdefg hijklmn op"); -// assert.equal(stdOut, ''); -// assert.equal(stdErr, ''); -// }); + assert.equal(returnValue, "abcdefg hijklmn op"); + assert.equal(stdOut, ''); + assert.equal(stdErr, ''); +}); -// describe('Can access PHP callbacks that return objects via php.x function.', async () => { -// test('One level deep.', async () => { -// const php = new PhpNode(); +describe('Can access PHP callbacks that return objects via php.x function.', async () => { + test('One level deep.', async () => { + const php = new PhpNode(); -// let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + let stdOut = '', stdErr = ''; + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// await php.binary; + await php.binary; -// const callback = await php.x`function() { return (object)["a" => "abcdefg"]; }`; -// const returnValue = callback(); + const callback = await php.x`function() { return (object)["a" => "abcdefg"]; }`; + const returnValue = callback(); -// assert.equal(returnValue.a, "abcdefg"); -// assert.equal(stdOut, ''); -// assert.equal(stdErr, ''); -// }); + assert.equal(returnValue.a, "abcdefg"); + assert.equal(stdOut, ''); + assert.equal(stdErr, ''); + }); -// test('Two levels deep.', async () => { -// const php = new PhpNode(); + test('Two levels deep.', async () => { + const php = new PhpNode(); -// let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + let stdOut = '', stdErr = ''; + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// await php.binary; + await php.binary; -// const callback = await php.x`function() { return function() { return (object)["a" => "abcdefg"]; }; }`; -// const returnValue = callback()(); + const callback = await php.x`function() { return function() { return (object)["a" => "abcdefg"]; }; }`; + const returnValue = callback()(); -// assert.equal(returnValue.a, "abcdefg"); -// assert.equal(stdOut, ''); -// assert.equal(stdErr, ''); -// }); -// }); + assert.equal(returnValue.a, "abcdefg"); + assert.equal(stdOut, ''); + assert.equal(stdErr, ''); + }); +}); -// test('Can get the date with strtotime() and format it with date().', async () => { -// const php = new PhpNode(); +test('Can get the date with strtotime() and format it with date().', async () => { + const php = new PhpNode(); -// let stdOut = '', stdErr = ''; + let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// await php.binary; + await php.binary; -// // Get yesterday's date and format in JS... -// const yesterday = new Date(new Date().getTime() - (24 * 60 * 60 * 1000)); -// const jsFormatted = `${yesterday.getFullYear()}-${String(1 + yesterday.getMonth()).padStart(2, '0')}-${String(yesterday.getDate()).padStart(2, '0')} 13:00:00`; + // Get yesterday's date and format in JS... + const yesterday = new Date(new Date().getTime() - (24 * 60 * 60 * 1000)); + const jsFormatted = `${yesterday.getFullYear()}-${String(1 + yesterday.getMonth()).padStart(2, '0')}-${String(yesterday.getDate()).padStart(2, '0')} 13:00:00`; -// // Extract the functions from PHP... -// const strtotime = await php.x`strtotime(...)`; -// const date = await php.x`date(...)`; + // Extract the functions from PHP... + const strtotime = await php.x`strtotime(...)`; + const date = await php.x`date(...)`; -// // Set the timezone... -// await php.x`date_default_timezone_set(${Intl.DateTimeFormat().resolvedOptions().timeZone})`; + // Set the timezone... + await php.x`date_default_timezone_set(${Intl.DateTimeFormat().resolvedOptions().timeZone})`; -// // Get yesterday's date and format in PHP... -// const phpFormatted = date('Y-m-d H:i:s', strtotime('yesterday 1PM')); + // Get yesterday's date and format in PHP... + const phpFormatted = date('Y-m-d H:i:s', strtotime('yesterday 1PM')); -// assert.equal(jsFormatted, phpFormatted); + assert.equal(jsFormatted, phpFormatted); -// assert.equal(stdOut, ''); -// assert.equal(stdErr, ''); -// }); + assert.equal(stdOut, ''); + assert.equal(stdErr, ''); +}); -// test('Can get the date from a native object with strtotime() and format it with date().', async () => { -// const php = new PhpNode(); +test('Can get the date from a native object with strtotime() and format it with date().', async () => { + const php = new PhpNode(); -// let stdOut = '', stdErr = ''; + let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// await php.binary; + await php.binary; -// // Get yesterday's date and format in JS... -// const yesterday = new Date(); -// const jsFormatted = `${yesterday.getFullYear()}-${String(1 + yesterday.getMonth()).padStart(2, '0')}-${String(yesterday.getDate()).padStart(2, '0')}` -// + ` ${String(yesterday.getHours()).padStart(2, '0')}:${String(yesterday.getMinutes()).padStart(2, '0')}:${String(yesterday.getSeconds()).padStart(2, '0')}`; + // Get yesterday's date and format in JS... + const yesterday = new Date(); + const jsFormatted = `${yesterday.getFullYear()}-${String(1 + yesterday.getMonth()).padStart(2, '0')}-${String(yesterday.getDate()).padStart(2, '0')}` + + ` ${String(yesterday.getHours()).padStart(2, '0')}:${String(yesterday.getMinutes()).padStart(2, '0')}:${String(yesterday.getSeconds()).padStart(2, '0')}`; -// // Set the timezone... -// await php.x`date_default_timezone_set(${Intl.DateTimeFormat().resolvedOptions().timeZone})`; + // Set the timezone... + await php.x`date_default_timezone_set(${Intl.DateTimeFormat().resolvedOptions().timeZone})`; -// // Create a formateDate callback in PHP... -// const formatDate = await php.x`function() { -// $nativeJsDateClass = ${Date}; -// $nativeJsDateObject = new $nativeJsDateClass; -// $isoString = $nativeJsDateObject->toISOString(); -// $timestamp = strtotime($isoString); -// $formatted = date('Y-m-d H:i:s', $timestamp); -// return $formatted; -// }`; + // Create a formateDate callback in PHP... + const formatDate = await php.x`function() { + $nativeJsDateClass = ${Date}; + $nativeJsDateObject = new $nativeJsDateClass; + $isoString = $nativeJsDateObject->toISOString(); + $timestamp = strtotime($isoString); + $formatted = date('Y-m-d H:i:s', $timestamp); + return $formatted; + }`; -// const phpFormatted = formatDate(); + const phpFormatted = formatDate(); -// assert.equal(jsFormatted, phpFormatted); + assert.equal(jsFormatted, phpFormatted); -// assert.equal(stdOut, ''); -// assert.equal(stdErr, ''); -// }); + assert.equal(stdOut, ''); + assert.equal(stdErr, ''); +}); -// test('Can use url_fopen with file_get_contents.', async () => { -// const php = new PhpNode(); +test('Can use url_fopen with file_get_contents.', async () => { + const php = new PhpNode(); -// let stdOut = '', stdErr = ''; + let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// await php.binary; + await php.binary; -// const json = JSON.parse(await php.x`file_get_contents('https://jsonplaceholder.typicode.com/users')`); + const json = JSON.parse(await php.x`file_get_contents('https://jsonplaceholder.typicode.com/users')`); -// assert.equal(typeof json, 'object'); -// assert.equal(Array.isArray(json), true); -// assert.equal(json.length, 10); -// }); + assert.equal(typeof json, 'object'); + assert.equal(Array.isArray(json), true); + assert.equal(json.length, 10); +}); test('Can get headers from url_fopen with file_get_contents.', async () => { const php = new PhpNode(); @@ -471,58 +471,56 @@ test('Can get headers from url_fopen with file_get_contents.', async () => { await php.binary; - const json = (await php.x`(function(){ + const json = JSON.parse(await php.x`(function(){ file_get_contents('https://jsonplaceholder.typicode.com/users'); return json_encode($http_response_header); })()`); - console.log(json, stdOut, stdErr); - - // assert.equal(typeof json, 'object'); - // assert.equal(Array.isArray(json), true); + assert.equal(typeof json, 'object'); + assert.equal(Array.isArray(json), true); }); -// test('Can use url_fopen with file_get_contents with a context.', async () => { -// const php = new PhpNode(); +test('Can use url_fopen with file_get_contents with a context.', async () => { + const php = new PhpNode(); -// let stdOut = '', stdErr = ''; + let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// await php.binary; + await php.binary; -// const json = JSON.parse(await php.x`(function(){ -// $opts = ['http' => ['method' => 'GET']]; -// $context = stream_context_create($opts); -// return file_get_contents('https://jsonplaceholder.typicode.com/users', false, $context); -// })()`); + const json = JSON.parse(await php.x`(function(){ + $opts = ['http' => ['method' => 'GET']]; + $context = stream_context_create($opts); + return file_get_contents('https://jsonplaceholder.typicode.com/users', false, $context); + })()`); -// assert.equal(typeof json, 'object'); -// assert.equal(Array.isArray(json), true); -// assert.equal(json.length, 10); -// }); + assert.equal(typeof json, 'object'); + assert.equal(Array.isArray(json), true); + assert.equal(json.length, 10); +}); -// test('Can use url_fopen with file_get_contents with a context. (POST) ', async () => { -// const php = new PhpNode(); +test('Can use url_fopen with file_get_contents with a context. (POST) ', async () => { + const php = new PhpNode(); -// let stdOut = '', stdErr = ''; + let stdOut = '', stdErr = ''; -// php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); -// php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); + php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line))); + php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line))); -// await php.binary; + await php.binary; -// const json = JSON.parse(await php.x`(function(){ -// $opts = ['http' => [ -// 'method' => 'POST', -// 'header' => 'Content-type: application/json', -// 'content' => json_encode(['UID'=>0]), -// ]]; -// $context = stream_context_create($opts); -// return file_get_contents('https://jsonplaceholder.typicode.com/users', false, $context); -// })()`); + const json = JSON.parse(await php.x`(function(){ + $opts = ['http' => [ + 'method' => 'POST', + 'header' => 'Content-type: application/json', + 'content' => json_encode(['UID'=>0]), + ]]; + $context = stream_context_create($opts); + return file_get_contents('https://jsonplaceholder.typicode.com/users', false, $context); + })()`); -// assert.equal(typeof json, 'object'); -// assert.equal(Array.isArray(json), false); -// }); + assert.equal(typeof json, 'object'); + assert.equal(Array.isArray(json), false); +});