File tree Expand file tree Collapse file tree 5 files changed +113
-0
lines changed Expand file tree Collapse file tree 5 files changed +113
-0
lines changed Original file line number Diff line number Diff line change @@ -245,3 +245,25 @@ Feature: DTO input and output
245
245
"""
246
246
Then the response status code should be 201
247
247
And the response should be empty
248
+
249
+ Scenario : Use messenger with an input where the handler gives a synchronous result
250
+ When I add "Content-Type" header equal to "application/ld+json"
251
+ And I send a "POST" request to "/messenger_with_inputs" with body:
252
+ """
253
+ {
254
+ "var": "test"
255
+ }
256
+ """
257
+ Then the response status code should be 201
258
+ And the response should be in JSON
259
+ And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
260
+ And the JSON should be equal to:
261
+ """
262
+ {
263
+ "@context": "/contexts/MessengerWithInput",
264
+ "@id": "/messenger_with_inputs/1",
265
+ "@type": "MessengerWithInput",
266
+ "id": 1,
267
+ "name": "test"
268
+ }
269
+ """
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the API Platform project.
5
+ *
6
+ * (c) Kévin Dunglas <[email protected] >
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ declare (strict_types=1 );
13
+
14
+ namespace ApiPlatform \Core \Tests \Fixtures \TestBundle \Dto ;
15
+
16
+ class MessengerInput
17
+ {
18
+ /**
19
+ * @var string
20
+ */
21
+ public $ var ;
22
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the API Platform project.
5
+ *
6
+ * (c) Kévin Dunglas <[email protected] >
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ declare (strict_types=1 );
13
+
14
+ namespace ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity ;
15
+
16
+ use ApiPlatform \Core \Annotation \ApiProperty ;
17
+ use ApiPlatform \Core \Annotation \ApiResource ;
18
+ use ApiPlatform \Core \Tests \Fixtures \TestBundle \Dto \MessengerInput ;
19
+
20
+ /**
21
+ * @ApiResource(messenger="input", input=MessengerInput::class)
22
+ */
23
+ class MessengerWithInput
24
+ {
25
+ /**
26
+ * @ApiProperty(identifier=true)
27
+ */
28
+ public $ id ;
29
+ /**
30
+ * @var string
31
+ */
32
+ public $ name ;
33
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the API Platform project.
5
+ *
6
+ * (c) Kévin Dunglas <[email protected] >
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ declare (strict_types=1 );
13
+
14
+ namespace ApiPlatform \Core \Tests \Fixtures \TestBundle \MessengerHandler ;
15
+
16
+ use ApiPlatform \Core \Tests \Fixtures \TestBundle \Dto \MessengerInput ;
17
+ use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \MessengerWithInput ;
18
+ use Symfony \Component \Messenger \Handler \MessageHandlerInterface ;
19
+
20
+ class MessengerWithInputHandler implements MessageHandlerInterface
21
+ {
22
+ public function __invoke (MessengerInput $ data )
23
+ {
24
+ $ object = new MessengerWithInput ();
25
+ $ object ->name = 'test ' ;
26
+ $ object ->id = 1 ;
27
+
28
+ return $ object ;
29
+ }
30
+ }
Original file line number Diff line number Diff line change @@ -238,3 +238,9 @@ services:
238
238
public : false
239
239
tags :
240
240
- { name: 'api_platform.data_transformer' }
241
+
242
+ app.messenger_handler.messenger_with_inputs :
243
+ class : ' ApiPlatform\Core\Tests\Fixtures\TestBundle\MessengerHandler\MessengerWithInputHandler'
244
+ public : false
245
+ tags :
246
+ - { name: 'messenger.message_handler' }
You can’t perform that action at this time.
0 commit comments