88use KaririCode \Contract \Processor \ProcessorRegistry ;
99use KaririCode \Sanitizer \Attribute \Sanitize ;
1010use KaririCode \Sanitizer \Contract \SanitizationResult ;
11- use KaririCode \Sanitizer \Contract \SanitizationResultProcessor ;
12- use KaririCode \Sanitizer \Processor \Input \TrimSanitizer ;
1311use KaririCode \Sanitizer \Sanitizer ;
1412use PHPUnit \Framework \MockObject \MockObject ;
1513use PHPUnit \Framework \TestCase ;
@@ -18,18 +16,14 @@ final class SanitizerTest extends TestCase
1816{
1917 private Sanitizer $ sanitizer ;
2018 private ProcessorRegistry |MockObject $ registry ;
21- private SanitizationResultProcessor |MockObject $ resultProcessor ;
22- private SanitizationResult |MockObject $ sanitizationResult ;
2319
2420 protected function setUp (): void
2521 {
2622 $ this ->registry = $ this ->createMock (ProcessorRegistry::class);
27- $ this ->resultProcessor = $ this ->createMock (SanitizationResultProcessor::class);
28- $ this ->sanitizationResult = $ this ->createMock (SanitizationResult::class);
29- $ this ->sanitizer = new Sanitizer ($ this ->registry , $ this ->resultProcessor );
23+ $ this ->sanitizer = new Sanitizer ($ this ->registry );
3024 }
3125
32- private function createProcessorMock (string $ name , mixed $ input , mixed $ output ): Processor |MockObject
26+ private function createProcessorMock (mixed $ input , mixed $ output ): Processor |MockObject
3327 {
3428 $ processor = $ this ->createMock (Processor::class);
3529 $ processor ->method ('process ' )
@@ -76,14 +70,11 @@ public function testSanitizeProcessesObjectProperties(): void
7670 return null ;
7771 });
7872
79- $ this ->resultProcessor ->method ('process ' )
80- ->willReturn ($ this ->sanitizationResult );
81-
8273 $ result = $ this ->sanitizer ->sanitize ($ testObject );
8374
8475 $ this ->assertSame ('Walmir Silva ' , $ testObject ->name );
8576 $ this ->assertSame ('walmir.silva@example.com ' , $ testObject ->email );
86- $ this ->assertSame ( $ this -> sanitizationResult , $ result );
77+ $ this ->assertInstanceOf (SanitizationResult::class , $ result );
8778 }
8879
8980 public function testSanitizeHandlesNonProcessableAttributes (): void
@@ -96,7 +87,6 @@ public function testSanitizeHandlesNonProcessableAttributes(): void
9687 };
9788
9889 $ trimProcessor = $ this ->createProcessorMock (
99- 'trim ' ,
10090 ' trim me ' ,
10191 'trim me '
10292 );
@@ -105,14 +95,11 @@ public function testSanitizeHandlesNonProcessableAttributes(): void
10595 ->with ('sanitizer ' , 'trim ' )
10696 ->willReturn ($ trimProcessor );
10797
108- $ this ->resultProcessor ->method ('process ' )
109- ->willReturn ($ this ->sanitizationResult );
110-
11198 $ result = $ this ->sanitizer ->sanitize ($ testObject );
11299
113100 $ this ->assertSame ('trim me ' , $ testObject ->processable );
114101 $ this ->assertSame ('leave me alone ' , $ testObject ->nonProcessable );
115- $ this ->assertSame ( $ this -> sanitizationResult , $ result );
102+ $ this ->assertInstanceOf (SanitizationResult::class , $ result );
116103 }
117104
118105 public function testSanitizeHandlesExceptionsAndUsesFallbackValue (): void
@@ -130,13 +117,10 @@ public function testSanitizeHandlesExceptionsAndUsesFallbackValue(): void
130117 ->with ('sanitizer ' , 'problematic ' )
131118 ->willReturn ($ problematicProcessor );
132119
133- $ this ->resultProcessor ->method ('process ' )
134- ->willReturn ($ this ->sanitizationResult );
135-
136120 $ result = $ this ->sanitizer ->sanitize ($ testObject );
137121
138122 $ this ->assertSame ('cause problem ' , $ testObject ->problematic );
139- $ this ->assertSame ( $ this -> sanitizationResult , $ result );
123+ $ this ->assertInstanceOf (SanitizationResult::class , $ result );
140124 }
141125
142126 public function testSanitizeHandlesPrivateAndProtectedProperties (): void
@@ -171,14 +155,11 @@ public function getProtectedProp(): string
171155 ->with ('sanitizer ' , 'trim ' )
172156 ->willReturn ($ trimProcessor );
173157
174- $ this ->resultProcessor ->method ('process ' )
175- ->willReturn ($ this ->sanitizationResult );
176-
177158 $ result = $ this ->sanitizer ->sanitize ($ testObject );
178159
179160 $ this ->assertSame ('private ' , $ testObject ->getPrivateProp ());
180161 $ this ->assertSame ('protected ' , $ testObject ->getProtectedProp ());
181- $ this ->assertSame ( $ this -> sanitizationResult , $ result );
162+ $ this ->assertInstanceOf (SanitizationResult::class , $ result );
182163 }
183164
184165 public function testSanitizeHandlesMultipleProcessorsForSingleProperty (): void
@@ -189,13 +170,11 @@ public function testSanitizeHandlesMultipleProcessorsForSingleProperty(): void
189170 };
190171
191172 $ trimProcessor = $ this ->createProcessorMock (
192- 'trim ' ,
193173 ' hello world ' ,
194174 'hello world '
195175 );
196176
197177 $ uppercaseProcessor = $ this ->createProcessorMock (
198- 'uppercase ' ,
199178 'hello world ' ,
200179 'HELLO WORLD '
201180 );
@@ -206,12 +185,9 @@ public function testSanitizeHandlesMultipleProcessorsForSingleProperty(): void
206185 ['sanitizer ' , 'uppercase ' , $ uppercaseProcessor ],
207186 ]);
208187
209- $ this ->resultProcessor ->method ('process ' )
210- ->willReturn ($ this ->sanitizationResult );
211-
212188 $ result = $ this ->sanitizer ->sanitize ($ testObject );
213189
214190 $ this ->assertSame ('HELLO WORLD ' , $ testObject ->multiProcessed );
215- $ this ->assertSame ( $ this -> sanitizationResult , $ result );
191+ $ this ->assertInstanceOf (SanitizationResult::class , $ result );
216192 }
217193}
0 commit comments