File tree Expand file tree Collapse file tree 5 files changed +114
-0
lines changed
Expand file tree Collapse file tree 5 files changed +114
-0
lines changed Original file line number Diff line number Diff line change @@ -242,3 +242,26 @@ Feature: DTO input and output
242242 }
243243 }
244244 """
245+
246+ @createSchema
247+ Scenario : Use messenger with an input where the handler gives a synchronous result
248+ When I add "Content-Type" header equal to "application/ld+json"
249+ And I send a "POST" request to "/messenger_with_inputs" with body:
250+ """
251+ {
252+ "var": "test"
253+ }
254+ """
255+ Then the response status code should be 201
256+ And the response should be in JSON
257+ And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
258+ And the JSON should be equal to:
259+ """
260+ {
261+ "@context": "/contexts/MessengerWithInput",
262+ "@id": "/messenger_with_inputs/1",
263+ "@type": "MessengerWithInput",
264+ "id": 1,
265+ "name": "test"
266+ }
267+ """
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 <dunglas@gmail.com>
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 <dunglas@gmail.com>
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 <dunglas@gmail.com>
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:
238238 public : false
239239 tags :
240240 - { 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