Skip to content

Commit 8a01fac

Browse files
authored
[ php-wasm ] Intl : Improve integration (#159)
## Motivation for the change, related issues Based on pull request [#150](Automattic/wordpress-playground-private#150) ## Implementation details - [x] Add intl extension test in php.spec.ts - [x] Shorten jobs implementation in `worklflows/ci.yml` with matrix syntax ## Testing Instructions (or ideally a Blueprint) CI
1 parent fc24cb0 commit 8a01fac

File tree

3 files changed

+98
-156
lines changed

3 files changed

+98
-156
lines changed

.github/workflows/ci.yml

Lines changed: 22 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -23,94 +23,28 @@ jobs:
2323
- uses: ./.github/actions/prepare-playground
2424
- run: npx nx affected --target=lint
2525
- run: npx nx affected --target=typecheck
26-
test-unit-asyncify-node-1-out-of-7:
27-
runs-on: wordpress-playground-private
28-
needs: [lint-and-typecheck]
29-
services:
30-
mysql:
31-
image: mysql:5.7
32-
env:
33-
MYSQL_DATABASE: test_db
34-
MYSQL_USER: user
35-
MYSQL_PASSWORD: password
36-
MYSQL_ROOT_PASSWORD: rootpassword
37-
ports:
38-
- 3306:3306
39-
options: >-
40-
--health-cmd="mysqladmin ping --silent"
41-
--health-interval=10s
42-
--health-timeout=5s
43-
--health-retries=3
44-
steps:
45-
- uses: actions/checkout@v4
46-
with:
47-
submodules: true
48-
- uses: ./.github/actions/prepare-playground
49-
with:
50-
node-version: 20
51-
- run: node --expose-gc node_modules/nx/bin/nx affected --target=test --configuration=ci
52-
env:
53-
MYSQL_DATABASE: test_db
54-
MYSQL_USER: user
55-
MYSQL_PASSWORD: password
56-
test-unit-asyncify-node-2-out-of-7:
57-
runs-on: wordpress-playground-private
58-
needs: [lint-and-typecheck]
59-
steps:
60-
- uses: actions/checkout@v4
61-
with:
62-
submodules: true
63-
- uses: ./.github/actions/prepare-playground
64-
with:
65-
node-version: 20
66-
- run: node --expose-gc node_modules/nx/bin/nx affected --target=test-php
67-
test-unit-asyncify-node-3-out-of-7:
68-
runs-on: wordpress-playground-private
69-
needs: [lint-and-typecheck]
70-
steps:
71-
- uses: actions/checkout@v4
72-
with:
73-
submodules: true
74-
- uses: ./.github/actions/prepare-playground
75-
with:
76-
node-version: 20
77-
- run: node --expose-gc node_modules/nx/bin/nx affected --target=test-php-asyncify-file-get-contents
78-
test-unit-asyncify-node-4-out-of-7:
79-
runs-on: wordpress-playground-private
80-
needs: [lint-and-typecheck]
81-
steps:
82-
- uses: actions/checkout@v4
83-
with:
84-
submodules: true
85-
- uses: ./.github/actions/prepare-playground
86-
with:
87-
node-version: 20
88-
- run: node --expose-gc node_modules/nx/bin/nx affected --target=test-php-asyncify-fopen
89-
test-unit-asyncify-node-5-out-of-7:
90-
runs-on: wordpress-playground-private
91-
needs: [lint-and-typecheck]
92-
steps:
93-
- uses: actions/checkout@v4
94-
with:
95-
submodules: true
96-
- uses: ./.github/actions/prepare-playground
97-
with:
98-
node-version: 20
99-
- run: node --expose-gc node_modules/nx/bin/nx affected --target=test-php-asyncify-fsockopen
100-
test-unit-asyncify-node-6-out-of-7:
101-
runs-on: wordpress-playground-private
102-
needs: [lint-and-typecheck]
103-
steps:
104-
- uses: actions/checkout@v4
105-
with:
106-
submodules: true
107-
- uses: ./.github/actions/prepare-playground
108-
with:
109-
node-version: 20
110-
- run: node --expose-gc node_modules/nx/bin/nx affected --target=test-php-asyncify-gethostbyname
111-
test-unit-asyncify-node-7-out-of-7:
26+
test-unit-asyncify:
11227
runs-on: wordpress-playground-private
11328
needs: [lint-and-typecheck]
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
include:
33+
- name: test-unit-asyncify (1/7)
34+
target: test
35+
- name: test-unit-asyncify (2/7)
36+
target: test-php
37+
- name: test-unit-asyncify (3/7)
38+
target: test-php-asyncify-file-get-contents
39+
- name: test-unit-asyncify (4/7)
40+
target: test-php-asyncify-fopen
41+
- name: test-unit-asyncify (5/7)
42+
target: test-php-asyncify-fsockopen
43+
- name: test-unit-asyncify (6/7)
44+
target: test-php-asyncify-gethostbyname
45+
- name: test-unit-asyncify (7/7)
46+
target: test-php-asyncify-mysqli
47+
name: ${{ matrix.name }}
11448
services:
11549
mysql:
11650
image: mysql:5.7
@@ -133,12 +67,11 @@ jobs:
13367
- uses: ./.github/actions/prepare-playground
13468
with:
13569
node-version: 20
136-
- run: node --expose-gc node_modules/nx/bin/nx affected --target=test-php-asyncify-mysqli
70+
- run: node --expose-gc node_modules/nx/bin/nx affected --target=${{ matrix.target }}
13771
env:
13872
MYSQL_DATABASE: test_db
13973
MYSQL_USER: user
14074
MYSQL_PASSWORD: password
141-
14275
# Most of these tests pass locally but the process is crashing
14376
# on the CI runner.
14477
#
@@ -308,18 +241,7 @@ jobs:
308241
github.ref == 'refs/heads/trunk' &&
309242
github.event_name == 'push'
310243
# Add a dependency to the build job
311-
needs:
312-
[
313-
test-unit-asyncify-node-1-out-of-7,
314-
test-unit-asyncify-node-2-out-of-7,
315-
test-unit-asyncify-node-3-out-of-7,
316-
test-unit-asyncify-node-4-out-of-7,
317-
test-unit-asyncify-node-5-out-of-7,
318-
test-unit-asyncify-node-6-out-of-7,
319-
test-unit-asyncify-node-7-out-of-7,
320-
test-e2e,
321-
build,
322-
]
244+
needs: [test-unit-asyncify, test-e2e, build]
323245
name: 'Deploy doc site'
324246

325247
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment

packages/php-wasm/node/src/test/php.spec.ts

Lines changed: 76 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,6 +2022,82 @@ bar1
20222022
});
20232023
});
20242024

2025+
/**
2026+
* exif support
2027+
*/
2028+
describe('exif extension support', () => {
2029+
beforeEach(async () => {
2030+
await php.writeFile(
2031+
'/image.jpg',
2032+
new Uint8Array(
2033+
readFileSync(joinPaths(__dirname, 'test-data', 'image.jpg'))
2034+
)
2035+
);
2036+
});
2037+
it('should return correct image type using exif_imagetype', async () => {
2038+
const response = await php.run({
2039+
code: `<?php echo exif_imagetype('/image.jpg');`,
2040+
});
2041+
expect(response.errors).toBe('');
2042+
expect(response.text).toBe('2');
2043+
});
2044+
it('should be able to use exif_read_data', async () => {
2045+
const response = await php.run({
2046+
code: `<?php echo json_encode(exif_read_data('/image.jpg'));`,
2047+
});
2048+
expect(response.errors).toBe('');
2049+
expect(response.json).toMatchObject({
2050+
FileName: 'image.jpg',
2051+
FileDateTime: expect.any(Number),
2052+
FileSize: 1241,
2053+
FileType: 2,
2054+
MimeType: 'image/jpeg',
2055+
SectionsFound: 'COMMENT',
2056+
COMPUTED: {
2057+
html: 'width="30" height="30"',
2058+
Height: 30,
2059+
Width: 30,
2060+
IsColor: 1,
2061+
},
2062+
COMMENT: ['Created with GIMP'],
2063+
});
2064+
});
2065+
it('should be able to use exif_tagname ', async () => {
2066+
const response = await php.run({
2067+
code: `<?php echo exif_tagname(256);`,
2068+
});
2069+
expect(response.errors).toBe('');
2070+
expect(response.text).toBe('ImageWidth');
2071+
});
2072+
it('should be able to use exif_thumbnail', async () => {
2073+
const response = await php.run({
2074+
code: `<?php
2075+
var_dump(exif_thumbnail('/image.jpg'));
2076+
`,
2077+
});
2078+
expect(response.errors).toBe('');
2079+
// TODO: we could improve this by providing an image with a valid thumbnail
2080+
expect(response.text).toBe('bool(false)\n');
2081+
});
2082+
});
2083+
2084+
/**
2085+
* intl support
2086+
*/
2087+
describe('intl extension support', () => {
2088+
it('Should be able to use intl functions', async () => {
2089+
const response = await php.run({
2090+
code: `<?php
2091+
$formatter = new NumberFormatter('en-US', NumberFormatter::CURRENCY);
2092+
echo $formatter->format(100.00);
2093+
$formatter = new NumberFormatter('fr-FR', NumberFormatter::CURRENCY);
2094+
echo $formatter->format(100.00);
2095+
?>`,
2096+
});
2097+
expect(response.text).toEqual('$100.00100,00\xA0€');
2098+
});
2099+
});
2100+
20252101
describe('onMessage', () => {
20262102
it('should pass messages to JS', async () => {
20272103
let messageReceived = '';
@@ -2107,61 +2183,6 @@ bar1
21072183
});
21082184
});
21092185

2110-
describe('exif extension support', () => {
2111-
beforeEach(async () => {
2112-
await php.writeFile(
2113-
'/image.jpg',
2114-
new Uint8Array(
2115-
readFileSync(joinPaths(__dirname, 'test-data', 'image.jpg'))
2116-
)
2117-
);
2118-
});
2119-
it('should return correct image type using exif_imagetype', async () => {
2120-
const response = await php.run({
2121-
code: `<?php echo exif_imagetype('/image.jpg');`,
2122-
});
2123-
expect(response.errors).toBe('');
2124-
expect(response.text).toBe('2');
2125-
});
2126-
it('should be able to use exif_read_data', async () => {
2127-
const response = await php.run({
2128-
code: `<?php echo json_encode(exif_read_data('/image.jpg'));`,
2129-
});
2130-
expect(response.errors).toBe('');
2131-
expect(response.json).toMatchObject({
2132-
FileName: 'image.jpg',
2133-
FileDateTime: expect.any(Number),
2134-
FileSize: 1241,
2135-
FileType: 2,
2136-
MimeType: 'image/jpeg',
2137-
SectionsFound: 'COMMENT',
2138-
COMPUTED: {
2139-
html: 'width="30" height="30"',
2140-
Height: 30,
2141-
Width: 30,
2142-
IsColor: 1,
2143-
},
2144-
COMMENT: ['Created with GIMP'],
2145-
});
2146-
});
2147-
it('should be able to use exif_tagname ', async () => {
2148-
const response = await php.run({
2149-
code: `<?php echo exif_tagname(256);`,
2150-
});
2151-
expect(response.errors).toBe('');
2152-
expect(response.text).toBe('ImageWidth');
2153-
});
2154-
it('should be able to use exif_thumbnail', async () => {
2155-
const response = await php.run({
2156-
code: `<?php
2157-
var_dump(exif_thumbnail('/image.jpg'));
2158-
`,
2159-
});
2160-
expect(response.errors).toBe('');
2161-
// TODO: we could improve this by providing an image with a valid thumbnail
2162-
expect(response.text).toBe('bool(false)\n');
2163-
});
2164-
});
21652186
describe('Disk space', () => {
21662187
it('should return the correct total disk space', async () => {
21672188
const response = await php.run({

packages/php-wasm/node/vite.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export default defineConfig(function () {
5454
},
5555
},
5656
environment: 'node',
57-
// include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
5857
reporters: ['default'],
5958
},
6059

0 commit comments

Comments
 (0)