Skip to content

Commit 608c24d

Browse files
committed
Fix documentation
1 parent ffbac6b commit 608c24d

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

src/LiveComponent/doc/index.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3782,9 +3782,10 @@ uses Symfony's test client to render and make requests to your components::
37823782
;
37833783

37843784
// Assert that the event was emitted
3785-
$this->componentHasEmittedEvent($render, 'increaseEvent', [
3786-
'amount' => 2,
3787-
]);
3785+
$this->componentHasEmittedEvent($testComponent->render(), 'increaseEvent')
3786+
->withData(['amount' => 2])
3787+
->withDataSubset(['amount' => 2]) // test partial parameters
3788+
;
37883789

37893790
// set live props
37903791
$testComponent

src/LiveComponent/src/Test/InteractsWithLiveComponents.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ protected function createLiveComponent(string $name, array $data = [], ?KernelBr
4545
);
4646
}
4747

48+
/**
49+
* @return object{withData: callable(array): object, withDataSubset: callable(array): object}
50+
*/
4851
protected function assertComponentEmitEvent(TestLiveComponent $testLiveComponent, string $expectedEventName): object
4952
{
5053
$event = $testLiveComponent->getEmittedEvent($testLiveComponent->render(), $expectedEventName);
@@ -59,7 +62,10 @@ public function __construct(private KernelTestCase $parent, private readonly str
5962
{
6063
}
6164

62-
public function withDataSubset(array $expectedEventData): void
65+
/**
66+
* @return self
67+
*/
68+
public function withDataSubset(array $expectedEventData): object
6369
{
6470
foreach ($expectedEventData as $key => $value) {
6571
$this->parent->assertArrayHasKey($key, $this->data, \sprintf('The expected event "%s" data "%s" does not exists', $this->eventName, $key));
@@ -75,11 +81,18 @@ public function withDataSubset(array $expectedEventData): void
7581
)
7682
);
7783
}
84+
85+
return $this;
7886
}
7987

80-
public function withData(array $expectedEventData): void
88+
/**
89+
* @return self
90+
*/
91+
public function withData(array $expectedEventData): object
8192
{
8293
$this->parent->assertEquals($expectedEventData, $this->data, \sprintf('The expected event "%s" data does not match.', $this->eventName));
94+
95+
return $this;
8396
}
8497
};
8598
}

src/LiveComponent/tests/Functional/Test/InteractsWithLiveComponentsTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,10 @@ public function testComponentEmitsExpectedPartialEventData(): void
250250

251251
$testComponent->call('actionThatEmits');
252252

253-
$this->assertComponentEmitEvent($testComponent, 'event1')->withDataSubset([
254-
'foo' => 'bar',
255-
]);
253+
$this->assertComponentEmitEvent($testComponent, 'event1')
254+
->withDataSubset(['foo' => 'bar'])
255+
->withDataSubset(['bar' => 'foo'])
256+
;
256257
}
257258

258259
public function testComponentDoesNotEmitUnexpectedEvent(): void

0 commit comments

Comments
 (0)