Skip to content

Add test helper functions for controlling HTML ID generation#274

Merged
vjik merged 6 commits into
masterfrom
html-generate-id
May 15, 2026
Merged

Add test helper functions for controlling HTML ID generation#274
vjik merged 6 commits into
masterfrom
html-generate-id

Conversation

@vjik
Copy link
Copy Markdown
Member

@vjik vjik commented May 7, 2026

Q A
Is bugfix?
New feature? ✔️
Breaks BC?

@vjik vjik requested a review from a team May 7, 2026 18:06
@vjik vjik added the status:code review The pull request needs review. label May 7, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (3507be6) to head (6c6813a).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##              master      #274   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       828       831    +3     
===========================================
  Files             89        91    +2     
  Lines           2225      2233    +8     
===========================================
+ Hits            2225      2233    +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a deterministic testing mechanism for Html::generateId() by extracting the ID-generation logic into an internal IdGenerator and adding opt-in test helper functions to control timestamp seeding and counters. It also updates the PHPUnit bootstrap, documentation, and test suite to use the new approach instead of mocking hrtime().

Changes:

  • Add Yiisoft\Html\IdGenerator and refactor Html::generateId() to delegate to it.
  • Add src/test-functions.php with enableSeed(), disableSeed(), and reset() helpers for deterministic ID generation in tests.
  • Update PHPUnit bootstrap/config, documentation, changelog, and replace the old hrtime() mock-based test with a new dedicated test class.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/mocks/hrtime.php Removes the old hrtime() mocking approach.
tests/HtmlTest.php Drops the previous generateId test and associated mock plumbing.
tests/HtmlGenerateIdTest.php Adds new focused tests covering seeded vs deterministic ID generation and reset behavior.
tests/bootstrap.php Adds a PHPUnit bootstrap that loads Composer autoload + the new test helper functions.
src/test-functions.php Introduces test-only helper functions to manipulate IdGenerator state.
src/IdGenerator.php Adds extracted internal ID generation logic and state.
src/Html.php Refactors generateId() to use IdGenerator::generate() and updates PHPDoc.
README.md Links to the new “Testing ID generation” documentation.
phpunit.xml.dist Switches PHPUnit bootstrap to tests/bootstrap.php.
docs/testing-id-generation.md Adds documentation describing how to make ID generation deterministic in tests.
CHANGELOG.md Records the new feature entry for the upcoming release.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/test-functions.php
Comment thread tests/HtmlGenerateIdTest.php Outdated
vjik and others added 3 commits May 15, 2026 14:02
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@vjik vjik merged commit d7ff5ea into master May 15, 2026
22 checks passed
@vjik vjik deleted the html-generate-id branch May 15, 2026 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:code review The pull request needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants