Make WordPress Core

Opened 4 weeks ago

Last modified 4 days ago

#66074 accepted task (blessed)

Tests: Reduce the cost of the heaviest PHPUnit test classes

Reported by: lancewillett Owned by: lancewillett
Priority: normal Milestone: 7.2
Component: Build/Test Tools Version:
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses: tests, performance

Description

#65887 gave the suite its first published timing data and closed. This ticket is where the follow-up work lives: the classes that cost the most, claimed one at a time.

What we can measure now

The first two trunk data points on August 31 were 443 s and 330 s for consecutive commits that touched no test, so single points are noise on shared runners. Only a sustained shift means anything. The same two runs counted 32 and 20 tests over one second.

Where the time is

One local run of trunk at 6c0f205fd6 on August 16 (PHP 8.3, MySQL 9.7, Docker, single site) gives the shape. Directional, not authoritative:

  • 30,865 tests in 1,066 classes, 234 s of summed per-test time.
  • Half of that time is in 22 classes. A quarter is in 7.
  • 61 REST API classes account for 49% of it.

The heaviest classes by summed time, in seconds:

sec tests avg class
16.3 197 0.083 WP_Test_REST_Attachments_Controller
11.8 281 0.042 WP_Test_REST_Posts_Controller
7.0 151 0.046 WP_Test_REST_Post_Meta_Fields
6.9 200 0.034 WP_Test_REST_Comments_Controller
6.9 259 0.027 Tests_REST_API
6.5 359 0.018 Tests_Media
6.4 452 0.014 Tests_Blocks_registerCoreBlockStyleHandles
5.2 129 0.041 WP_Test_REST_Users_Controller
4.9 113 0.043 Tests_Image_Functions
4.6 11 0.421 Tests_Admin_ExportWp
4.5 93 0.049 Tests_Theme
4.4 4,474 0.001 Tests_WpTokenMap
4.3 95 0.045 WP_Test_REST_Themes_Controller
4.3 848 0.005 Tests_Canonical_PostStatus
3.8 100 0.038 Tests_REST_WpRestUrlDetailsController
3.8 129 0.030 Tests_REST_Server
3.4 29 0.117 Tests_Image_Editor_Imagick
3.2 95 0.033 WP_REST_Global_Styles_Controller_Test
2.7 70 0.039 WP_Test_REST_Tags_Controller
2.6 49 0.054 Tests_REST_WpRestTemplatesController

Two profiles appear, and they need different fixes. Tests_WpTokenMap and Tests_Canonical_PostStatus are data-provider matrices of cheap tests, so the lever is the size of the matrix. Tests_Admin_ExportWp and Tests_Image_Editor_Imagick are a few expensive tests, so the lever is fixture and I/O cost inside each one.

How to work a class

  1. Claim it in a comment here, one class at a time.
  2. Measure before: npm run test:php -- --filter Class_Name, then read the time attributes in tests/phpunit/build/logs/junit.xml.
  3. Apply the levers the handbook already documents: hoist immutable fixtures into wpSetUpBeforeClass(), share expensive objects across the class, trim provider matrices that exercise identical code paths, and mock file or image work where the assertion does not need the real thing.
  4. Measure after, the same way, and post both numbers on this ticket with the PR.

Guardrails: no assertion is removed to save time, no expected value changes to make a test pass, no timeouts are raised, and a test that protects a specific behavior stays even if it is slow.

Related: #42904, #42278 and #41451 (older performance proposals that can now be evaluated against data), #63026 (the bcrypt precedent), #52645, #65887.

Change History (47)

#1 @sainathpoojary
4 weeks ago

Thanks for setting up this tracking ticket @lancewillett! I'll claim Tests_Blocks_registerCoreBlockStyleHandles. I'll work on reducing the repeated style registrations while keeping all assertions intact, and will share the before/after metrics here with the PR.

This ticket was mentioned in ​PR #13457 on ​WordPress/wordpress-develop by ​@sainathpoojary.


4 weeks ago
#2

  • Keywords has-patch has-unit-tests added; needs-patch removed

Updates Tests_Blocks_registerCoreBlockStyleHandles to avoid repeating the same setup for each block.

Previously, four test methods each ran separately for 113 blocks, giving 452 test cases. Each case called register_core_block_style_handles(), which registers styles for all blocks when separate block assets are enabled, but checked only one block.

Each method now calls the function once and loops through all blocks to check the results. This reduces the test cases from 452 to 4 while preserving all 1,873 assertions and their expected values. Failure messages include the block name to help identify problems.

### Performance
Tested locally across three consecutive runs on trunk versus the fix branch:

Run Trunk Test Time (junit.xml) Trunk Wall Time Fix Test Time (junit.xml) Fix Wall Time
Run 1 4.474s 4.798s 0.062s 0.342s
Run 2 4.062s 4.377s 0.057s 0.295s
Run 3 3.709s 4.029s 0.094s 0.352s
Average 4.082s 4.401s 0.071s 0.330s

Trac ticket: https://core.trac.wordpress.org/ticket/66074

## Use of AI Tools

AI assistance: Yes
Tool(s): Github Copilot
Model(s): Claude Sonnet 4.6
Used for: Edge-case checks, and assistance with the PR description, implementation and testing were reviewed and verified by me.

#3 @lancewillett
4 weeks ago

In 63563:

Tests: Reduce repeated core block style registration.

Register core block styles once per scenario, then check all block handles. Replace per-block data-provider cases with loops, retaining the assertions and adding block names to failure messages.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13457

Props sainathpoojary.
See #66074.

#5 @sainathpoojary
4 weeks ago

Thanks for the review and merge @lancewillett !

I’d take on Tests_WpTokenMap for my next PR. I'll focus on trimming the repeated setup while ensuring all assertions remain intact.

This ticket was mentioned in ​PR #13478 on ​WordPress/wordpress-develop by ​@sainathpoojary.


4 weeks ago
#6

Updates Tests_WpTokenMap to avoid repeated test runner overhead for each HTML5 named character reference.

Previously, test_reads_token_at_given_offset and test_detects_all_tokens each used a 2,231-item data provider (data_html5_test_dataset), creating 4,462 individual test invocations. Each invocation incurred PHPUnit test runner lifecycle overhead (setup, teardown, and event handling) for in-memory token map checks.

Both methods now retrieve the dataset via a private helper method and assert all tokens within internal loops. This reduces the test case count from 4,474 to 14 while preserving all 24,587 assertions. Failure messages have also been updated to include the token name to maintain precise diagnostics if a regression occurs.

### Performance

Performance measured locally across three consecutive runs comparing trunk to this branch:

Run Trunk Test Time Trunk Wall Time Fix Test Time Fix Wall Time
:--- :--- :--- :--- :---
Run 1 4.892s 5.277s 0.192s 0.218s
Run 2 5.628s 6.121s 0.192s 0.214s
Run 3 4.452s 4.790s 0.195s 0.232s
Average 4.991s 5.396s 0.193s 0.221s
  • Pure Test Time: ~96.1% reduction (from ~4.99s to ~0.19s).
  • PHPUnit Wall Time: ~95.9% reduction (from ~5.40s to ~0.22s).

Trac ticket: https://core.trac.wordpress.org/ticket/66074

## Use of AI Tools

AI assistance: Yes
Tool(s): Github Copilot
Used for: Edge-case checks, and assistance with the PR description, implementation and testing were reviewed and verified by me.

#7 @lancewillett
4 weeks ago

In 63591:

Tests: Reduce repeated token map test setup.

Check all HTML5 named character references within each token map test instead of running a separate test for every token. Preserve the per-token assertions and include token names in failure messages.

Reduce test invocations from 4,474 to 14, avoiding repeated test runner setup and teardown.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13478

Props sainathpoojary.
See #66074.

#9 @sainathpoojary
3 weeks ago

I'd like to claim Tests_Admin_ExportWp next.

I'll optimize wpSetUpBeforeClass() by mocking image uploads/thumbnail generation, as the export assertions only require attachment database records.

I'll open a PR with before/after measurements shortly.

This ticket was mentioned in ​PR #13495 on ​WordPress/wordpress-develop by ​@sainathpoojary.


3 weeks ago
#10

Optimizes fixture setup in Tests_Admin_ExportWp by avoiding physical image uploads and thumbnail generation during sample data preparation.

As noted in the ticket description for #66074, Tests_Admin_ExportWp is driven by fixture and I/O cost. Previously, wpSetUpBeforeClass() called create_upload_object(), which physically copied four JPEGs to the uploads folder and generated intermediate image sizes for each of the 11 tests running in separate PHP processes.

export_wp() tests only assert that post and attachment database records appear correctly in the exported XML, they do not inspect physical files or image dimensions. Replacing create_upload_object() with $factory->attachment->create() creates the necessary database records and thumbnail relationships directly, eliminating disk writes and GD/Imagick sub-size generation.

### Performance

Local measurements across three runs (each running 11 tests across separate processes):

Run Trunk Test Time Trunk Wall Time Fix Test Time Fix Wall Time
:--- :--- :--- :--- :---
Run 1 10.63s 34.17s 7.96s 27.24s
Run 2 8.01s 26.46s 8.36s 26.65s
Run 3 9.01s 29.13s 8.53s 29.20s
Average 9.22s 29.92s 8.28s 27.70s
  • Average JUnit runtime: ~10.1% reduction (from 9.22s to 8.28s).
  • Average PHPUnit runtime: ~7.4% reduction (from 29.92s to 27.70s).
  • Setup time per process: Dropped from ~0.72s to ~0.60s.

While the local time gain is modest and subject to process variance, eliminating disk I/O and thumbnail generation removes unnecessary filesystem churn across all separate test processes.

### Validation

  • All 11 tests and 35 assertions pass on both single-site and multisite.
  • Verified attachment parent relationships and featured image IDs (set_post_thumbnail) are intact.
  • PHPCS passes with 0 errors and 0 warnings.

Trac ticket: https://core.trac.wordpress.org/ticket/66074

## Use of AI Tools

AI assistance: Yes
Tool(s): Github Copilot
Used for: Edge-case checks, and assistance with the PR description. Implementation and testing were made and reviewed by me.

#11 @lancewillett
3 weeks ago

  • Owner set to lancewillett
  • Status new → accepted

​@sainathpoojary commented on ​PR #13495:


3 weeks ago
#12

Thanks for the feedback @lancewillett .

I investigated and found that Tests_Admin_IncludesMedia was not cleaning up its uploads, and scan_user_uploads() was rescanning when the directory started empty because an empty array evaluated as falsy.

This update:

  • Adds cleanup to Tests_Admin_IncludesMedia::tear_down().
  • Preserves empty initial snapshots in WP_UnitTestCase_Base.
  • Adds regression coverage in uploadSnapshot.php.

The suite passes cleanly locally. Could you please recheck when you have time?

#13 @lancewillett
3 weeks ago

In 63631:

Tests: Reduce export fixture cost and fix upload cleanup.

Create export attachment fixtures directly in the database instead of copying images and generating intermediate sizes. Preserve the attachment parent and featured-image relationships.

Cache an initially empty upload snapshot and clean up files created by the admin media tests, preventing leftover uploads from changing later filenames. Add regression coverage for empty and nonempty initial snapshots.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13495

Props sainathpoojary.
See #66074.

#15 @sainathpoojary
3 weeks ago

I'd like to take on WP_Test_REST_Post_Meta_Fields next. I'll optimize it by reusing the editor fixture to avoid repeated user creation, and will open a PR shortly.

This ticket was mentioned in ​PR #13589 on ​WordPress/wordpress-develop by ​@sainathpoojary.


3 weeks ago
#16

Optimizes fixture setup in WP_Test_REST_Post_Meta_Fields by avoiding repeated editor user creation across individual tests.

Previously, grant_write_permission() called $factory->user->create() each time it was invoked (65+ calls across test methods and data provider iterations). This introduced unnecessary database insertions and teardown overhead for tests that only needed an authenticated editor user.

This change creates a shared editor user once in wpSetUpBeforeClass(), sets that user in grant_write_permission(), and cleans it up via self::delete_user() in wpTearDownAfterClass(). All 151 tests and 581 assertions remain unchanged and pass.

Performance

Measured locally across three consecutive runs comparing trunk to this branch:

Run Trunk Test Time (junit.xml) Trunk Wall Time Fix Test Time (junit.xml) Fix Wall Time
:--- :--- :--- :--- :---
Run 1 2.386s 2.695s 1.829s 2.287s
Run 2 2.295s 2.612s 1.802s 2.219s
Run 3 2.242s 2.548s 1.850s 2.325s
Average 2.308s 2.618s 1.827s 2.277s

Trac ticket: https://core.trac.wordpress.org/ticket/66074

Use of AI Tools

AI assistance: Yes
Tool(s): Github Copilot
Used for: Edge-case checks and assistance with the PR description, implementation and testing were done and reviewed by me.

​@sainathpoojary commented on ​PR #13589:


2 weeks ago
#17

I noticed a few of the CI test jobs are failing, so I spent some time investigating. I ran the tests locally, but they are passing for me without any issues.

I also checked trunk and a few other open PRs, and it looks like these similar failures are happening there as well. Since this is happening other places as well, it seems like these might be random test failures rather than something caused by these changes.

This ticket was mentioned in ​PR #13619 on ​WordPress/wordpress-develop by ​@sainathpoojary.


2 weeks ago
#18

Optimizes fixture setup in WP_Test_REST_Attachments_Controller by avoiding unnecessary image processing in tests that do not check generated image sizes.

Three permission tests previously uploaded JPEG files and generated intermediate image sizes before asserting that the REST request was rejected. The permission callback returns the expected error before image editing begins, so these tests now create attachment records directly with the required MIME type, status, and file path.

The EXIF orientation test still uploads and edits a real image, but it only checks the full-size image dimensions after rotation. It now skips intermediate image size generation while preserving the real upload, EXIF correction, rotation, and all assertions.

All 200 tests and 1,159 assertions remain unchanged and pass.

Performance

Measured locally across three consecutive runs comparing trunk to this branch:

Run Trunk Test Time (junit.xml) Trunk Wall Time Fix Test Time (junit.xml) Fix Wall Time
:--- :--- :--- :--- :---
Run 1 8.337s 9.176s 6.950s 7.777s
Run 2 8.178s 9.020s 6.904s 7.739s
Run 3 8.466s 9.314s 7.166s 7.984s
Average 8.327s 9.170s 7.007s 7.833s

Trac ticket: https://core.trac.wordpress.org/ticket/66074

Use of AI Tools

AI assistance: Yes
Tool(s): Github Copilot
Used for: Edge-case checks and assistance with the PR description, implementation and testing were done and reviewed by me.

#19 @sainathpoojary
2 weeks ago

@lancewillett I also took a look at WP_Test_REST_Term_Meta_Fields. It's not on the main list, but it has the same setup overhead as the WP_Test_REST_Post_Meta_Fields class. Fixing it drops the local runtime from 0.843s to 0.769s (all 52 tests / 267 assertions intact). Would this smaller optimization be useful for this ticket, or should work remain limited to the listed classes?

#20 @lancewillett
2 weeks ago

@sainathpoojary Yes, useful here. Thanks!

#21 @lancewillett
2 weeks ago

In 63776:

Tests: Reuse the editor in REST post meta tests.

Create the editor once per class instead of recreating it for each write-permission check. Delete the shared user during class teardown.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13589

Props sainathpoojary.
See #66074.

#22 @lancewillett
2 weeks ago

In 63777:

Tests: Reduce image work in REST attachment tests.

Use attachment records without uploading images in three permission tests, and remove their unnecessary imagejpeg requirement. Skip intermediate image sizes in the EXIF orientation test while preserving the full-size image checks.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13619

Props sainathpoojary.
See #66074.

This ticket was mentioned in ​PR #13636 on ​WordPress/wordpress-develop by ​@sainathpoojary.


2 weeks ago
#25

Optimizes fixture setup in WP_Test_REST_Term_Meta_Fields by avoiding repeated editor user creation across individual tests.

Previously, grant_write_permission() created a new editor user each time it was called. This introduced unnecessary database work for tests that only needed an authenticated editor user.

This change creates one shared editor user in wpSetUpBeforeClass(), uses it in grant_write_permission(), and removes it with self::delete_user() in wpTearDownAfterClass(). All 52 tests and 267 assertions remain unchanged and pass.

Performance

Measured locally across three consecutive runs comparing trunk to this branch:

Run Trunk Test Time (junit.xml) Trunk Wall Time Fix Test Time (junit.xml) Fix Wall Time
:--- :--- :--- :--- :---
Run 1 0.597s 0.864s 0.400s 0.788s
Run 2 0.554s 0.811s 0.387s 0.766s
Run 3 0.596s 0.853s 0.379s 0.754s
Average 0.582s 0.843s 0.389s 0.769s

Trac ticket: https://core.trac.wordpress.org/ticket/66074

Use of AI Tools

AI assistance: Yes
Tool(s): Github Copilot
Used for: Edge-case checks and assistance with the PR description, implementation and testing were done and reviewed by me.

#26 @lancewillett
2 weeks ago

In 63781:

Tests: Reuse the editor fixture in REST term meta tests.

Create one editor user for the REST term meta test class and reuse it when granting write permission. Delete the shared user during class teardown, avoiding repeated user creation while preserving the existing assertions.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13636

Props sainathpoojary.
See #66074.

This ticket was mentioned in ​PR #13694 on ​WordPress/wordpress-develop by ​@sainathpoojary.


12 days ago
#28

Reduces unnecessary REST server setup in Tests_REST_API.

Previously, every test created a Spy_REST_Server and initialized all REST routes, including helper tests that did not need them.

This change initializes the server only where needed using rest_get_server(). The test bootstrap continues to select Spy_REST_Server. Setup and teardown clear the server to preserve test isolation.

Performance

Measured locally across three runs:

Run Trunk Test Time Trunk Wall Time Fix Test Time Fix Wall Time
:--- :--- :--- :--- :---
Run 1 1.593s 1.884s 0.558s 0.852s
Run 2 1.756s 2.049s 0.535s 0.823s
Run 3 1.578s 1.877s 0.551s 0.850s
Average 1.642s 1.937s 0.548s 0.842s

Trac ticket: https://core.trac.wordpress.org/ticket/66074

Use of AI Tools

AI assistance: Yes
Tool(s): Github Copilot
Used for: Edge-case checks, and assistance with the PR description. Implementation and testing were made and reviewed by me.

This ticket was mentioned in ​PR #13818 on ​WordPress/wordpress-develop by ​@shailu25.


6 days ago
#29

Trac ticket: #66074

What

Optimizes Tests_Canonical_PostStatus by asserting all plain- and pretty-permalink matrix cases inside two tests instead of one PHPUnit invocation per row.

Previously, @dataProvider created hundreds of individual test cases. Each case paid PHPUnit setup/teardown cost for the same shared fixtures and permalink structure.

Why

Part of #66074. This class is on the heavy list as a data-provider matrix of cheap tests: the lever is reducing matrix invocations, not removing coverage.

Same approach as the landed Tests_WpTokenMap work: keep every assertion, cut repeated runner overhead.

How

  • test_canonical_redirects_to_plain_permalinks and test_canonical_redirects_to_pretty_permalinks loop over private case helpers
  • Dataset builders keep the same cases and expected URLs
  • Permalink structure is set once per method (identical for every case in that method)
  • Each case still resets attachment-pages option, current user, and post cache
  • Failure messages include post_key, user_role, and URLs for diagnosis
  • No assertions removed; no expected values changed

Testing instructions

  1. Start the local WordPress develop environment.
  2. Run:
npm run test:php -- --filter Tests_Canonical_PostStatus

Use of AI tools

Cursor

​@lancewillett commented on ​PR #13818:


6 days ago
#30

Optional, non-blocking improvement: could both exception handlers preserve PHPUnit’s comparison details when adding the case context?

A deliberate URL mismatch confirmed that catching ExpectationFailedException and calling $this->fail() loses the actual URL and PHPUnit’s expected/actual diff. The output includes the case identifiers and expected URL, followed by “Failed asserting that two strings are identical,” but not the actual result.

Keeping the original exception’s getComparisonFailure() when rethrowing would retain the useful diff alongside the new context.

Code: ​https://github.com/WordPress/wordpress-develop/blob/7f8774ed8c7dee0a5d08738afc622a5b34e4939b/tests/phpunit/tests/canonical/postStatus.php#L246

---
<sub>Adversarial review · <code>gpt-6</code></sub>

#31 @sainathpoojary
6 days ago

I'd like to claim Tests_REST_Server next. I'll look into optimizing the test setups to reduce its runtime while keeping all assertions intact. I'll open a PR shortly.

This ticket was mentioned in ​PR #13823 on ​WordPress/wordpress-develop by ​@sainathpoojary.


6 days ago
#32

Optimizes fixture setup in Tests_REST_Server by avoiding an unnecessary image upload and thumbnail generation.

Previously, wpSetUpBeforeClass() uploaded test-image-large.jpg and generated intermediate image sizes. The test using this attachment only checks the site icon ID and URL returned by the REST API. It does not inspect image dimensions or physical files.

This change creates the attachment record directly with a JPEG MIME type and file path. The site icon URL still resolves through the normal WordPress attachment APIs, and the existing teardown removes the attachment record. All 129 tests and 407 assertions remain unchanged.

Performance

Measured locally across three consecutive runs comparing trunk to this branch:

Run Trunk PHPUnit Time Fix PHPUnit Time
:--- :--- :---
Run 1 2.593s 1.153s
Run 2 2.534s 1.297s
Run 3 2.512s 1.266s
Average 2.546s 1.239s

Average PHPUnit runtime decreased by approximately 51.4%. The improvement comes from removing image upload and resizing work during class setup, which is not included in JUnit’s individual test timings.

Trac ticket: https://core.trac.wordpress.org/ticket/66074

Use of AI Tools

AI assistance: Yes
Tool(s): Github Copilot
Used for: PR description

​@lancewillett commented on ​PR #13823:


6 days ago
#33

Separate, non-blocking follow-up: randomized runs exposed an existing test-isolation issue in this class, reproduced on both the unchanged baseline and this patch.

Seeds 13823 and 13824 fail test_nocache_headers_on_authenticated_requests() with “Header Expires is not present in the response”; seed 13825 passes. The nonce-test helper sets $wp_rest_auth_cookie = true without restoring it. A later authenticated request without a nonce is then treated as unauthenticated.

A diagnostic reset of that global before each test made seed 13823 pass on both versions, in single-site and multisite. Could we address restoration of this global in a separate PR? This fixture optimization does not introduce the failure.

Reproduce with:

npm run test:php -- --filter Tests_REST_Server --order-by=random --random-order-seed=13823

Code: ​https://github.com/WordPress/wordpress-develop/blob/21c80fd0d53a384afbeec613b7ee8a3486f431b2/tests/phpunit/tests/rest-api/rest-server.php#L1819

---
<sub>Adversarial review · <code>gpt-6</code></sub>

#34 @lancewillett
6 days ago

In 64005:

Tests: Avoid unnecessary image upload in REST server tests.

Create the site icon attachment record directly instead of uploading an image and generating thumbnails. The REST index test checks the attachment ID and URL, so physical image files and dimensions are unnecessary.

Preserve URL resolution through the WordPress attachment APIs and all existing assertions while reducing fixture setup time.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13823

Props sainathpoojary.
See #66074.

#36 @lancewillett
6 days ago

In 64006:

Tests: Initialize the REST API test server only when needed.

Avoid initializing the REST server for tests that do not use it. Initialize it explicitly in route tests and reset the global server between tests. Remove redundant server restoration from preload tests.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13694

Props sainathpoojary, mindctrl.
See #66074.

#38 @lancewillett
6 days ago

r64007 -- I forgot the Trac reference. 😄

Tests: Reduce setup overhead in canonical post status tests.

Loop through the plain and pretty permalink cases within their respective test methods instead of repeating test setup for each data set. Preserve all 848 assertions and reset request state between cases.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13818

Props shailu25.

Last edited 6 days ago by lancewillett (previous) (diff)

#40 @sainathpoojary
4 days ago

I'd like to claim Tests_Media next. I'll optimize it by reusing the existing image fixture to avoid repeated uploads, and will open a PR shortly.

This ticket was mentioned in ​PR #13905 on ​WordPress/wordpress-develop by ​@sainathpoojary.


4 days ago
#41

Updates Tests_Media to reuse its existing image attachment in the attachment filesize fallback test.

Previously, each of the nine data provider cases uploaded canola.jpg and generated image sizes. The test only needs a readable attachment file to confirm that wp_prepare_attachment_for_js() falls back to the file size when attachment metadata contains an invalid filesize value.

This change reuses the class fixture, which is already a real uploaded image. All nine cases and 63 assertions remain unchanged.

Performance

Measured locally across three runs for the affected nine test cases:

Run Trunk Test Time Fix Test Time
:--- :--- :---
Run 1 0.385s 0.056s
Run 2 0.384s 0.045s
Run 3 0.390s 0.040s
Average 0.386s 0.047s

Trac ticket: https://core.trac.wordpress.org/ticket/66074

Use of AI Tools

AI assistance: Yes
Tool(s): Github Copilot
Used for: PR description

#42 @lancewillett
4 days ago

In 64033:

Tests: Reuse the media fixture for attachment filesize tests.

Reuse the existing uploaded image in the attachment filesize fallback test instead of uploading an image and generating image sizes for each data set. Preserve all nine cases and 63 assertions against a real attachment file.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13905

Props sainathpoojary.
See #66074.

#44 @sainathpoojary
4 days ago

I'd like to claim Tests_Image_Functions next. Will optimize it by using a database fixture instead of real file uploads, and will open a PR shortly.

This ticket was mentioned in ​PR #13909 on ​WordPress/wordpress-develop by ​@sainathpoojary.


4 days ago
#45

Three wp_image_editor() filter tests were uploading an image file and creating real thumbnail files on disk.

These tests only check if the image_edit_thumbnails_separately filter runs and if the imgedit-applyto markup is printed. They do not process image pixels.

This PR replaces the file upload and thumbnail generation with a fixture using self::factory()->attachment->create() and static metadata. A thumbnail entry is kept in the metadata so the editor markup still renders properly.

Performance

Measured locally across three consecutive runs comparing trunk against this branch:

Full Class (Tests_Image_Functions, 113 tests)

Run Trunk Test Time Fix Test Time
--- ---: ---:
1 5.993s 6.017s
2 6.067s 5.846s
3 6.374s 5.841s
Average 6.145s 5.901s

Affected Filter Tests (3 tests)

Run Trunk Test Time Fix Test Time

| --- | ---: | ---: |
| 1 | 0.133s | 0.019s |
| 2 | 0.131s | 0.019s |

3 0.134s 0.018s

| Average | 0.133s | 0.019s |

Trac ticket: https://core.trac.wordpress.org/ticket/66074

AI assistance: Yes
Tool(s): Github Copilot
Used for: Edge-case checks and drafting the PR description, implementation and testing were reviewed and verified by me.

#46 @lancewillett
4 days ago

In 64036:

Tests: Use static metadata for image editor filter tests.

Create attachment records with static image metadata instead of uploading images and generating thumbnails for the image_edit_thumbnails_separately filter tests. Preserve the filter invocation and conditional markup checks, including the thumbnail metadata needed to render the controls.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13909

Props sainathpoojary.
See #66074.

Note: See TracTickets for help on using tickets.