Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
feat(tests): Add TestSupport trait and corresponding test suite for inaccessible properties and methods.#12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
fd04b2b7b4b129aeb0902d90df75a4d9d4ea1c96d1490efb8379389606dcb1dc702bf8741bab0File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -20,46 +20,20 @@ | ||
| use function unlink; | ||
| /** | ||
| * Assertion utility class for advanced test introspection and manipulation. | ||
| * Trait providing utilities for testing inaccessible properties, methods, and filesystem cleanup. | ||
| * | ||
| * Provides static helper methods for accessing and modifying inaccessible properties and methods invoking parent class | ||
| * logic, and performing file system cleanup in test environments. | ||
| * Supplies static helper methods for normalizing line endings, accessing or modifying private/protected properties and | ||
| * methods (including those inherited from parent classes), invoking inaccessible methods, and recursively removing | ||
| * files from directories. | ||
| * | ||
| * Extends {@see \PHPUnit\Framework\Assert} to offer additional capabilities for testing private/protected members and | ||
| * for managing test artifacts, supporting robust and isolated unit tests. | ||
| * These utilities are designed to facilitate comprehensive unit testing by enabling assertions and manipulations that | ||
| * would otherwise be restricted by visibility constraints or platform differences. | ||
| * | ||
| * Key features. | ||
| * - Access and modify inaccessible (private/protected) properties and methods via reflection. | ||
| * - Invoke parent class methods and properties for testing inheritance scenarios. | ||
| * - Normalize line endings for cross-platform string assertions. | ||
| * - Remove files and directories recursively for test environment cleanup. | ||
| * | ||
| * @copyright Copyright (C) 2025 PHPForge. | ||
| * @copyright Copyright (C) 2025 Terabytesoftw. | ||
| * @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License. | ||
| */ | ||
| final class Assert extends \PHPUnit\Framework\Assert | ||
| trait TestSupport | ||
terabytesoftw marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| { | ||
| /** | ||
| * Asserts that two strings are equal after normalizing line endings to unix style ('\n'). | ||
| * | ||
| * Replaces all windows style ('\r\n') line endings with unix style ('\n') in both the expected and actual strings | ||
| * before performing the equality assertion. | ||
| * | ||
| * This ensures cross-platform consistency in string comparisons where line ending differences may otherwise cause | ||
| * `false` negatives. | ||
| * | ||
| * @param string $expected Expected string value, with any line endings. | ||
| * @param string $actual Actual string value, with any line endings. | ||
| * @param string $message Optional failure message to display if the assertion fails. Default is an empty string. | ||
| */ | ||
| public static function equalsWithoutLE(string $expected, string $actual, string $message = ''): void | ||
| { | ||
| $expected = str_replace("\r\n", "\n", $expected); | ||
| $actual = str_replace("\r\n", "\n", $actual); | ||
| self::assertEquals($expected, $actual, $message); | ||
| } | ||
| /** | ||
| * Retrieves the value of an inaccessible property from a parent class instance. | ||
| * | ||
| @@ -185,6 +159,23 @@ public static function invokeParentMethod( | ||
| return $result ?? null; | ||
| } | ||
| /** | ||
| * Normalizes line endings to Unix style ('\n') for cross-platform string assertions. | ||
| * | ||
| * Converts Windows style ('\r\n') line endings to Unix style ('\n') to ensure consistent string comparisons across | ||
| * different operating systems during testing. | ||
| * | ||
| * This method is useful for eliminating false negatives in assertions caused by platform-specific line endings. | ||
| * | ||
| * @param string $line Input string potentially containing Windows style line endings. | ||
| * | ||
| * @return string String with normalized Unix style line endings. | ||
| */ | ||
| public static function normalizeLineEndings(string $line): string | ||
| { | ||
| return str_replace(["\r\n", "\r"], "\n", $line); | ||
| } | ||
| /** | ||
| * Removes all files and directories recursively from the specified base path, excluding '.gitignore' and | ||
| * '.gitkeep'. | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.