Skip to content

Commit

Permalink
Rename WebhookHandler to WebhookConsumer and all() method on payload
Browse files Browse the repository at this point in the history
  • Loading branch information
maelanleborgne authored and jrushlow committed Apr 5, 2024
1 parent 35f8652 commit 5582b7b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/Maker/MakeWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
Str::asClassName($this->name.'RequestParser'),
'Webhook\\'
);
$remoteEventHandlerDetails = $this->generator->createClassNameDetails(
Str::asClassName($this->name.'WebhookHandler'),
$remoteEventConsumerDetails = $this->generator->createClassNameDetails(
Str::asClassName($this->name.'WebhookConsumer'),
'RemoteEvent\\'
);

Expand All @@ -142,8 +142,8 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
$this->generateRequestParser($io, $requestParserDetails);

$this->generator->generateClass(
$remoteEventHandlerDetails->getFullName(),
'webhook/WebhookHandler.tpl.php',
$remoteEventConsumerDetails->getFullName(),
'webhook/WebhookConsumer.tpl.php',
[
'webhook_name' => $this->name,
]
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/skeleton/webhook/RequestParser.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function doParse(Request $request, #[\SensitiveParameter] string $secr
}

// Parse the request payload and return a RemoteEvent object.
$payload = $request->getPayload()->getIterator()->getArrayCopy();
$payload = $request->getPayload()->all();

return new RemoteEvent(
$payload['name'],
Expand Down
14 changes: 7 additions & 7 deletions tests/Maker/MakeWebhookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public function getTestDetails(): \Generator
'use Symfony\Component\Webhook\Client\AbstractRequestParser;',
file_get_contents($runner->getPath('src/Webhook/RemoteServiceRequestParser.php'))
);
$this->assertFileExists($runner->getPath('src/RemoteEvent/RemoteServiceWebhookHandler.php'));
$this->assertFileExists($runner->getPath('src/RemoteEvent/RemoteServiceWebhookConsumer.php'));
$this->assertStringContainsString(
'#[AsRemoteEventConsumer(\'remote_service\')]',
file_get_contents($runner->getPath('src/RemoteEvent/RemoteServiceWebhookHandler.php')),
file_get_contents($runner->getPath('src/RemoteEvent/RemoteServiceWebhookConsumer.php')),
);
$securityConfig = $runner->readYaml('config/packages/webhook.yaml');
$this->assertEquals(
Expand All @@ -59,7 +59,7 @@ public function getTestDetails(): \Generator
->run(function (MakerTestRunner $runner) {
$runner->copy('make-webhook/webhook.yaml', 'config/packages/webhook.yaml');
$runner->copy('make-webhook/RemoteServiceRequestParser.php', 'src/Webhook/RemoteServiceRequestParser.php');
$runner->copy('make-webhook/RemoteServiceWebhookHandler.php', 'src/RemoteEvent/RemoteServiceWebhookHandler.php');
$runner->copy('make-webhook/RemoteServiceWebhookConsumer.php', 'src/RemoteEvent/RemoteServiceWebhookConsumer.php');
$output = $runner->runMaker([
// webhook name
'another_remote_service',
Expand All @@ -68,7 +68,7 @@ public function getTestDetails(): \Generator
]);
$this->assertStringContainsString('created:', $output);
$this->assertFileExists($runner->getPath('src/Webhook/AnotherRemoteServiceRequestParser.php'));
$this->assertFileExists($runner->getPath('src/RemoteEvent/AnotherRemoteServiceWebhookHandler.php'));
$this->assertFileExists($runner->getPath('src/RemoteEvent/AnotherRemoteServiceWebhookConsumer.php'));
$securityConfig = $runner->readYaml('config/packages/webhook.yaml');
// original config should not be modified
$this->assertArrayHasKey('remote_service', $securityConfig['framework']['webhook']['routing']);
Expand Down Expand Up @@ -103,7 +103,7 @@ public function getTestDetails(): \Generator
]);
$this->assertStringContainsString('created:', $output);
$this->assertFileExists($runner->getPath('src/Webhook/RemoteServiceRequestParser.php'));
$this->assertFileExists($runner->getPath('src/RemoteEvent/RemoteServiceWebhookHandler.php'));
$this->assertFileExists($runner->getPath('src/RemoteEvent/RemoteServiceWebhookConsumer.php'));
$requestParserSource = file_get_contents($runner->getPath('src/Webhook/RemoteServiceRequestParser.php'));
$this->assertStringContainsString(
'use Symfony\Component\HttpFoundation\RequestMatcher\IsJsonRequestMatcher;',
Expand All @@ -127,7 +127,7 @@ public function getTestDetails(): \Generator
]);
$this->assertStringContainsString('created:', $output);
$this->assertFileExists($runner->getPath('src/Webhook/RemoteServiceRequestParser.php'));
$this->assertFileExists($runner->getPath('src/RemoteEvent/RemoteServiceWebhookHandler.php'));
$this->assertFileExists($runner->getPath('src/RemoteEvent/RemoteServiceWebhookConsumer.php'));
$requestParserSource = file_get_contents($runner->getPath('src/Webhook/RemoteServiceRequestParser.php'));
$this->assertStringContainsString(
'use Symfony\Component\HttpFoundation\RequestMatcher\IsJsonRequestMatcher;',
Expand Down Expand Up @@ -165,7 +165,7 @@ public function getTestDetails(): \Generator
]);
$this->assertStringContainsString('created:', $output);
$this->assertFileExists($runner->getPath('src/Webhook/RemoteServiceRequestParser.php'));
$this->assertFileExists($runner->getPath('src/RemoteEvent/RemoteServiceWebhookHandler.php'));
$this->assertFileExists($runner->getPath('src/RemoteEvent/RemoteServiceWebhookConsumer.php'));
$requestParserSource = file_get_contents($runner->getPath('src/Webhook/RemoteServiceRequestParser.php'));
$this->assertStringContainsString(
'use Symfony\Component\HttpFoundation\RequestMatcher\IsJsonRequestMatcher;',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Symfony\Component\RemoteEvent\RemoteEvent;

#[AsRemoteEventConsumer('remote_service')]
final class RemoteServiceWebhookHandler implements ConsumerInterface
final class RemoteServiceWebhookConsumer implements ConsumerInterface
{
public function __construct()
{
Expand Down

0 comments on commit 5582b7b

Please sign in to comment.