diff --git a/packages/php-wasm/node/src/test/php.spec.ts b/packages/php-wasm/node/src/test/php.spec.ts index 40e62f8cf4..f099dbee44 100644 --- a/packages/php-wasm/node/src/test/php.spec.ts +++ b/packages/php-wasm/node/src/test/php.spec.ts @@ -1163,6 +1163,12 @@ describe.each(SupportedPHPVersions)('PHP %s', (phpVersion) => { }); }); + describe('Interface', () => { + it('run() should throw an error when neither `code` nor `scriptFile` is provided', async () => { + expect(() => php.run({})).rejects.toThrowError(TypeError); + }); + }); + describe('Startup sequence – basics', () => { /** * This test ensures that the PHP runtime can be loaded twice. diff --git a/packages/php-wasm/universal/src/lib/php.ts b/packages/php-wasm/universal/src/lib/php.ts index f742e75cbc..3afd021875 100644 --- a/packages/php-wasm/universal/src/lib/php.ts +++ b/packages/php-wasm/universal/src/lib/php.ts @@ -430,8 +430,13 @@ export class PHP implements Disposable { if (typeof request.code === 'string') { this.writeFile('/internal/eval.php', request.code); this.#setScriptPath('/internal/eval.php'); - } else { + } else if (typeof request.scriptPath === 'string') { this.#setScriptPath(request.scriptPath || ''); + } else { + throw new TypeError( + 'The request object must have either a `code` or a ' + + '`scriptPath` property.' + ); } const $_SERVER = this.#prepareServerEntries(