|
11 | 11 |
|
12 | 12 | namespace Symfony\UX\LiveComponent\Tests\Functional\Test;
|
13 | 13 |
|
| 14 | +use PHPUnit\Framework\AssertionFailedError; |
14 | 15 | use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
15 | 16 | use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
16 | 17 | use Symfony\Component\Security\Core\User\InMemoryUser;
|
@@ -217,4 +218,38 @@ public function testSetLocaleRenderLocalizedComponent(): void
|
217 | 218 | $testComponent->setRouteLocale('de');
|
218 | 219 | $this->assertStringContainsString('Locale: de', $testComponent->render());
|
219 | 220 | }
|
| 221 | + |
| 222 | + public function testComponentEmitsExpectedEventWithParameters(): void |
| 223 | + { |
| 224 | + $testComponent = $this->createLiveComponent('component_with_emit'); |
| 225 | + |
| 226 | + $testComponent->call('actionThatEmits'); |
| 227 | + |
| 228 | + $this->assertComponentEmitEvent($testComponent, 'event1', [ |
| 229 | + 'foo' => 'bar', |
| 230 | + ]); |
| 231 | + } |
| 232 | + |
| 233 | + public function testComponentDoesNotEmitUnexpectedEvent(): void |
| 234 | + { |
| 235 | + $testComponent = $this->createLiveComponent('component_with_emit'); |
| 236 | + |
| 237 | + $testComponent->call('actionThatEmits'); |
| 238 | + |
| 239 | + $this->assertComponentNotEmitEvent($testComponent, 'non_emitted_event'); |
| 240 | + } |
| 241 | + |
| 242 | + public function testComponentEmitsEventWithWrongParametersFails(): void |
| 243 | + { |
| 244 | + $testComponent = $this->createLiveComponent('component_with_emit'); |
| 245 | + |
| 246 | + $testComponent->call('actionThatEmits'); |
| 247 | + |
| 248 | + $this->expectException(AssertionFailedError::class); |
| 249 | + $this->expectExceptionMessage('EventData (foo2) is not valid'); |
| 250 | + $this->assertComponentEmitEvent($testComponent, 'event1', [ |
| 251 | + 'foo' => 'bar', |
| 252 | + 'foo2' => 'bar2', |
| 253 | + ]); |
| 254 | + } |
220 | 255 | }
|
0 commit comments