Skip to content

Conversation

@walmir-silva
Copy link
Contributor

No description provided.

…e test suite quality

The previous implementation of the IntrospectionProcessor was brittle, relying on a fixed 'stackDepth' that would break tests when the call stack changed due to framework updates or other refactors.

This commit introduces a more robust and intelligent approach:
- The IntrospectionProcessor is refactored to dynamically find the true origin of a log call by identifying the boundary between application code and the logging library itself. This removes the fragile 'stackDepth' configuration.
- Key test suites, including IntrospectionProcessorTest, LoggerManagerTest, and LoggerBuilderTest, have been rewritten to a higher quality standard, using semantic method names, clear Arrange-Act-Assert blocks, and more precise assertions.
- The obsolete `toArray()` method has been removed from `LogRecord` and related formatters, promoting direct property access and a cleaner immutable pattern.
- A new, comprehensive `real_world_example.php` has been added to provide a practical demonstration of the library's features in a realistic application context, replacing the older example file.
Previously, components requiring a logger had to handle cases where one might not be provided, often leading to nullable properties (`?Logger`) and conditional checks. This increased complexity and the risk of fatal errors if a null logger was used.

This commit introduces the `SilentLogger`, a new class that implements the Null Object Pattern for the Logger interface.

- The `SilentLogger` can be used as a default or fallback logger.
- It silently discards all log messages it receives, ensuring that calls to methods like `info()` or `error()` are always safe, even when no actual logging is configured.
- This eliminates the need for `null` checks in client code (e.g., services, command executors), resulting in a cleaner and more robust design.

A corresponding PHPUnit test (`SilentLoggerTest.php`) is included to ensure the class adheres to the Logger contract and functions correctly.
@walmir-silva walmir-silva merged commit fb50fd4 into main Aug 12, 2025
1 check 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.

2 participants