@@ -95,6 +95,123 @@ public function testProcessBypassesWithoutMapAttribute(): void
9595 $ processor = new ObjectMapperProcessor ($ objectMapper , $ decorated );
9696 $ this ->assertEquals ($ data , $ processor ->process ($ data , $ operation ));
9797 }
98+
99+ public function testProcessWithNoCustomInputAndNoCustomOutput (): void
100+ {
101+ $ entity = new DummyEntity ();
102+ $ persisted = new DummyEntity ();
103+ $ operation = (new Post (class: DummyEntity::class, write: true ))->withMap (true );
104+
105+ $ objectMapper = $ this ->createMock (ObjectMapperInterface::class);
106+ $ objectMapper ->expects ($ this ->never ())->method ('map ' );
107+
108+ $ decorated = $ this ->createMock (ProcessorInterface::class);
109+ $ decorated ->expects ($ this ->once ())
110+ ->method ('process ' )
111+ ->with ($ entity , $ operation , [], [])
112+ ->willReturn ($ persisted );
113+
114+ $ processor = new ObjectMapperProcessor ($ objectMapper , $ decorated );
115+ $ result = $ processor ->process ($ entity , $ operation );
116+
117+ $ this ->assertSame ($ persisted , $ result );
118+ }
119+
120+ public function testProcessWithNoCustomInputAndCustomOutput (): void
121+ {
122+ $ entity = new DummyEntity ();
123+ $ persisted = new DummyEntity ();
124+ $ output = new DummyOutput ();
125+ $ operation = (new Post (
126+ class: DummyEntity::class,
127+ output: ['class ' => DummyOutput::class],
128+ write: true
129+ ))->withMap (true );
130+
131+ $ objectMapper = $ this ->createMock (ObjectMapperInterface::class);
132+ $ objectMapper ->expects ($ this ->once ())
133+ ->method ('map ' )
134+ ->with ($ persisted , DummyOutput::class)
135+ ->willReturn ($ output );
136+
137+ $ decorated = $ this ->createMock (ProcessorInterface::class);
138+ $ decorated ->expects ($ this ->once ())
139+ ->method ('process ' )
140+ ->with ($ entity , $ operation , [], [])
141+ ->willReturn ($ persisted );
142+
143+ $ processor = new ObjectMapperProcessor ($ objectMapper , $ decorated );
144+ $ result = $ processor ->process ($ entity , $ operation );
145+
146+ $ this ->assertSame ($ output , $ result );
147+ }
148+
149+ public function testProcessWithCustomInputAndNoCustomOutput (): void
150+ {
151+ $ input = new DummyInput ();
152+ $ entity = new DummyEntity ();
153+ $ persisted = new DummyEntity ();
154+ $ operation = (new Post (
155+ class: DummyEntity::class,
156+ input: ['class ' => DummyInput::class],
157+ write: true
158+ ))->withMap (true );
159+
160+ $ objectMapper = $ this ->createMock (ObjectMapperInterface::class);
161+ $ objectMapper ->expects ($ this ->once ())
162+ ->method ('map ' )
163+ ->with ($ input , null )
164+ ->willReturn ($ entity );
165+
166+ $ decorated = $ this ->createMock (ProcessorInterface::class);
167+ $ decorated ->expects ($ this ->once ())
168+ ->method ('process ' )
169+ ->with ($ entity , $ operation , [], [])
170+ ->willReturn ($ persisted );
171+
172+ $ processor = new ObjectMapperProcessor ($ objectMapper , $ decorated );
173+ $ result = $ processor ->process ($ input , $ operation );
174+
175+ $ this ->assertSame ($ persisted , $ result );
176+ }
177+
178+ public function testProcessWithCustomInputAndCustomOutput (): void
179+ {
180+ $ input = new DummyInput ();
181+ $ entity = new DummyEntity ();
182+ $ persisted = new DummyEntity ();
183+ $ output = new DummyOutput ();
184+ $ operation = (new Post (
185+ class: DummyEntity::class,
186+ input: ['class ' => DummyInput::class],
187+ output: ['class ' => DummyOutput::class],
188+ write: true
189+ ))->withMap (true );
190+
191+ $ objectMapper = $ this ->createMock (ObjectMapperInterface::class);
192+ $ objectMapper ->expects ($ this ->exactly (2 ))
193+ ->method ('map ' )
194+ ->willReturnCallback (function ($ data , $ target ) use ($ input , $ entity , $ persisted , $ output ) {
195+ if ($ data === $ input && null === $ target ) {
196+ return $ entity ;
197+ }
198+ if ($ data === $ persisted && DummyOutput::class === $ target ) {
199+ return $ output ;
200+ }
201+ throw new \Exception ('Unexpected map call ' );
202+ });
203+
204+ $ decorated = $ this ->createMock (ProcessorInterface::class);
205+ $ decorated ->expects ($ this ->once ())
206+ ->method ('process ' )
207+ ->with ($ entity , $ operation , [], [])
208+ ->willReturn ($ persisted );
209+
210+ $ processor = new ObjectMapperProcessor ($ objectMapper , $ decorated );
211+ $ result = $ processor ->process ($ input , $ operation );
212+
213+ $ this ->assertSame ($ output , $ result );
214+ }
98215}
99216
100217class DummyResourceWithoutMap
@@ -105,3 +222,18 @@ class DummyResourceWithoutMap
105222class DummyResourceWithMap
106223{
107224}
225+
226+ #[Map]
227+ class DummyEntity
228+ {
229+ }
230+
231+ #[Map]
232+ class DummyInput
233+ {
234+ }
235+
236+ #[Map]
237+ class DummyOutput
238+ {
239+ }
0 commit comments