From b49ca61a9231c658afe3b8ae98fec82a1ce38082 Mon Sep 17 00:00:00 2001 From: sneakyvv Date: Sun, 20 Aug 2023 21:50:56 +0200 Subject: [PATCH] [LiveComponent] Fix tests now that a live id is always added Embedded components can also be live now, so they also need a live-id. The TestLiveComponent trait was added after the live-id change had been introduced in the embbeded live components branch, so it now needed to be synced with those changes. --- src/LiveComponent/src/Test/TestLiveComponent.php | 2 ++ .../Functional/EventListener/LiveComponentSubscriberTest.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/LiveComponent/src/Test/TestLiveComponent.php b/src/LiveComponent/src/Test/TestLiveComponent.php index 212d5b962b6..45cce6c2822 100644 --- a/src/LiveComponent/src/Test/TestLiveComponent.php +++ b/src/LiveComponent/src/Test/TestLiveComponent.php @@ -40,6 +40,8 @@ public function __construct( ) { $this->client->catchExceptions(false); + $data['attributes']['data-live-id'] ??= 'in-a-real-scenario-it-would-already-have-one---provide-one-yourself-if-needed'; + $mounted = $this->factory->create($this->metadata->getName(), $data); $props = $this->hydrator->dehydrate( $mounted->getComponent(), diff --git a/src/LiveComponent/tests/Functional/EventListener/LiveComponentSubscriberTest.php b/src/LiveComponent/tests/Functional/EventListener/LiveComponentSubscriberTest.php index 0216a4fa29b..4e57d2682e1 100644 --- a/src/LiveComponent/tests/Functional/EventListener/LiveComponentSubscriberTest.php +++ b/src/LiveComponent/tests/Functional/EventListener/LiveComponentSubscriberTest.php @@ -290,7 +290,7 @@ public function testItUseBlocksFromEmbeddedContextUsingMultipleComponents(): voi }) ->post('/_components/component2/increase', [ 'headers' => ['X-CSRF-TOKEN' => $token], - 'body' => json_encode(['props' => $dehydrated->getProps()]), + 'body' => ['data' => json_encode(['props' => $dehydrated->getProps()])], ]) ->assertSuccessful() ->assertHeaderContains('Content-Type', 'html')