@@ -95,6 +95,126 @@ 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, map: true , write: 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+ map: true ,
129+ write: true
130+ );
131+
132+ $ objectMapper = $ this ->createMock (ObjectMapperInterface::class);
133+ $ objectMapper ->expects ($ this ->once ())
134+ ->method ('map ' )
135+ ->with ($ persisted , DummyOutput::class)
136+ ->willReturn ($ output );
137+
138+ $ decorated = $ this ->createMock (ProcessorInterface::class);
139+ $ decorated ->expects ($ this ->once ())
140+ ->method ('process ' )
141+ ->with ($ entity , $ operation , [], [])
142+ ->willReturn ($ persisted );
143+
144+ $ processor = new ObjectMapperProcessor ($ objectMapper , $ decorated );
145+ $ result = $ processor ->process ($ entity , $ operation );
146+
147+ $ this ->assertSame ($ output , $ result );
148+ }
149+
150+ public function testProcessWithCustomInputAndNoCustomOutput (): void
151+ {
152+ $ input = new DummyInput ();
153+ $ entity = new DummyEntity ();
154+ $ persisted = new DummyEntity ();
155+ $ operation = new Post (
156+ class: DummyEntity::class,
157+ input: ['class ' => DummyInput::class],
158+ map: true ,
159+ write: true
160+ );
161+
162+ $ objectMapper = $ this ->createMock (ObjectMapperInterface::class);
163+ $ objectMapper ->expects ($ this ->once ())
164+ ->method ('map ' )
165+ ->with ($ input , null )
166+ ->willReturn ($ entity );
167+
168+ $ decorated = $ this ->createMock (ProcessorInterface::class);
169+ $ decorated ->expects ($ this ->once ())
170+ ->method ('process ' )
171+ ->with ($ entity , $ operation , [], [])
172+ ->willReturn ($ persisted );
173+
174+ $ processor = new ObjectMapperProcessor ($ objectMapper , $ decorated );
175+ $ result = $ processor ->process ($ input , $ operation );
176+
177+ $ this ->assertSame ($ persisted , $ result );
178+ }
179+
180+ public function testProcessWithCustomInputAndCustomOutput (): void
181+ {
182+ $ input = new DummyInput ();
183+ $ entity = new DummyEntity ();
184+ $ persisted = new DummyEntity ();
185+ $ output = new DummyOutput ();
186+ $ operation = new Post (
187+ class: DummyEntity::class,
188+ input: ['class ' => DummyInput::class],
189+ output: ['class ' => DummyOutput::class],
190+ map: true ,
191+ write: true
192+ );
193+
194+ $ objectMapper = $ this ->createMock (ObjectMapperInterface::class);
195+ $ objectMapper ->expects ($ this ->exactly (2 ))
196+ ->method ('map ' )
197+ ->willReturnCallback (function ($ data , $ target ) use ($ input , $ entity , $ persisted , $ output ) {
198+ if ($ data === $ input && $ target === null ) {
199+ return $ entity ;
200+ }
201+ if ($ data === $ persisted && $ target === DummyOutput::class) {
202+ return $ output ;
203+ }
204+ throw new \Exception ('Unexpected map call ' );
205+ });
206+
207+ $ decorated = $ this ->createMock (ProcessorInterface::class);
208+ $ decorated ->expects ($ this ->once ())
209+ ->method ('process ' )
210+ ->with ($ entity , $ operation , [], [])
211+ ->willReturn ($ persisted );
212+
213+ $ processor = new ObjectMapperProcessor ($ objectMapper , $ decorated );
214+ $ result = $ processor ->process ($ input , $ operation );
215+
216+ $ this ->assertSame ($ output , $ result );
217+ }
98218}
99219
100220class DummyResourceWithoutMap
@@ -105,3 +225,18 @@ class DummyResourceWithoutMap
105225class DummyResourceWithMap
106226{
107227}
228+
229+ #[Map]
230+ class DummyEntity
231+ {
232+ }
233+
234+ #[Map]
235+ class DummyInput
236+ {
237+ }
238+
239+ #[Map]
240+ class DummyOutput
241+ {
242+ }
0 commit comments