@@ -40,11 +40,11 @@ public function testInspect(): void
4040
4141 $ mockHandler ->expects ($ this ->once ())
4242 ->method ('handleAttribute ' )
43- ->willReturn ( ' handled result ' );
43+ ->with ( ' property1 ' , $ this -> isInstanceOf (\stdClass::class), ' value1 ' );
4444
4545 $ result = $ this ->inspector ->inspect ($ object , $ mockHandler );
4646
47- $ this ->assertEquals ([ ' property1 ' => [ ' handled result ' ]] , $ result );
47+ $ this ->assertSame ( $ mockHandler , $ result );
4848 }
4949
5050 public function testInspectWithNoResults (): void
@@ -56,9 +56,12 @@ public function testInspectWithNoResults(): void
5656 ->method ('analyzeObject ' )
5757 ->willReturn ([]);
5858
59+ $ mockHandler ->expects ($ this ->never ())
60+ ->method ('handleAttribute ' );
61+
5962 $ result = $ this ->inspector ->inspect ($ object , $ mockHandler );
6063
61- $ this ->assertEmpty ( $ result );
64+ $ this ->assertSame ( $ mockHandler , $ result );
6265 }
6366
6467 public function testInspectWithAnalyzerException (): void
@@ -76,7 +79,7 @@ public function testInspectWithAnalyzerException(): void
7679 $ this ->inspector ->inspect ($ object , $ mockHandler );
7780 }
7881
79- public function testInspectWithHandlerReturningNull (): void
82+ public function testInspectWithMultipleAttributes (): void
8083 {
8184 $ object = new \stdClass ();
8285 $ mockHandler = $ this ->createMock (PropertyAttributeHandler::class);
@@ -86,39 +89,46 @@ public function testInspectWithHandlerReturningNull(): void
8689 ->willReturn ([
8790 'property1 ' => [
8891 'value ' => 'value1 ' ,
89- 'attributes ' => [new \stdClass ()],
92+ 'attributes ' => [new \stdClass (), new \ stdClass () ],
9093 ],
9194 ]);
9295
93- $ mockHandler ->expects ($ this ->once ( ))
96+ $ mockHandler ->expects ($ this ->exactly ( 2 ))
9497 ->method ('handleAttribute ' )
95- ->willReturn ( null );
98+ ->with ( ' property1 ' , $ this -> isInstanceOf (\stdClass::class), ' value1 ' );
9699
97100 $ result = $ this ->inspector ->inspect ($ object , $ mockHandler );
98101
99- $ this ->assertEmpty ( $ result );
102+ $ this ->assertSame ( $ mockHandler , $ result );
100103 }
101104
102- public function testInspectWithMultipleAttributes (): void
105+ public function testInspectWithGeneralException (): void
103106 {
104107 $ object = new \stdClass ();
105108 $ mockHandler = $ this ->createMock (PropertyAttributeHandler::class);
106109
107110 $ this ->analyzer ->expects ($ this ->once ())
108111 ->method ('analyzeObject ' )
109- ->willReturn ([
110- 'property1 ' => [
111- 'value ' => 'value1 ' ,
112- 'attributes ' => [new \stdClass (), new \stdClass ()],
113- ],
114- ]);
112+ ->willThrowException (new \Exception ('General exception ' ));
115113
116- $ mockHandler ->expects ($ this ->exactly (2 ))
117- ->method ('handleAttribute ' )
118- ->willReturn ('handled result ' );
114+ $ this ->expectException (PropertyInspectionException::class);
115+ $ this ->expectExceptionMessage ('An exception occurred during object analysis: General exception ' );
119116
120- $ result = $ this ->inspector ->inspect ($ object , $ mockHandler );
117+ $ this ->inspector ->inspect ($ object , $ mockHandler );
118+ }
119+
120+ public function testInspectWithError (): void
121+ {
122+ $ object = new \stdClass ();
123+ $ mockHandler = $ this ->createMock (PropertyAttributeHandler::class);
124+
125+ $ this ->analyzer ->expects ($ this ->once ())
126+ ->method ('analyzeObject ' )
127+ ->willThrowException (new \Error ('Fatal error ' ));
121128
122- $ this ->assertEquals (['property1 ' => ['handled result ' , 'handled result ' ]], $ result );
129+ $ this ->expectException (PropertyInspectionException::class);
130+ $ this ->expectExceptionMessage ('An error occurred during object analysis: Fatal error ' );
131+
132+ $ this ->inspector ->inspect ($ object , $ mockHandler );
123133 }
124134}
0 commit comments