44
55namespace PHPForge \Support \Tests ;
66
7- use PHPForge \Support \Assert ;
87use PHPForge \Support \Tests \Stub \{TestBaseClass , TestClass };
8+ use PHPForge \Support \TestSupport ;
99use PHPUnit \Framework \TestCase ;
1010use ReflectionException ;
1111use RuntimeException ;
1212
1313/**
14- * Test suite for {@see Assert} utility methods and reflection helpers .
14+ * Test suite for {@see TestSupport} trait utility methods.
1515 *
16- * Verifies the behavior of assertion and reflection-based utility methods for testing inaccessible properties, parent
17- * properties, and methods, as well as file system operations for test directories.
16+ * Verifies the behavior of utility methods provided by the {@see TestSupport} trait for testing inaccessible
17+ * properties, parent properties, and methods, as well as file system operations for test directories.
1818 *
1919 * These tests ensure correct access and mutation of private/protected members, invocation of inaccessible methods, and
2020 * robust file removal logic, including error handling for non-existent directories.
2121 *
22- * Test coverage.
22+ * Test coverage:
2323 * - Accessing and asserting values of inaccessible properties and parent properties.
2424 * - Ensuring correct exception handling for invalid operations.
2525 * - Invoking inaccessible methods and parent methods.
26+ * - Normalizing line endings.
2627 * - Removing files from directories and handling missing directories.
2728 * - Setting values for inaccessible properties and parent properties.
2829 *
2930 * @copyright Copyright (C) 2025 Terabytesoftw.
3031 * @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
3132 */
32- final class AssertTest extends TestCase
33+ final class TestSupportTest extends TestCase
3334{
34- public function testEqualsWithoutLEReturnsTrueWhenStringsAreIdenticalWithLineEndings (): void
35- {
36- Assert::equalsWithoutLE (
37- "foo \r\nbar " ,
38- "foo \r\nbar " ,
39- "Should return 'true' when both strings are identical including line endings. " ,
40- );
41- }
35+ use TestSupport;
4236
4337 /**
4438 * @throws ReflectionException
@@ -47,7 +41,7 @@ public function testInaccessibleParentPropertyReturnsExpectedValue(): void
4741 {
4842 self ::assertSame (
4943 'valueParent ' ,
50- Assert ::inaccessibleParentProperty (
44+ self ::inaccessibleParentProperty (
5145 new TestClass (),
5246 TestBaseClass::class,
5347 'propertyParent ' ,
@@ -56,6 +50,15 @@ public function testInaccessibleParentPropertyReturnsExpectedValue(): void
5650 );
5751 }
5852
53+ public function testNormalizeLineEndingsWhenStringsAreIdenticalWithLineEndings (): void
54+ {
55+ self ::assertSame (
56+ self ::normalizeLineEndings ("foo \r\nbar " ),
57+ self ::normalizeLineEndings ("foo \r\nbar " ),
58+ "Should return 'true' when both strings are identical including line endings. " ,
59+ );
60+ }
61+
5962 public function testRemoveFilesFromDirectoryRemovesAllFiles (): void
6063 {
6164 $ dir = dirname (__DIR__ ) . '/runtime ' ;
@@ -64,7 +67,7 @@ public function testRemoveFilesFromDirectoryRemovesAllFiles(): void
6467 touch ("{$ dir }/test.txt " );
6568 touch ("{$ dir }/subdir/test.txt " );
6669
67- Assert ::removeFilesFromDirectory ($ dir );
70+ self ::removeFilesFromDirectory ($ dir );
6871
6972 $ this ->assertFileDoesNotExist (
7073 "{$ dir }/test.txt " ,
@@ -83,7 +86,7 @@ public function testReturnInaccessiblePropertyValueWhenPropertyIsPrivate(): void
8386 {
8487 self ::assertSame (
8588 'value ' ,
86- Assert ::inaccessibleProperty (new TestClass (), 'property ' ),
89+ self ::inaccessibleProperty (new TestClass (), 'property ' ),
8790 "Should return the value of the private property 'property' when accessed via reflection. " ,
8891 );
8992 }
@@ -95,7 +98,7 @@ public function testReturnValueWhenInvokingInaccessibleMethod(): void
9598 {
9699 $ this ->assertSame (
97100 'value ' ,
98- Assert ::invokeMethod (new TestClass (), 'inaccessibleMethod ' ),
101+ self ::invokeMethod (new TestClass (), 'inaccessibleMethod ' ),
99102 "Should return 'value' when invoking the inaccessible method 'inaccessibleParentMethod' on 'TestClass' " .
100103 'via reflection. ' ,
101104 );
@@ -108,7 +111,7 @@ public function testReturnValueWhenInvokingInaccessibleParentMethod(): void
108111 {
109112 $ this ->assertSame (
110113 'valueParent ' ,
111- Assert ::invokeParentMethod (
114+ self ::invokeParentMethod (
112115 new TestClass (),
113116 TestBaseClass::class,
114117 'inaccessibleParentMethod ' ,
@@ -125,11 +128,11 @@ public function testSetInaccessibleParentProperty(): void
125128 {
126129 $ object = new TestClass ();
127130
128- Assert ::setInaccessibleParentProperty ($ object , TestBaseClass::class, 'propertyParent ' , 'foo ' );
131+ self ::setInaccessibleParentProperty ($ object , TestBaseClass::class, 'propertyParent ' , 'foo ' );
129132
130133 $ this ->assertSame (
131134 'foo ' ,
132- Assert ::inaccessibleParentProperty ($ object , TestBaseClass::class, 'propertyParent ' ),
135+ self ::inaccessibleParentProperty ($ object , TestBaseClass::class, 'propertyParent ' ),
133136 "Should return 'foo' after setting the parent property 'propertyParent' via " .
134137 "'setInaccessibleParentProperty' method. " ,
135138 );
@@ -142,11 +145,11 @@ public function testSetInaccessiblePropertySetsValueCorrectly(): void
142145 {
143146 $ object = new TestClass ();
144147
145- Assert ::setInaccessibleProperty ($ object , 'property ' , 'foo ' );
148+ self ::setInaccessibleProperty ($ object , 'property ' , 'foo ' );
146149
147150 $ this ->assertSame (
148151 'foo ' ,
149- Assert ::inaccessibleProperty ($ object , 'property ' ),
152+ self ::inaccessibleProperty ($ object , 'property ' ),
150153 "Should return 'foo' after setting the private property 'property' via 'setInaccessibleProperty' method. " ,
151154 );
152155 }
@@ -156,6 +159,6 @@ public function testThrowRuntimeExceptionWhenRemoveFilesFromDirectoryNonExisting
156159 $ this ->expectException (RuntimeException::class);
157160 $ this ->expectExceptionMessage ('Unable to open directory: non-existing-directory ' );
158161
159- Assert ::removeFilesFromDirectory (__DIR__ . '/non-existing-directory ' );
162+ self ::removeFilesFromDirectory (__DIR__ . '/non-existing-directory ' );
160163 }
161164}
0 commit comments