Skip to content

test: add unit tests for Utils/ExecutionTime - #198

Merged
darwinz merged 3 commits into
TheAlgorithms:masterfrom
tahakotil:add-execution-time-test
Nov 12, 2026
Merged

darwinz merged 3 commits into
TheAlgorithms:masterfrom
tahakotil:add-execution-time-test

Conversation

@tahakotil

Copy link
Copy Markdown
Contributor

Adds a dedicated PHPUnit test class for Utils/ExecutionTime.php, which previously had no test coverage.

Verified locally:

  • phpunit tests — 287 tests, OK (285 before this change)
  • vendor/bin/phpcs -n tests/Utils/ExecutionTimeTest.php — clean

The tests assert that no output is emitted while the timer is alive and that __destruct() reports a plausible elapsed time, including that the reported interval covers the sleep duration. DIRECTORY.md is updated to list the new test file, following the existing pattern.

@tahakotil

Copy link
Copy Markdown
Contributor Author

Hi, friendly ping on this one. The CI workflows (PHP Composer, Code style) are waiting for maintainer approval since this is my first contribution here. Could someone approve the run and take a look when you have a moment? Happy to adjust anything. Thanks!

@darwinz darwinz left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for adding coverage for ExecutionTime, and for the clear description!

I merged this against current master locally. phpcs -n is clean, and the new tests passed 30 out of 30 runs. I'm requesting a few small changes before merging: remove the redundant first measurement in the second test, make sure the output buffer is always closed on failure, and drop the DIRECTORY.md edit. The details are in the inline comments.

Thanks!

Comment thread tests/Utils/ExecutionTimeTest.php Resolved
Comment thread tests/Utils/ExecutionTimeTest.php Resolved
Comment thread tests/Utils/ExecutionTimeTest.php Resolved
Comment thread DIRECTORY.md Resolved
@tahakotil

Copy link
Copy Markdown
Contributor Author

Thanks for the review, addressed in f0e47e3:

  • Removed the redundant first measurement in the second test (single measured run now).
  • The output buffer is now always closed via try/finally around ob_start/ob_end_clean.
  • Dropped the DIRECTORY.md change.
    Also made the regex tolerate scientific notation ([0-9.]+(?:E-?\d+)?) as suggested in the third inline comment.

@darwinz

darwinz commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Thanks for the quick turnaround. f0e47e3 addresses everything: the second test does a single measured run, both tests close the output buffer in a finally, the patterns accept scientific notation, and the DIRECTORY.md change is gone. CI is green, so this is good to merge.

@darwinz
darwinz merged commit 416703c into TheAlgorithms:master Nov 12, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants