@@ -40,11 +40,11 @@ public function testInspect(): void
40
40
41
41
$ mockHandler ->expects ($ this ->once ())
42
42
->method ('handleAttribute ' )
43
- ->willReturn ( ' handled result ' );
43
+ ->with ( ' property1 ' , $ this -> isInstanceOf (\stdClass::class), ' value1 ' );
44
44
45
45
$ result = $ this ->inspector ->inspect ($ object , $ mockHandler );
46
46
47
- $ this ->assertEquals ([ ' property1 ' => [ ' handled result ' ]] , $ result );
47
+ $ this ->assertSame ( $ mockHandler , $ result );
48
48
}
49
49
50
50
public function testInspectWithNoResults (): void
@@ -56,9 +56,12 @@ public function testInspectWithNoResults(): void
56
56
->method ('analyzeObject ' )
57
57
->willReturn ([]);
58
58
59
+ $ mockHandler ->expects ($ this ->never ())
60
+ ->method ('handleAttribute ' );
61
+
59
62
$ result = $ this ->inspector ->inspect ($ object , $ mockHandler );
60
63
61
- $ this ->assertEmpty ( $ result );
64
+ $ this ->assertSame ( $ mockHandler , $ result );
62
65
}
63
66
64
67
public function testInspectWithAnalyzerException (): void
@@ -76,7 +79,7 @@ public function testInspectWithAnalyzerException(): void
76
79
$ this ->inspector ->inspect ($ object , $ mockHandler );
77
80
}
78
81
79
- public function testInspectWithHandlerReturningNull (): void
82
+ public function testInspectWithMultipleAttributes (): void
80
83
{
81
84
$ object = new \stdClass ();
82
85
$ mockHandler = $ this ->createMock (PropertyAttributeHandler::class);
@@ -86,39 +89,46 @@ public function testInspectWithHandlerReturningNull(): void
86
89
->willReturn ([
87
90
'property1 ' => [
88
91
'value ' => 'value1 ' ,
89
- 'attributes ' => [new \stdClass ()],
92
+ 'attributes ' => [new \stdClass (), new \ stdClass () ],
90
93
],
91
94
]);
92
95
93
- $ mockHandler ->expects ($ this ->once ( ))
96
+ $ mockHandler ->expects ($ this ->exactly ( 2 ))
94
97
->method ('handleAttribute ' )
95
- ->willReturn ( null );
98
+ ->with ( ' property1 ' , $ this -> isInstanceOf (\stdClass::class), ' value1 ' );
96
99
97
100
$ result = $ this ->inspector ->inspect ($ object , $ mockHandler );
98
101
99
- $ this ->assertEmpty ( $ result );
102
+ $ this ->assertSame ( $ mockHandler , $ result );
100
103
}
101
104
102
- public function testInspectWithMultipleAttributes (): void
105
+ public function testInspectWithGeneralException (): void
103
106
{
104
107
$ object = new \stdClass ();
105
108
$ mockHandler = $ this ->createMock (PropertyAttributeHandler::class);
106
109
107
110
$ this ->analyzer ->expects ($ this ->once ())
108
111
->method ('analyzeObject ' )
109
- ->willReturn ([
110
- 'property1 ' => [
111
- 'value ' => 'value1 ' ,
112
- 'attributes ' => [new \stdClass (), new \stdClass ()],
113
- ],
114
- ]);
112
+ ->willThrowException (new \Exception ('General exception ' ));
115
113
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 ' );
119
116
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 ' ));
121
128
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 );
123
133
}
124
134
}
0 commit comments