Skip to content

Commit 0d66a4a

Browse files
committed
Test input with messenger
1 parent 9e2d393 commit 0d66a4a

File tree

5 files changed

+113
-0
lines changed

5 files changed

+113
-0
lines changed

features/main/input_output.feature

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,25 @@ Feature: DTO input and output
245245
"""
246246
Then the response status code should be 201
247247
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+
"""
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
}

tests/Fixtures/app/config/config_common.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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' }

0 commit comments

Comments
 (0)