Skip to content

Commit 5a37a3e

Browse files
committed
bug #1434 fix: use method from metadata for live component test helper (daFish)
This PR was merged into the 2.x branch. Discussion ---------- fix: use method from metadata for live component test helper | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT After #1218 has been released as part of 2.14.0 my tests fail. This change passes the actual method to the requests made by the test helper. Commits ------- d84f3eb fix: use method from metadata for live component test helper
2 parents d2f0de2 + d84f3eb commit 5a37a3e

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/LiveComponent/src/Test/TestLiveComponent.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,25 @@ public function __construct(
5151
$this->metadataFactory->getMetadata($mounted->getName())
5252
);
5353

54-
$this->client->request('GET', $this->router->generate(
55-
$this->metadata->get('route'),
56-
[
57-
'_live_component' => $this->metadata->getName(),
58-
'props' => json_encode($props->getProps(), flags: \JSON_THROW_ON_ERROR),
59-
]
60-
));
54+
if ('POST' === strtoupper($this->metadata->get('method'))) {
55+
$this->client->request(
56+
'POST',
57+
$this->router->generate($this->metadata->get('route'), [
58+
'_live_component' => $this->metadata->getName(),
59+
]),
60+
[
61+
'data' => json_encode(['props' => $props->getProps()], flags: \JSON_THROW_ON_ERROR),
62+
],
63+
);
64+
} else {
65+
$this->client->request('GET', $this->router->generate(
66+
$this->metadata->get('route'),
67+
[
68+
'_live_component' => $this->metadata->getName(),
69+
'props' => json_encode($props->getProps(), flags: \JSON_THROW_ON_ERROR),
70+
]
71+
));
72+
}
6173
}
6274

6375
public function render(): RenderedComponent

0 commit comments

Comments
 (0)