Skip to content

Commit c7c56f0

Browse files
Lustmoredweaverryan
authored andcommitted
Use expectException to mitigate test failures.
1 parent cf8ef71 commit c7c56f0

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/LiveComponent/tests/Functional/Controller/BatchActionControllerTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
1515
use Symfony\Component\DomCrawler\Crawler;
16+
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1617
use Symfony\UX\LiveComponent\Tests\LiveComponentTestHelper;
1718
use Zenstruck\Browser\KernelBrowser;
1819
use Zenstruck\Browser\Test\HasBrowser;
@@ -160,6 +161,7 @@ public function testException(): void
160161
$this->browser()
161162
->get('/_components/with_actions', ['query' => ['props' => json_encode($dehydrated->getProps())]])
162163
->assertSuccessful()
164+
->expectException(\RuntimeException::class, 'Exception message')
163165
->use(function (Crawler $crawler, KernelBrowser $browser) {
164166
$rootElement = $crawler->filter('ul')->first();
165167
$liveProps = json_decode($rootElement->attr('data-live-props-value'), true);
@@ -178,8 +180,6 @@ public function testException(): void
178180
'headers' => ['X-CSRF-TOKEN' => $crawler->filter('ul')->first()->attr('data-live-csrf-value')],
179181
]);
180182
})
181-
->assertStatus(500)
182-
->assertContains('Exception message')
183183
;
184184
}
185185

@@ -190,6 +190,7 @@ public function testCannotBatchWithNonLiveAction(): void
190190
$this->browser()
191191
->get('/_components/with_actions', ['query' => ['props' => json_encode($dehydrated->getProps())]])
192192
->assertSuccessful()
193+
->expectException(NotFoundHttpException::class, 'The action "nonLive" either doesn\'t exist or is not allowed')
193194
->use(function (Crawler $crawler, KernelBrowser $browser) {
194195
$rootElement = $crawler->filter('ul')->first();
195196
$liveProps = json_decode($rootElement->attr('data-live-props-value'), true);
@@ -208,8 +209,6 @@ public function testCannotBatchWithNonLiveAction(): void
208209
'headers' => ['X-CSRF-TOKEN' => $crawler->filter('ul')->first()->attr('data-live-csrf-value')],
209210
]);
210211
})
211-
->assertStatus(404)
212-
->assertContains('The action \"nonLive\" either doesn\'t exist or is not allowed')
213212
;
214213
}
215214
}

0 commit comments

Comments
 (0)