Repository navigation
test(framework): fix StdoutLogger tests to handle timestamp prefix - #7621
Conversation
Updated StdoutLoggerTest to properly handle the new timestamp format introduced in StdoutLogger. The logger now outputs timestamps in the format [YYYY-MM-DD HH:MM:SS-mmm] before each log message. Changes: - Updated test assertions to strip timestamp prefix before comparison - Fixed expected output format spacing (single to double space) - All tests now pass with the new timestamp feature Fixes test failures in StdoutLoggerTest::testLog, testFixedErrorContextCount, and testLogComplexityContext
Fixed StdoutLogger to properly handle spacing when tags are present or absent. Updated tests to strip timestamp prefix before comparison. Changes to StdoutLogger.php: - Improved tag spacing logic to avoid double spaces when no tags present - Tags string now conditionally adds leading space only when tags exist - Format: [timestamp] <level>[LEVEL]</> message (no tags) - Format: [timestamp] <level>[LEVEL]</> [tag] message (with tags) Changes to StdoutLoggerTest.php: - Added timestamp stripping in test assertions using regex - Tests now properly handle dynamic timestamps in log output - All 4 tests pass successfully Fixes spacing issues in log output formatting.
|
@huangdijia 大佬 .v 是不是更好
|
调整了 |
There was a problem hiding this comment.
Pull request overview
This PR fixes the StdoutLoggerTest to properly handle the new timestamp prefix feature that was added to StdoutLogger. The logger now prepends timestamps in the format [YYYY-MM-DD HH:MM:SS.mmm] to all log messages, and the tests needed to be updated to strip this prefix before comparing expected vs actual output.
Key changes:
- Updated test helper method to strip timestamp prefix using regex before assertions
- Added timestamp formatting to the logger's message output
- Updated CHANGELOG to document the new timestamp feature
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/framework/tests/StdoutLoggerTest.php | Modified getLogger() method to strip timestamp prefix from messages before assertion comparison |
| src/framework/src/Logger/StdoutLogger.php | Added timestamp prefix to log message format and refactored message formatting logic |
| CHANGELOG-3.2.md | Documented the addition of timestamp prefix feature to StdoutLogger |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $output = Mockery::mock(ConsoleOutput::class); | ||
| $output->shouldReceive('writeln')->with(Mockery::any())->once()->andReturnUsing(function ($message) use ($expected) { | ||
| $this->assertSame($expected, $message); | ||
| // Strip the timestamp prefix [YYYY-MM-DD HH:MM:SS-mmm] before comparing |
There was a problem hiding this comment.
The comment says the format is [YYYY-MM-DD HH:MM:SS-mmm] but the actual format uses a dot (.) before milliseconds, not a hyphen (-). The comment should be updated to match the actual format: [YYYY-MM-DD HH:MM:SS.mmm].
| // Strip the timestamp prefix [YYYY-MM-DD HH:MM:SS-mmm] before comparing | |
| // Strip the timestamp prefix [YYYY-MM-DD HH:MM:SS.mmm] before comparing |

Summary
Fixed StdoutLoggerTest to properly handle the new timestamp format that was recently added to StdoutLogger. The logger now outputs timestamps in the format
[YYYY-MM-DD HH:MM:SS.mmm]before each log message, but the tests were not updated to account for this change.Changes
getLogger()method to strip timestamp prefix before comparing expected vs actual output</>to double space</>)Test Results
Test Plan
composer test -- src/framework/tests/StdoutLoggerTest.php