Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Work in progress. Aims to solves #111
To test, run
npx jest ./src/php-wasm/__tests__/php.ts
How does it work?
Here's a step-by-step log of how I arrived at this PR:
Step 0: Get a working
wordpress-develop
setupClone the repo, install composer dependencies, and build WordPress as you normally would.
Step 1: Patch PHPUnit and bootstrap.php
I had to update the following files to get the tests running:
#!/usr/bin/env php
shebang fromvendor/bin/phpunit
andvendor/phpunit/phpunit/phpunit
– WASM SAPI does not understand itmbstring
andxmlwriter
from the list of required PHP extensions invendor/phpunit/phpunit/phpunit
- WASM SAPI does not support them yet (although perhaps adding support wouldn't be too hard)gd
from the list of required PHP extensions intest/phpunit/includes/bootstrap.php
Step 2: Package wordpress-develop
Then, I turned wordpress-develop into an emscripten data bundle using the following Dockerfile:
I then ran it as follows:
As a result, I got two files:
wp-dev.js
andwp-dev.data
.Step 3: Build Playground for node.js and with Libxml support
The default WordPress playground build does not support libxml so I re-ran the
build:php:node:8.0
script withWITH_LIBXML=yes
env variable.Step 4: Run PHPUnit inside a jest test
Jest is already configured to run a node.js build of PHP which makes it a convenient choice for this PoC. I added the following test:
The output
A few PHP warnings aside, it works nicely!
cc @hellofromtonya