From d84f3eba3f8815f83ff196bad382034f60c2b548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20St=C3=B6hr?= Date: Wed, 31 Jan 2024 11:13:33 +0100 Subject: [PATCH] fix: use method from metadata for live component test helper --- .../src/Test/TestLiveComponent.php | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/LiveComponent/src/Test/TestLiveComponent.php b/src/LiveComponent/src/Test/TestLiveComponent.php index a0300723142..fcfa8b9a545 100644 --- a/src/LiveComponent/src/Test/TestLiveComponent.php +++ b/src/LiveComponent/src/Test/TestLiveComponent.php @@ -51,13 +51,25 @@ public function __construct( $this->metadataFactory->getMetadata($mounted->getName()) ); - $this->client->request('GET', $this->router->generate( - $this->metadata->get('route'), - [ - '_live_component' => $this->metadata->getName(), - 'props' => json_encode($props->getProps(), flags: \JSON_THROW_ON_ERROR), - ] - )); + if ('POST' === strtoupper($this->metadata->get('method'))) { + $this->client->request( + 'POST', + $this->router->generate($this->metadata->get('route'), [ + '_live_component' => $this->metadata->getName(), + ]), + [ + 'data' => json_encode(['props' => $props->getProps()], flags: \JSON_THROW_ON_ERROR), + ], + ); + } else { + $this->client->request('GET', $this->router->generate( + $this->metadata->get('route'), + [ + '_live_component' => $this->metadata->getName(), + 'props' => json_encode($props->getProps(), flags: \JSON_THROW_ON_ERROR), + ] + )); + } } public function render(): RenderedComponent